Class: JsRegex::Converter::LiteralConverter
- Defined in:
- lib/js_regex/converter/literal_converter.rb
Overview
Template class implementation.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from JsRegex::Converter::Base
Class Method Details
.convert(data, converter) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/js_regex/converter/literal_converter.rb', line 9 def self.convert(data, converter) utf8_data = data.dup.force_encoding('UTF-8') if /[\u{10000}-\u{FFFFF}]/ =~ utf8_data converter.send(:warn_of_unsupported_feature, 'astral plane character') else ensure_json_compatibility(utf8_data) end end |
.ensure_json_compatibility(data) ⇒ Object
18 19 20 |
# File 'lib/js_regex/converter/literal_converter.rb', line 18 def self.ensure_json_compatibility(data) data.gsub(/\\?[\f\n\r\t]/) { |lit| Regexp.escape(lit.delete('\\')) } end |