Module: Tk::CoreExtensions::Regexp

Defined in:
lib/ffi-tk/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_tclObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ffi-tk/core_extensions.rb', line 56

def to_tcl
  embed = []
  embed << 'i' if options & ::Regexp::IGNORECASE != 0
  embed << 'x' if options & ::Regexp::EXTENDED != 0
  embed << 'n' if options & ::Regexp::MULTILINE != 0

  if embed.empty?
    pattern = source
  else
    pattern = "(?#{embed.join})#{source}"
  end

  TclString.new('{' << pattern.gsub(/([^\\])(?=[{}])/, '\1\\\\\2') << '}')
end