class

Noir::JSRouteExtractor::ByteOffsets

Inherits Reference < Object

JSLexer route positions are CHAR indices, but every String op keyed by a char index ([], index(str, offset), MatchData#begin) walks from byte 0 once a file holds one non-ASCII char, and index(String, offset) does so even on ASCII. Done per route that was quadratic in the route count. Convert each position once here and work in bytes, so per-route cost stays proportional to the route's own text.

Constructors

new(content : String)
Source

Instance methods

byte(char_pos : Int32) : Int32

Byte offset of CHAR index char_pos.

Source
content
Source
line(byte_pos : Int32) : Int32

1-based line of a byte offset.

Source
window(start : Int32, max : Int32) : String

Up to max bytes from start, shortened to end on a char boundary.

Source