line-col

Crates.io version shield Docs.rs shield Crates.io license shield

A simple crate for calculating 1-based line/col numbers for a string slice.

Example

```rust use line_col::LineColLookup;

let text = "One\nTwo"; let lookup = LineColLookup::new(text); asserteq!(lookup.get(0), (1, 1)); // 'O' (line 1, col 1) asserteq!(lookup.get(1), (1, 2)); // 'n' (line 1, col 2) asserteq!(lookup.get(2), (1, 3)); // 'e' (line 1, col 3) asserteq!(lookup.get(4), (2, 1)); // 'T' (line 2, col 1) asserteq!(lookup.get(5), (2, 2)); // 'w' (line 2, col 2) asserteq!(lookup.get(6), (2, 3)); // 'o' (line 2, col 3) assert_eq!(lookup.get(7), (2, 4)); // (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.

Changelog

0.1.1

0.1.0

Initial version