4 releases

0.1.2 Oct 18, 2024
0.1.1 Dec 12, 2023
0.1.0 Jul 3, 2023
0.1.0-pre.1 May 7, 2023

#62 in Text processing

Download history 9628/week @ 2024-08-20 9295/week @ 2024-08-27 8957/week @ 2024-09-03 12642/week @ 2024-09-10 12158/week @ 2024-09-17 13456/week @ 2024-09-24 14693/week @ 2024-10-01 14011/week @ 2024-10-08 13258/week @ 2024-10-15 14794/week @ 2024-10-22 14537/week @ 2024-10-29 11714/week @ 2024-11-05 10544/week @ 2024-11-12 11533/week @ 2024-11-19 12802/week @ 2024-11-26 10407/week @ 2024-12-03

47,407 downloads per month
Used in 25 crates (7 directly)

MIT/Apache

28KB
526 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