rust-analyzer/lib/line-index
homersimpsons 0f69276e60
line-index: Update README.md with suggestions
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2024-01-07 15:38:40 +01:00
..
src fix: correct existing tests for WideChar in lib 'line-index' and add more tests 2023-12-07 15:33:28 +08:00
Cargo.toml Use Cargo's [workspace.lints.*] to config clippy 2023-12-29 23:51:32 +09:00
README.md line-index: Update README.md with suggestions 2024-01-07 15:38:40 +01:00

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.