3 releases

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

#58 in Text processing

Download history 7044/week @ 2024-01-15 6445/week @ 2024-01-22 5554/week @ 2024-01-29 8285/week @ 2024-02-05 7752/week @ 2024-02-12 7409/week @ 2024-02-19 7254/week @ 2024-02-26 7821/week @ 2024-03-04 7764/week @ 2024-03-11 8418/week @ 2024-03-18 7826/week @ 2024-03-25 7488/week @ 2024-04-01 7443/week @ 2024-04-08 7611/week @ 2024-04-15 7108/week @ 2024-04-22 6477/week @ 2024-04-29

29,578 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