4 releases

0.1.2 Oct 18, 2024
0.1.1 Dec 12, 2023
0.1.0 Jul 3, 2023
0.1.0-pre.1 May 7, 2023

#62 in Text processing

Download history 12977/week @ 2025-01-19 12680/week @ 2025-01-26 13990/week @ 2025-02-02 12375/week @ 2025-02-09 12034/week @ 2025-02-16 14040/week @ 2025-02-23 12751/week @ 2025-03-02 13632/week @ 2025-03-09 13955/week @ 2025-03-16 14416/week @ 2025-03-23 15536/week @ 2025-03-30 15146/week @ 2025-04-06 15510/week @ 2025-04-13 16497/week @ 2025-04-20 20814/week @ 2025-04-27 15065/week @ 2025-05-04

68,962 downloads per month
Used in 32 crates (8 directly)

MIT/Apache

28KB
526 lines

See LineIndex.


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.

Dependencies

~39KB

OSZAR »