class JsRegex::Converter::EscapeConverter
Template class implementation.
Constants
- ESCAPES_SHARED_BY_RUBY_AND_JS
Private Instance Methods
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
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 :bell, :escape, :hex, :octal hex_escape_codepoint when *ESCAPES_SHARED_BY_RUBY_AND_JS pass_through else warn_of_unsupported_feature end end
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
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
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