| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
Data.Text.Offset
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
- data OffsetTable
- createOffsetTable :: Text -> OffsetTable
- lineColToByteOffsetDetail :: OffsetTable -> Int -> Int -> Either OffsetError Int
- lineColToByteOffset :: OffsetTable -> Int -> Int -> Maybe Int
- data OffsetError- = NoSuchLine
- | EmptyLine
- | OverLineEnd !ByteOffset !OverLineKind
 
- data OverLineKind
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 # | |
| Defined in Data.Text.Offset | |
| Show OffsetTable Source # | |
| Defined in Data.Text.Offset Methods showsPrec :: Int -> OffsetTable -> ShowS # show :: OffsetTable -> String # showList :: [OffsetTable] -> ShowS # | |
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 OffsetError Source #
Constructors
| NoSuchLine | |
| EmptyLine | |
| OverLineEnd !ByteOffset !OverLineKind | Clients might want to recover from this case, see  | 
Instances
| Eq OffsetError Source # | |
| Defined in Data.Text.Offset | |
| Ord OffsetError Source # | |
| Defined in Data.Text.Offset Methods compare :: OffsetError -> OffsetError -> Ordering # (<) :: OffsetError -> OffsetError -> Bool # (<=) :: OffsetError -> OffsetError -> Bool # (>) :: OffsetError -> OffsetError -> Bool # (>=) :: OffsetError -> OffsetError -> Bool # max :: OffsetError -> OffsetError -> OffsetError # min :: OffsetError -> OffsetError -> OffsetError # | |
| Show OffsetError Source # | |
| Defined in Data.Text.Offset Methods showsPrec :: Int -> OffsetError -> ShowS # show :: OffsetError -> String # showList :: [OffsetError] -> ShowS # | |
data OverLineKind Source #
Constructors
| JustAtLineEnd | Referenced position is just after the line content. Position can be a valid non-inclusive ending span offset. | 
| AfterLineEnd | 
Instances
| Eq OverLineKind Source # | |
| Defined in Data.Text.Offset | |
| Ord OverLineKind Source # | |
| Defined in Data.Text.Offset Methods compare :: OverLineKind -> OverLineKind -> Ordering # (<) :: OverLineKind -> OverLineKind -> Bool # (<=) :: OverLineKind -> OverLineKind -> Bool # (>) :: OverLineKind -> OverLineKind -> Bool # (>=) :: OverLineKind -> OverLineKind -> Bool # max :: OverLineKind -> OverLineKind -> OverLineKind # min :: OverLineKind -> OverLineKind -> OverLineKind # | |
| Show OverLineKind Source # | |
| Defined in Data.Text.Offset Methods showsPrec :: Int -> OverLineKind -> ShowS # show :: OverLineKind -> String # showList :: [OverLineKind] -> ShowS # | |