Class: JsonCompleter::Scanners::ParsedStringToken
- Inherits:
-
Struct
- Object
- Struct
- JsonCompleter::Scanners::ParsedStringToken
- Defined in:
- lib/json_completer/scanners.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#context ⇒ Object
Returns the value of attribute context.
-
#escape_state ⇒ Object
Returns the value of attribute escape_state.
-
#pending_high_surrogate ⇒ Object
Returns the value of attribute pending_high_surrogate.
-
#role ⇒ Object
Returns the value of attribute role.
-
#slot ⇒ Object
Returns the value of attribute slot.
-
#unicode_digits ⇒ Object
Returns the value of attribute unicode_digits.
-
#visible_key ⇒ Object
Returns the value of attribute visible_key.
-
#visible_key_replaced_present ⇒ Object
Returns the value of attribute visible_key_replaced_present.
-
#visible_key_replaced_value ⇒ Object
Returns the value of attribute visible_key_replaced_value.
Instance Method Summary collapse
-
#append_simple_escape(byte) ⇒ Object
ASCII escape bytes: 98/102/110/114/116 = b/f/n/r/t.
- #append_slice(input, start_index, length) ⇒ Object
- #append_unicode_digit(byte) ⇒ Object
- #finish_unicode_escape! ⇒ Object
-
#initialize(role:, slot: nil, context: nil, buffer: nil, escape_state: nil, unicode_digits: nil, pending_high_surrogate: nil, visible_key: nil, visible_key_replaced_value: nil, visible_key_replaced_present: false) ⇒ ParsedStringToken
constructor
A new instance of ParsedStringToken.
- #invalid_unicode! ⇒ Object
- #start_escape! ⇒ Object
- #start_unicode_escape! ⇒ Object
- #terminate! ⇒ Object
- #valid_simple_escape?(byte) ⇒ Boolean
Constructor Details
#initialize(role:, slot: nil, context: nil, buffer: nil, escape_state: nil, unicode_digits: nil, pending_high_surrogate: nil, visible_key: nil, visible_key_replaced_value: nil, visible_key_replaced_present: false) ⇒ ParsedStringToken
Returns a new instance of ParsedStringToken.
76 77 78 79 80 81 82 |
# File 'lib/json_completer/scanners.rb', line 76 def initialize( role:, slot: nil, context: nil, buffer: nil, escape_state: nil, unicode_digits: nil, pending_high_surrogate: nil, visible_key: nil, visible_key_replaced_value: nil, visible_key_replaced_present: false ) super self.buffer ||= String.new end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def buffer @buffer end |
#context ⇒ Object
Returns the value of attribute context
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def context @context end |
#escape_state ⇒ Object
Returns the value of attribute escape_state
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def escape_state @escape_state end |
#pending_high_surrogate ⇒ Object
Returns the value of attribute pending_high_surrogate
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def pending_high_surrogate @pending_high_surrogate end |
#role ⇒ Object
Returns the value of attribute role
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def role @role end |
#slot ⇒ Object
Returns the value of attribute slot
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def slot @slot end |
#unicode_digits ⇒ Object
Returns the value of attribute unicode_digits
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def unicode_digits @unicode_digits end |
#visible_key ⇒ Object
Returns the value of attribute visible_key
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def visible_key @visible_key end |
#visible_key_replaced_present ⇒ Object
Returns the value of attribute visible_key_replaced_present
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def visible_key_replaced_present @visible_key_replaced_present end |
#visible_key_replaced_value ⇒ Object
Returns the value of attribute visible_key_replaced_value
71 72 73 |
# File 'lib/json_completer/scanners.rb', line 71 def visible_key_replaced_value @visible_key_replaced_value end |
Instance Method Details
#append_simple_escape(byte) ⇒ Object
ASCII escape bytes: 98/102/110/114/116 = b/f/n/r/t.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/json_completer/scanners.rb', line 93 def append_simple_escape(byte) buffer << case byte when 98 "\b" when 102 "\f" when 110 "\n" when 114 "\r" when 116 "\t" else byte end end |
#append_slice(input, start_index, length) ⇒ Object
88 89 90 |
# File 'lib/json_completer/scanners.rb', line 88 def append_slice(input, start_index, length) buffer << input.byteslice(start_index, length) end |
#append_unicode_digit(byte) ⇒ Object
123 124 125 |
# File 'lib/json_completer/scanners.rb', line 123 def append_unicode_digit(byte) unicode_digits << byte end |
#finish_unicode_escape! ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/json_completer/scanners.rb', line 127 def finish_unicode_escape! codepoint = unicode_digits.to_i(16) if pending_high_surrogate unless codepoint.between?(0xDC00, 0xDFFF) self.pending_high_surrogate = nil return :invalid_unicode end combined = 0x10000 + ((pending_high_surrogate - 0xD800) << 10) + (codepoint - 0xDC00) buffer << combined.chr(Encoding::UTF_8) self.pending_high_surrogate = nil return :ok end if codepoint.between?(0xD800, 0xDBFF) self.pending_high_surrogate = codepoint elsif codepoint.between?(0xDC00, 0xDFFF) return :invalid_unicode else buffer << codepoint.chr(Encoding::UTF_8) end :ok rescue RangeError self.pending_high_surrogate = nil :invalid_unicode end |
#invalid_unicode! ⇒ Object
155 156 157 158 159 |
# File 'lib/json_completer/scanners.rb', line 155 def invalid_unicode! self.escape_state = nil self.unicode_digits = nil self.pending_high_surrogate = nil end |
#start_escape! ⇒ Object
84 85 86 |
# File 'lib/json_completer/scanners.rb', line 84 def start_escape! self.escape_state = :backslash end |
#start_unicode_escape! ⇒ Object
119 120 121 |
# File 'lib/json_completer/scanners.rb', line 119 def start_unicode_escape! self.unicode_digits = String.new end |
#terminate! ⇒ Object
161 |
# File 'lib/json_completer/scanners.rb', line 161 def terminate!; end |
#valid_simple_escape?(byte) ⇒ Boolean
110 111 112 113 114 115 116 117 |
# File 'lib/json_completer/scanners.rb', line 110 def valid_simple_escape?(byte) case byte when 34, 92, 47, 98, 102, 110, 114, 116 true else false end end |