text-offset-0.1.0.0: Library for converting between line/column and byte offset.

Safe HaskellNone
LanguageHaskell2010

Data.Text.Offset

Contents

Description

Helpers for calculating char/byte offset from line and column number. All line and column offsets in this module are zero-based.

Note: currently only line/column to byte offset calculation is exposed, but the OffsetTable structure supports more, which can be added on demand.

Synopsis

Documentation

data OffsetTable Source #

Stores info for mapping line/column number (Char-based) to raw offset (either Char or UTF-8 encoded bytes-based).

Instances
Eq OffsetTable Source # 
Instance details

Defined in Data.Text.Offset

Show OffsetTable Source # 
Instance details

Defined in Data.Text.Offset

Creation

createOffsetTable :: Text -> OffsetTable Source #

Calculates the OffsetTable for the given text. The table calculation is not optimized (non-strict tuples are lying around), but lookups on the result are performant (since the tuples are stored as unboxed vectors).

Querying

lineColToByteOffsetDetail :: OffsetTable -> Int -> Int -> Either OffsetError Int Source #

Line and col are zero-based, col is in characters.

lineColToByteOffset :: OffsetTable -> Int -> Int -> Maybe Int Source #

Like lineColToByteOffsetDetail, but without failure details.

data OverLineKind Source #

Constructors

JustAtLineEnd

Referenced position is just after the line content. Position can be a valid non-inclusive ending span offset.

AfterLineEnd