Module: JsRegex::Converter

Defined in:
lib/js_regex/converter.rb,
lib/js_regex/converter/base.rb,
lib/js_regex/converter/context.rb,
lib/js_regex/converter/set_converter.rb,
lib/js_regex/converter/meta_converter.rb,
lib/js_regex/converter/type_converter.rb,
lib/js_regex/converter/group_converter.rb,
lib/js_regex/converter/anchor_converter.rb,
lib/js_regex/converter/escape_converter.rb,
lib/js_regex/converter/literal_converter.rb,
lib/js_regex/converter/property_converter.rb,
lib/js_regex/converter/assertion_converter.rb,
lib/js_regex/converter/freespace_converter.rb,
lib/js_regex/converter/conditional_converter.rb,
lib/js_regex/converter/backreference_converter.rb,
lib/js_regex/converter/subexpression_converter.rb,
lib/js_regex/converter/unsupported_token_converter.rb

Defined Under Namespace

Classes: AnchorConverter, AssertionConverter, BackreferenceConverter, Base, ConditionalConverter, Context, EscapeConverter, FreespaceConverter, GroupConverter, LiteralConverter, MetaConverter, PropertyConverter, SetConverter, SubexpressionConverter, TypeConverter, UnsupportedTokenConverter

Constant Summary collapse

MAP =
Hash.new(UnsupportedTokenConverter).merge(
  anchor:      AnchorConverter,
  assertion:   AssertionConverter,
  backref:     BackreferenceConverter,
  conditional: ConditionalConverter,
  escape:      EscapeConverter,
  expression:  SubexpressionConverter,
  free_space:  FreespaceConverter,
  group:       GroupConverter,
  literal:     LiteralConverter,
  meta:        MetaConverter,
  nonproperty: PropertyConverter,
  property:    PropertyConverter,
  set:         SetConverter,
  type:        TypeConverter
).freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.surrogate_pair_limit=(value) ⇒ Object (writeonly)

Limit the number of generated surrogate pairs, else the output might get to large for certain applications. The chosen number is somewhat arbitrary. 100 pairs make for about 1 KB, uncompressed. The median char count of all properties supported by Ruby is 92. 75% are below 300 chars.

Set this to nil if you need full unicode matches and size doesn’t matter.



41
42
43
# File 'lib/js_regex/converter.rb', line 41

def surrogate_pair_limit=(value)
  @surrogate_pair_limit = value
end

Class Method Details

.convert(exp, context = nil) ⇒ Object



27
28
29
# File 'lib/js_regex/converter.rb', line 27

def convert(exp, context = nil)
  self.for(exp).convert(exp, context || Context.new)
end

.for(expression) ⇒ Object



31
32
33
# File 'lib/js_regex/converter.rb', line 31

def for(expression)
  MAP[expression.type].new
end

.in_surrogate_pair_limit?(&pair_count) ⇒ Boolean



43
44
45
# File 'lib/js_regex/converter.rb', line 43

def in_surrogate_pair_limit?(&pair_count)
  @surrogate_pair_limit.nil? || @surrogate_pair_limit >= pair_count.call
end