class JsRegex::Converter::EscapeConverter

Template class implementation.

Constants

ESCAPES_SHARED_BY_RUBY_AND_JS

Private Instance Methods

convert_codepoint_list() click to toggle source
# File lib/js_regex/converter/escape_converter.rb, line 54
def convert_codepoint_list
  if context.enable_u_option
    split_codepoint_list
  else
    expression.chars.each_with_object(Node.new) do |char, node|
      node << LiteralConverter.convert_data(Regexp.escape(char), context)
    end
  end
end
convert_data() click to toggle source
# File lib/js_regex/converter/escape_converter.rb, line 37
def convert_data
  case subtype
  when :codepoint_list
    convert_codepoint_list
  when :control, :meta_sequence
    unicode_escape_codepoint
  when :literal
    LiteralConverter.convert_data(expression.char, context)
  when *ESCAPES_SHARED_BY_RUBY_AND_JS
    pass_through
  when :bell, :escape, :octal
    hex_escape_codepoint
  else
    warn_of_unsupported_feature
  end
end
hex_escape_codepoint() click to toggle source
# File lib/js_regex/converter/escape_converter.rb, line 72
def hex_escape_codepoint
  "\\x#{expression.codepoint.to_s(16).upcase.rjust(2, '0')}"
end
split_codepoint_list() click to toggle source
# File lib/js_regex/converter/escape_converter.rb, line 64
def split_codepoint_list
  expression.codepoints.map { |cp| "\\u{#{cp.to_s(16).upcase}}" }.join
end
unicode_escape_codepoint() click to toggle source
# File lib/js_regex/converter/escape_converter.rb, line 68
def unicode_escape_codepoint
  "\\u#{expression.codepoint.to_s(16).upcase.rjust(4, '0')}"
end