pub struct SourceTextInfo<'text> { /* private fields */ }Expand description
A view onto the source text, with additional information about the source text that was derived during parsing.
This struct provides methods to convert between opaque Location values, UTF-8 line and column indices, and UTF-16 line and column indices. It also provides methods to calculate the length of a span in UTF-8 bytes or UTF-16 code units.
Implementations§
source§impl SourceTextInfo<'_>
impl SourceTextInfo<'_>
sourcepub fn utf8_line_col(&self, loc: Location) -> LineColUtf8
pub fn utf8_line_col(&self, loc: Location) -> LineColUtf8
Returns a UTF-8 line and column index pair given a Location.
It is undefined behavior to pass a location that is out of bounds for the source text.
sourcepub fn utf16_line_col(&self, loc: Location) -> LineColUtf16
pub fn utf16_line_col(&self, loc: Location) -> LineColUtf16
Returns a UTF-16 line and column index pair given a Location.
It is undefined behavior to pass a location that is out of bounds for the source text.
sourcepub fn utf16_len(&self, span: Span) -> u32
pub fn utf16_len(&self, span: Span) -> u32
Returns the length of the given span in UTF-16 code units.
sourcepub fn utf8_loc(&self, line_col: LineColUtf8) -> Location
pub fn utf8_loc(&self, line_col: LineColUtf8) -> Location
Returns the location of the given UTF-8 line and column index pair.
If the line index is out of bounds, returns a location pointing to the end of the source text.
If the column index is greater than the line length, it is clamped to the line length. If the column index points to within a multi-byte character, the location will point to the the start of that character.
sourcepub fn utf16_loc(&self, line_col: LineColUtf16) -> Location
pub fn utf16_loc(&self, line_col: LineColUtf16) -> Location
Returns the location of the given UTF-16 line and column index pair.
If the line index is out of bounds, returns a location pointing to the end of the source text.
If the column index is greater than the line length, it is clamped to the line length. If the column index points to within a multi-byte character, the location will point to the the start of that character.