| License | BSD3 |
|---|---|
| Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Text.Utf8.Lines
Contents
Description
Since: 0.3
Synopsis
- data TextLines
- fromText :: Text -> TextLines
- toText :: TextLines -> Text
- null :: TextLines -> Bool
- getLine :: Word -> TextLines -> TextLines
- lines :: TextLines -> [Text]
- lengthInLines :: TextLines -> Word
- splitAtLine :: Word -> TextLines -> (TextLines, TextLines)
- length :: TextLines -> Word
- splitAt :: Word -> TextLines -> Maybe (TextLines, TextLines)
- data Position = Position {}
- lengthAsPosition :: TextLines -> Position
- splitAtPosition :: Position -> TextLines -> Maybe (TextLines, TextLines)
Documentation
A wrapper around Text for fast line/column navigation. Concatenation takes linear time.
This is a building block for Rope, which provides logarithmic concatenation.
Instances
| IsString TextLines Source # | |
Defined in Data.Text.Lines.Internal Methods fromString :: String -> TextLines # | |
| Monoid TextLines Source # | |
| Semigroup TextLines Source # | |
| Show TextLines Source # | |
| NFData TextLines Source # | |
Defined in Data.Text.Lines.Internal | |
| Eq TextLines Source # | |
| Ord TextLines Source # | |
Lines
getLine :: Word -> TextLines -> TextLines Source #
Get line with given 0-based index, O(1). The result does not contain \n characters.. Returns mempty if the line index is out of bounds.
>>>:set -XOverloadedStrings>>>map (\l -> getLine l "fя𐀀\n☺bar\n\n") [0..3]["fя𐀀","☺bar","",""]
Since: 0.3
lines :: TextLines -> [Text] Source #
Split into lines by \n, similar to Data.Text.lines. Each line is produced in O(1).
>>>:set -XOverloadedStrings>>>lines ""[]>>>lines "foo"["foo"]>>>lines "foo\n"["foo"]>>>lines "foo\n\n"["foo",""]>>>lines "foo\nbar"["foo","bar"]
lengthInLines :: TextLines -> Word Source #
splitAtLine :: Word -> TextLines -> (TextLines, TextLines) Source #
Split at given line, O(1).
>>>:set -XOverloadedStrings>>>map (\l -> splitAtLine l "foo\nbar") [0..3][("","foo\nbar"),("foo\n","bar"),("foo\nbar",""),("foo\nbar","")]
UTF-8 code units
length :: TextLines -> Word Source #
Length in UTF-8 code units aka bytes. Takes linear time.
>>>:set -XOverloadedStrings>>>length "fя𐀀"7>>>Data.Text.Lines.length "fя𐀀"3
splitAt :: Word -> TextLines -> Maybe (TextLines, TextLines) Source #
Split at given UTF-8 code unit aka byte. If requested number of code units splits a code point in half, return Nothing. Takes linear time.
>>>:set -XOverloadedStrings>>>map (\c -> splitAt c "fя𐀀") [0..7][Just ("","fя𐀀"),Just ("f","я𐀀"),Nothing,Just ("fя","𐀀"),Nothing,Nothing,Nothing,Just ("fя𐀀","")]
Represent a position in a text.
Constructors
| Position | |
lengthAsPosition :: TextLines -> Position Source #
Measure text length as an amount of lines and columns. Time is proportional to the length of the last line.
>>>:set -XOverloadedStrings>>>lengthAsPosition "f𐀀"Position {posLine = 0, posColumn = 7}>>>lengthAsPosition "f\n𐀀"Position {posLine = 1, posColumn = 4}>>>lengthAsPosition "f\n𐀀\n"Position {posLine = 2, posColumn = 0}
splitAtPosition :: Position -> TextLines -> Maybe (TextLines, TextLines) Source #
Combination of splitAtLine and subsequent splitAt. If requested number of code units splits a code point in half, return Nothing. Time is linear in posColumn, but does not depend on posLine.
>>>:set -XOverloadedStrings>>>splitAtPosition (Position 1 0) "f\n𐀀я"Just ("f\n","𐀀я")>>>splitAtPosition (Position 1 1) "f\n𐀀я"Nothing>>>splitAtPosition (Position 1 2) "f\n𐀀я"Nothing>>>splitAtPosition (Position 0 2) "f\n𐀀я"Just ("f\n","𐀀я")>>>splitAtPosition (Position 0 3) "f\n𐀀я"Nothing>>>splitAtPosition (Position 0 4) "f\n𐀀я"Nothing>>>splitAtPosition (Position 0 6) "f\n𐀀я"Just ("f\n𐀀","я")