line-col
A simple crate for calculating 1-based line/col numbers for a string slice.
Example
use LineColLookup;
let text = "One\nTwo";
let lookup = new;
assert_eq!; // 'O' (line 1, col 1)
assert_eq!; // 'n' (line 1, col 2)
assert_eq!; // 'e' (line 1, col 3)
assert_eq!; // 'T' (line 2, col 1)
assert_eq!; // 'w' (line 2, col 2)
assert_eq!; // 'o' (line 2, col 3)
assert_eq!; // <end> (line 2, col 4)
Column calculation methods
This crate offers two methods for calculating the column number.
The default behavior is to count the number of code points from the start of the line (plus one).
However, this does not account for grapheme clusters (e.g. complex accented characters, emoji, etc.)
If you would like to calculate the column based on the number of grapheme clusters instead, enable
the grapheme-clusters
feature.