Skip to content

line-index: Create README.md #16302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/line-index/README.md
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.