Class: RbJSON5::EscapeSequence Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rb_json5/escape_sequence.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Utility class to unescape the given escape sequence

Instance Method Summary collapse

Constructor Details

#initialize(sequence, valid_patterns = []) {|character, sequence| ... } ⇒ EscapeSequence

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EscapeSequence.

Parameters:

  • sequence (Parslet::Slice)

    escape sequence

  • valid_patterns (Array<Regexp>) (defaults to: [])

    list of patterns for valid unescaped character

Yields:

  • (character, sequence)

    call back block called when unespaced character is not matched with the given valid_patterns

Yield Parameters:

  • character (String)

    character unescaped from the given escape sequence

  • sequence (Parslet::Slice)

    the given escape sequence



18
19
20
21
# File 'lib/rb_json5/escape_sequence.rb', line 18

def initialize(sequence, valid_patterns = [], &ifinvalid)
  @character = unescape(sequence.to_s)
  validate(@character, sequence, valid_patterns, ifinvalid)
end

Instance Method Details

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

returns the character unescaped from the given escape sequence

Returns:

  • (String)

    unescaped character



27
28
29
# File 'lib/rb_json5/escape_sequence.rb', line 27

def to_s
  @character
end