#text #source #line #locations #string #offset #column

hydroper_source_text

Source text containing line locations

4 stable releases

1.0.3 Apr 9, 2024
1.0.1 Apr 8, 2024

#6 in #locations

45 downloads per month
Used in 4 crates (via as3_parser)

Apache-2.0

15KB
296 lines

Source text

Library for storing efficient line offset and column from std::string::String. It processes lines only once at the first invokation of any of the retrieval methods.

Example

Here is a basic example:

// offset 5 = "bar"
let text = SourceText::new("foo\r\nbar\r\nqux".into());
assert_eq!(0, text.get_column(5));
assert_eq!(2, text.get_line_number(5));
assert_eq!(5, text.get_line_offset(2).unwrap());
assert_eq!(5, text.get_line_offset_from_offset(7));

No runtime deps