| Copyright | (c) 2021-2022 Andrew Lelechenko | 
|---|---|
| License | BSD3 | 
| Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Text.Utf16.Rope
Contents
Description
Synopsis
- data Rope
 - fromText :: Text -> Rope
 - fromTextLines :: TextLines -> Rope
 - toText :: Rope -> Text
 - toTextLines :: Rope -> TextLines
 - null :: Rope -> Bool
 - lines :: Rope -> [Text]
 - lengthInLines :: Rope -> Word
 - splitAtLine :: Word -> Rope -> (Rope, Rope)
 - length :: Rope -> Word
 - splitAt :: Word -> Rope -> Maybe (Rope, Rope)
 - data Position = Position {}
 - lengthAsPosition :: Rope -> Position
 - splitAtPosition :: Position -> Rope -> Maybe (Rope, Rope)
 
Documentation
Rope of Text chunks with logarithmic concatenation.
 This rope offers an interface, based on UTF-16 code units.
 Use Data.Text.Rope, if you need code points,
 or Data.Text.Utf16.Rope.Mixed, if you need both interfaces.
Lines
lines :: Rope -> [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 :: Rope -> Word Source #
Equivalent to length . lines, but in logarithmic time.
>>>:set -XOverloadedStrings>>>lengthInLines ""0>>>lengthInLines "foo"1>>>lengthInLines "foo\n"1>>>lengthInLines "foo\n\n"2>>>lengthInLines "foo\nbar"2
If you do not care about ignoring the last newline character,
 you can use posLine . lengthAsPosition instead, which works in O(1).
splitAtLine :: Word -> Rope -> (Rope, Rope) Source #
Split at given line, logarithmic time.
>>>:set -XOverloadedStrings>>>map (\l -> splitAtLine l "foo\nbar") [0..3][("","foo\nbar"),("foo\n","bar"),("foo\nbar",""),("foo\nbar","")]
UTF-16 code units
length :: Rope -> Word Source #
Length in UTF-16 code units, O(1).
>>>:set -XOverloadedStrings>>>length "fя𐀀"4>>>Data.Text.Rope.length "fя𐀀"3
splitAt :: Word -> Rope -> Maybe (Rope, Rope) Source #
Split at given UTF-16 code unit.
 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..4][Just ("","fя𐀀"),Just ("f","я𐀀"),Just ("fя","𐀀"),Nothing,Just ("fя𐀀","")]
Represent a position in a text.
lengthAsPosition :: Rope -> Position Source #
Measure text length as an amount of lines and columns, O(1).
>>>:set -XOverloadedStrings>>>lengthAsPosition "f𐀀"Position {posLine = 0, posColumn = 3}>>>lengthAsPosition "f\n𐀀"Position {posLine = 1, posColumn = 2}>>>lengthAsPosition "f\n𐀀\n"Position {posLine = 2, posColumn = 0}
splitAtPosition :: Position -> Rope -> Maybe (Rope, Rope) Source #
Combination of splitAtLine and subsequent splitAt.
 Time is linear in posColumn and logarithmic in 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𐀀я"Just ("f\n𐀀","я")>>>splitAtPosition (Position 0 2) "f\n𐀀я"Just ("f\n","𐀀я")>>>splitAtPosition (Position 0 3) "f\n𐀀я"Nothing>>>splitAtPosition (Position 0 4) "f\n𐀀я"Just ("f\n𐀀","я")