forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#16302 - homersimpsons:patch-1, r=lnicola
line-index: Create README.md Fixes rust-lang#16180
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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 | ||
|
||
```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 | ||
|
||
This crate uses [semver](https://semver.org/) versioning. |