Class: RubyLsp::Document::Utf32Scanner
- Defined in:
- lib/ruby_lsp/document.rb
Overview
For the UTF-32 encoding, positions correspond directly to codepoints
Constant Summary
Constants inherited from Scanner
Scanner::LINE_BREAK, Scanner::SURROGATE_PAIR_START
Instance Method Summary collapse
-
#find_char_position(position) ⇒ Object
: (Hash[Symbol, untyped] position) -> Integer.
-
#initialize(source) ⇒ Utf32Scanner
constructor
: (String) -> void.
Constructor Details
#initialize(source) ⇒ Utf32Scanner
: (String) -> void
316 317 318 319 |
# File 'lib/ruby_lsp/document.rb', line 316 def initialize(source) super() @codepoints = source.codepoints #: Array[Integer] end |
Instance Method Details
#find_char_position(position) ⇒ Object
: (Hash[Symbol, untyped] position) -> Integer
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ruby_lsp/document.rb', line 323 def find_char_position(position) # Find the character index for the beginning of the requested line until @current_line == position[:line] codepoint = @codepoints[@pos] #: Integer? raise InvalidLocationError unless codepoint until LINE_BREAK == @codepoints[@pos] @pos += 1 codepoint = @codepoints[@pos] #: Integer? raise InvalidLocationError unless codepoint end @pos += 1 @current_line += 1 end @pos + position[:character] end |