2024-01-07 13:25:42 +00:00
|
|
|
# line-index
|
|
|
|
|
2024-01-07 14:38:40 +00:00
|
|
|
This crate is developed as part of `rust-analyzer`.
|
2024-01-07 13:25:42 +00:00
|
|
|
|
2024-01-07 14:38:40 +00:00
|
|
|
line-index is a library to convert between text offsets and corresponding line/column coordinates.
|
2024-01-07 13:25:42 +00:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
To add this crate to a project simply run `cargo add line-index`.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2024-01-07 14:38:40 +00:00
|
|
|
The main structure is `LineIndex`.
|
|
|
|
|
|
|
|
It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets.
|
2024-01-07 13:25:42 +00:00
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
```rust
|
|
|
|
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
|
|
|
|
|
2024-01-07 14:38:40 +00:00
|
|
|
This crate uses [semver](https://semver.org/) versioning.
|