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

#65 in Text processing

Download history 8203/week @ 2024-08-01 7982/week @ 2024-08-08 7617/week @ 2024-08-15 10196/week @ 2024-08-22 9001/week @ 2024-08-29 9418/week @ 2024-09-05 13941/week @ 2024-09-12 12348/week @ 2024-09-19 13489/week @ 2024-09-26 14864/week @ 2024-10-03 13428/week @ 2024-10-10 14091/week @ 2024-10-17 14618/week @ 2024-10-24 13433/week @ 2024-10-31 11813/week @ 2024-11-07 8718/week @ 2024-11-14

51,188 downloads per month
Used in 21 crates (4 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