Crates.io | line-index |
lib.rs | line-index |
version | 0.1.2 |
source | src |
created_at | 2023-05-07 10:13:19.400935 |
updated_at | 2024-10-18 11:39:58.582887 |
description | Maps flat `TextSize` offsets to/from `(line, column)` representation. |
homepage | |
repository | https://github.com/rust-lang/rust-analyzer/tree/master/lib/line-index |
max_upload_size | |
id | 859048 |
size | 27,246 |
This crate is developed as part of rust-analyzer
.
line-index is a library to convert between text offsets and corresponding line/column coordinates.
To add this crate to a project simply run cargo add line-index
.
The main structure is LineIndex
.
It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets.
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)
This crate uses semver versioning.