Class: JsonCompleter::Scanners::CompletionStringToken
- Inherits:
-
Struct
- Object
- Struct
- JsonCompleter::Scanners::CompletionStringToken
- Defined in:
- lib/json_completer/scanners.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#escape_state ⇒ Object
Returns the value of attribute escape_state.
-
#unicode_digits ⇒ Object
Returns the value of attribute unicode_digits.
Instance Method Summary collapse
-
#append_simple_escape(byte) ⇒ Object
completion keeps escape bytes verbatim, so convert the ASCII byte back into a 1-byte string.
- #append_slice(input, start_index, length) ⇒ Object
- #append_unicode_digit(byte) ⇒ Object
- #finalized_incomplete_value ⇒ Object
- #finish_unicode_escape! ⇒ Object
-
#initialize(buffer: nil, escape_state: nil, unicode_digits: nil) ⇒ CompletionStringToken
constructor
A new instance of CompletionStringToken.
- #invalid_unicode! ⇒ Object
- #start_escape! ⇒ Object
- #start_unicode_escape! ⇒ Object
- #terminate! ⇒ Object
- #valid_simple_escape?(_byte) ⇒ Boolean
Constructor Details
#initialize(buffer: nil, escape_state: nil, unicode_digits: nil) ⇒ CompletionStringToken
6 7 8 9 10 |
# File 'lib/json_completer/scanners.rb', line 6 def initialize(buffer: nil, escape_state: nil, unicode_digits: nil) buffer ||= StringIO.new buffer << '"' if buffer.string.empty? super end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer
5 6 7 |
# File 'lib/json_completer/scanners.rb', line 5 def buffer @buffer end |
#escape_state ⇒ Object
Returns the value of attribute escape_state
5 6 7 |
# File 'lib/json_completer/scanners.rb', line 5 def escape_state @escape_state end |
#unicode_digits ⇒ Object
Returns the value of attribute unicode_digits
5 6 7 |
# File 'lib/json_completer/scanners.rb', line 5 def unicode_digits @unicode_digits end |
Instance Method Details
#append_simple_escape(byte) ⇒ Object
completion keeps escape bytes verbatim, so convert the ASCII byte back into a 1-byte string.
22 23 24 |
# File 'lib/json_completer/scanners.rb', line 22 def append_simple_escape(byte) buffer << byte.chr(Encoding::UTF_8) end |
#append_slice(input, start_index, length) ⇒ Object
17 18 19 |
# File 'lib/json_completer/scanners.rb', line 17 def append_slice(input, start_index, length) buffer << input.byteslice(start_index, length) end |
#append_unicode_digit(byte) ⇒ Object
35 36 37 38 |
# File 'lib/json_completer/scanners.rb', line 35 def append_unicode_digit(byte) unicode_digits << byte buffer << byte.chr(Encoding::UTF_8) end |
#finalized_incomplete_value ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/json_completer/scanners.rb', line 55 def finalized_incomplete_value value = buffer.string.dup trailing_backslashes = 0 index = value.length - 1 while index >= 0 && value[index] == '\\' trailing_backslashes += 1 index -= 1 end value = value[0...-1] if trailing_backslashes.odd? value = value.sub(/\\u[0-9a-fA-F]{0,3}\z/, '') "#{value}\"" end |
#finish_unicode_escape! ⇒ Object
40 |
# File 'lib/json_completer/scanners.rb', line 40 def finish_unicode_escape!; end |
#invalid_unicode! ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/json_completer/scanners.rb', line 42 def invalid_unicode! current = buffer.string current = current.sub(/\\u[0-9a-fA-F]*\z/, '') self.buffer = StringIO.new buffer << current self.unicode_digits = nil self.escape_state = nil end |
#start_escape! ⇒ Object
12 13 14 15 |
# File 'lib/json_completer/scanners.rb', line 12 def start_escape! buffer << '\\' self.escape_state = :backslash end |
#start_unicode_escape! ⇒ Object
30 31 32 33 |
# File 'lib/json_completer/scanners.rb', line 30 def start_unicode_escape! self.unicode_digits = String.new buffer << 'u' end |
#terminate! ⇒ Object
51 52 53 |
# File 'lib/json_completer/scanners.rb', line 51 def terminate! buffer << '"' end |
#valid_simple_escape?(_byte) ⇒ Boolean
26 27 28 |
# File 'lib/json_completer/scanners.rb', line 26 def valid_simple_escape?(_byte) true end |