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

#59 in Text processing

Download history 13300/week @ 2024-09-20 13729/week @ 2024-09-27 14672/week @ 2024-10-04 13194/week @ 2024-10-11 14400/week @ 2024-10-18 14326/week @ 2024-10-25 13074/week @ 2024-11-01 11435/week @ 2024-11-08 10296/week @ 2024-11-15 12096/week @ 2024-11-22 13424/week @ 2024-11-29 12443/week @ 2024-12-06 11963/week @ 2024-12-13 10034/week @ 2024-12-20 11263/week @ 2024-12-27 10487/week @ 2025-01-03

45,741 downloads per month
Used in 26 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