pub struct FileMap { /* private fields */ }Expand description
Stores the content of a file and keeps track of some position meta data, such as linebreaks.
Implementations§
Source§impl FileMap
impl FileMap
Sourcepub fn new<U, V>(filename: U, src: V) -> FileMap
pub fn new<U, V>(filename: U, src: V) -> FileMap
Creates a new Filemap from existing buffers for the filename and content of the file.
pub fn filename(&self) -> &str
pub fn src(&self) -> &str
Sourcepub fn add_line(&self, offset: BytePos)
pub fn add_line(&self, offset: BytePos)
Adds a new line beginning with the given BytePos to the list. Line beginnings need to be added in order!
Sourcepub fn get_line_idx(&self, offset: BytePos) -> LineIdx
pub fn get_line_idx(&self, offset: BytePos) -> LineIdx
Returns the (0-based) index of the line in which the byte with the
given offset lives.
Sourcepub fn get_loc(&self, offset: BytePos) -> Loc
pub fn get_loc(&self, offset: BytePos) -> Loc
Returns the location of the given bytes as line and col numbers within this file.
Sourcepub fn get_line(&self, line: LineIdx) -> Option<&str>
pub fn get_line(&self, line: LineIdx) -> Option<&str>
Returns the line with the given index or None if it is invalid.
Sourcepub fn get_line_start(&self, line: LineIdx) -> Option<BytePos>
pub fn get_line_start(&self, line: LineIdx) -> Option<BytePos>
Returns the byte offset of the first symbol in line
Sourcepub fn find_lines(&self)
pub fn find_lines(&self)
Searches for line endings and collects all line beginnings in the source string. It starts searching at the latest line beginning in the list so far (or at the beginning of none was added yet).
Normally this is done while lexing to avoid iterating over the whole string multiple times. Mostly handy for tests.