Copyright | (C) 2011-2019 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Text.Trifecta.Rope
Description
A rope is a data strucure to efficiently store and manipulate long strings. Wikipedia provides a nice overview: https://en.wikipedia.org/wiki/Rope_(data_structure)
Synopsis
- data Rope = Rope !Delta !(FingerTree Delta Strand)
- rope :: FingerTree Delta Strand -> Rope
- ropeBS :: ByteString -> Rope
- data Strand
- = Strand !ByteString !Delta
- | Skipping !Delta
- strand :: ByteString -> Strand
- strands :: Rope -> FingerTree Delta Strand
- grabRest :: Delta -> Rope -> r -> (Delta -> ByteString -> r) -> r
- grabLine :: Delta -> Rope -> r -> (Delta -> ByteString -> r) -> r
Documentation
Constructors
Rope !Delta !(FingerTree Delta Strand) |
Instances
Monoid Rope Source # | |
Semigroup Rope Source # | |
Show Rope Source # | |
HasBytes Rope Source # | |
HasDelta Rope Source # | |
Measured Delta Rope Source # | |
Defined in Text.Trifecta.Rope | |
Reducer ByteString Rope Source # | |
Defined in Text.Trifecta.Rope Methods unit :: ByteString -> Rope # snoc :: Rope -> ByteString -> Rope # cons :: ByteString -> Rope -> Rope # | |
Reducer Rope Rope Source # | |
Reducer Strand Rope Source # | |
Reducer [Char] Rope Source # | |
ropeBS :: ByteString -> Rope Source #
Construct a Rope
out of a single ByteString
strand.
Constructors
Strand !ByteString !Delta | Data of a certain length |
Skipping !Delta | Absence of data of a certain length |
Instances
strand :: ByteString -> Strand Source #
Construct a single Strand
out of a ByteString
.
Arguments
:: Delta | Initial offset |
-> Rope | Input |
-> r | Default value if there is no input left |
-> (Delta -> ByteString -> r) | If there is some input left, create an |
-> r |
Grab the entire rest of the input Rope
, starting at an initial offset, or
return a default if we’re already at or beyond the end. Also see grabLine
.
Extract a suffix of a certain length from the input:
>>>
grabRest (delta ("Hello " :: ByteString)) (ropeBS "Hello World\nLorem") Nothing (\x y -> Just (x, Lazy.toString y))
Just (Columns 6 6,"World\nLorem")
Same deal, but over multiple strands:
>>>
grabRest (delta ("Hel" :: ByteString)) (ropeBS "Hello" <> ropeBS "World") Nothing (\x y -> Just (x, Lazy.toString y))
Just (Columns 3 3,"loWorld")
When the offset is too long, fall back to a default:
>>>
grabRest (delta ("OffetTooLong" :: ByteString)) (ropeBS "Hello") Nothing (\x y -> Just (x, Lazy.toString y))
Nothing
Arguments
:: Delta | Initial offset |
-> Rope | Input |
-> r | Default value if there is no input left |
-> (Delta -> ByteString -> r) | If there is some input left, create an |
-> r |
Grab the rest of the line at a certain offset in the input Rope
, or
return a default if there is no newline left in the input. Also see
grabRest
.
>>>
grabLine (delta ("Hello " :: ByteString)) (ropeBS "Hello" <> ropeBS " World\nLorem") Nothing (\x y -> Just (x, Strict.toString y))
Just (Columns 6 6,"World\n")