3 releases

0.1.1 Dec 12, 2023
0.1.0 Jul 3, 2023
0.1.0-pre.1 May 7, 2023

#71 in Text processing

Download history 8031/week @ 2024-03-14 8246/week @ 2024-03-21 7730/week @ 2024-03-28 7418/week @ 2024-04-04 7437/week @ 2024-04-11 7566/week @ 2024-04-18 7004/week @ 2024-04-25 6822/week @ 2024-05-02 6492/week @ 2024-05-09 7104/week @ 2024-05-16 7223/week @ 2024-05-23 7073/week @ 2024-05-30 7684/week @ 2024-06-06 7791/week @ 2024-06-13 7706/week @ 2024-06-20 6370/week @ 2024-06-27

30,738 downloads per month
Used in 16 crates (2 directly)

MIT/Apache

19KB
378 lines

line-index

This crate is developed as part of rust-analyzer.

line-index is a library to convert between text offsets and corresponding line/column coordinates.

Installation

To add this crate to a project simply run cargo add line-index.

Usage

The main structure is LineIndex.

It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets.

Example

use line_index::LineIndex;

let line_index = LineIndex::new("This is a\nmulti-line\ntext.");
line_index.line_col(3.into()); // LineCol { line: 0, col: 3 }
line_index.line_col(13.into()); // LineCol { line: 1, col: 3 }
line_index.offset(LineCol { line: 2, col: 3 }); // Some (24)

SemVer

This crate uses semver versioning.


lib.rs:

See LineIndex.

Dependencies

~39KB