class SyntaxTree::Parser::MultiByteString

Represents a line in the source. If this class is being used, it means that there are characters in the string that are multi-byte, so we will build up an array of indices, such that array will be equal to the index of the character within the string.

Attributes

indices[R]
start[R]

Public Class Methods

new(start, line) click to toggle source
# File lib/syntax_tree/parser.rb, line 41
def initialize(start, line)
  @start = start
  @indices = []

  line
    .each_char
    .with_index(start) do |char, index|
      char.bytesize.times { @indices << index }
    end
end

Public Instance Methods

[](byteindex) click to toggle source

Technically it’s possible for the column index to be a negative value if there’s a BOM at the beginning of the file, which is the reason we need to compare it to 0 here.

# File lib/syntax_tree/parser.rb, line 55
def [](byteindex)
  indices[[byteindex, 0].max]
end