3 releases

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

#52 in Text processing

Download history 6326/week @ 2023-12-23 5594/week @ 2023-12-30 6998/week @ 2024-01-06 6907/week @ 2024-01-13 6784/week @ 2024-01-20 5764/week @ 2024-01-27 7515/week @ 2024-02-03 7961/week @ 2024-02-10 7804/week @ 2024-02-17 6850/week @ 2024-02-24 7652/week @ 2024-03-02 7805/week @ 2024-03-09 8210/week @ 2024-03-16 8052/week @ 2024-03-23 7631/week @ 2024-03-30 6449/week @ 2024-04-06

31,501 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