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

#60 in Text processing

Download history 11646/week @ 2024-12-17 11317/week @ 2024-12-24 9858/week @ 2024-12-31 13461/week @ 2025-01-07 13678/week @ 2025-01-14 12626/week @ 2025-01-21 13593/week @ 2025-01-28 13171/week @ 2025-02-04 12084/week @ 2025-02-11 12692/week @ 2025-02-18 13551/week @ 2025-02-25 13277/week @ 2025-03-04 13611/week @ 2025-03-11 14017/week @ 2025-03-18 14587/week @ 2025-03-25 12840/week @ 2025-04-01

57,840 downloads per month
Used in 31 crates (8 directly)

MIT/Apache

28KB
526 lines

See LineIndex.


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.

Dependencies

~39KB