Data.Rope.UTF16.Internal

rope-utf16-splay-0.4.0.0: Ropes optimised for updating using UTF-16 code units and row/column pairs.

Safe Haskell | None
Language | Haskell2010

Data.Rope.UTF16.Internal

Contents

- Queries
- Conversions
- Transformations
- Chunking
- UTF-16 code unit indexing
- Lines
- Breaking by predicate
- Folds
- Special folds

Synopsis

- data Chunk = Chunk {
  - chunkText :: !Text
  - chunkMeasure :: !Position
  }
- chunk :: Text -> Chunk
- newtype Rope = Rope {
  - unrope :: SplayTree Position Chunk
  }
- chunkLength :: Int
- null :: Rope -> Bool
- length :: Rope -> Int
- rows :: Rope -> Int
- columns :: Rope -> Int
- toText :: Rope -> Text
- toLazyText :: Rope -> Text
- fromText :: Text -> Rope
- fromShortText :: Text -> Rope
- toString :: Rope -> String
- map :: (Char -> Char) -> Rope -> Rope
- intercalate :: Rope -> [Rope] -> Rope
- toChunks :: Rope -> [Text]
- unconsChunk :: Rope -> Maybe (Text, Rope)
- unsnocChunk :: Rope -> Maybe (Rope, Text)
- splitAt :: Int -> Rope -> (Rope, Rope)
- take :: Int -> Rope -> Rope
- drop :: Int -> Rope -> Rope
- rowColumnCodeUnits :: RowColumn -> Rope -> Int
- codeUnitsRowColumn :: Int -> Rope -> RowColumn
- splitAtLine :: Int -> Rope -> (Rope, Rope)
- span :: (Char -> Bool) -> Rope -> (Rope, Rope)
- break :: (Char -> Bool) -> Rope -> (Rope, Rope)
- takeWhile :: (Char -> Bool) -> Rope -> Rope
- dropWhile :: (Char -> Bool) -> Rope -> Rope
- foldl :: (a -> Char -> a) -> a -> Rope -> a
- foldl' :: (a -> Char -> a) -> a -> Rope -> a
- foldr :: (Char -> a -> a) -> a -> Rope -> a
- any :: (Char -> Bool) -> Rope -> Bool
- all :: (Char -> Bool) -> Rope -> Bool

# Documentation

data Chunk #

Constructors

Chunk |
Fields chunkText :: !Text chunkMeasure :: !Position

#### Instances

Instances details

Semigroup Chunk # |
Instance details Defined in Data.Rope.UTF16.Internal Methods (<>) :: Chunk -> Chunk -> Chunk # sconcat :: NonEmpty Chunk -> Chunk # stimes :: Integral b => b -> Chunk -> Chunk #
Show Chunk # |
Instance details Defined in Data.Rope.UTF16.Internal Methods showsPrec :: Int -> Chunk -> ShowS # show :: Chunk -> String # showList :: [Chunk] -> ShowS #
Measured Position Chunk # |
Instance details Defined in Data.Rope.UTF16.Internal Methods measure :: Chunk -> Position #

chunk :: Text -> Chunk #

newtype Rope #

A `SplayTree` of `Text` values optimised for being indexed by and modified at UTF-16 code units and row/column (`RowColumn`) positions. Internal invariant: No empty `Chunk`s in the `SplayTree`

Constructors

Rope |
Fields unrope :: SplayTree Position Chunk

#### Instances

Instances details

Monoid Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods mempty :: Rope # mappend :: Rope -> Rope -> Rope # mconcat :: [Rope] -> Rope #
Semigroup Rope # | Append joins adjacent chunks if that can be done while staying below `chunkLength`.
Instance details Defined in Data.Rope.UTF16.Internal Methods (<>) :: Rope -> Rope -> Rope # sconcat :: NonEmpty Rope -> Rope # stimes :: Integral b => b -> Rope -> Rope #
IsString Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods fromString :: String -> Rope #
Show Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods showsPrec :: Int -> Rope -> ShowS # show :: Rope -> String # showList :: [Rope] -> ShowS #
Eq Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods (==) :: Rope -> Rope -> Bool # (/=) :: Rope -> Rope -> Bool #
Ord Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods compare :: Rope -> Rope -> Ordering # (<) :: Rope -> Rope -> Bool # (<=) :: Rope -> Rope -> Bool # (>) :: Rope -> Rope -> Bool # (>=) :: Rope -> Rope -> Bool # max :: Rope -> Rope -> Rope # min :: Rope -> Rope -> Rope #
Measured Position Rope # |
Instance details Defined in Data.Rope.UTF16.Internal Methods measure :: Rope -> Position #

chunkLength :: Int #

The maximum length, in UTF-8 code units, of a chunk

# Queries

null :: Rope -> Bool #

Is the rope empty?

Since: 0.2.0.0

length :: Rope -> Int #

Length in UTF-16 code units (not characters)

rows :: Rope -> Int #

The number of newlines in the rope

Since: 0.3.0.0

columns :: Rope -> Int #

The number of UTF-16 code units (not characters) since the last newline or the start of the rope

Since: 0.3.0.0

# Conversions

toText :: Rope -> Text #

toLazyText :: Rope -> Text #

fromText :: Text -> Rope #

fromShortText :: Text -> Rope #

toString :: Rope -> String #

# Transformations

map :: (Char -> Char) -> Rope -> Rope #

Map over the characters of a rope

Since: 0.3.0.0

intercalate :: Rope -> [Rope] -> Rope #

Concatenate the interspersion of a rope between the elements of a list of ropes

Since: 0.3.0.0

# Chunking

toChunks :: Rope -> [Text] #

The raw `Text` data that the `Rope` is built from

unconsChunk :: Rope -> Maybe (Text, Rope) #

Get the first chunk and the rest of the `Rope` if non-empty

unsnocChunk :: Rope -> Maybe (Rope, Text) #

Get the last chunk and the rest of the `Rope` if non-empty

# UTF-16 code unit indexing

splitAt :: Int -> Rope -> (Rope, Rope) #

Split the rope at the nth UTF-16 code unit (not character)

take :: Int -> Rope -> Rope #

Take the first n UTF-16 code units (not characters)

drop :: Int -> Rope -> Rope #

Drop the first n UTF-16 code units (not characters)

rowColumnCodeUnits :: RowColumn -> Rope -> Int #

Get the UTF-16 code unit index in the rope that corresponds to a `RowColumn` position

Since: 0.2.0.0

codeUnitsRowColumn :: Int -> Rope -> RowColumn #

Get the `RowColumn` position that corresponds to a UTF-16 code unit index in the rope

Since: 0.3.2.0

# Lines

splitAtLine :: Int -> Rope -> (Rope, Rope) #

Split the rope immediately after the i:th newline

Since: 0.3.1.0

# Breaking by predicate

span :: (Char -> Bool) -> Rope -> (Rope, Rope) #

    span f r = (takeWhile f r, dropWhile f r)

break :: (Char -> Bool) -> Rope -> (Rope, Rope) #

    break f = span (not . f)

takeWhile :: (Char -> Bool) -> Rope -> Rope #

    takeWhile f = fst . span f

dropWhile :: (Char -> Bool) -> Rope -> Rope #

    dropWhile f = snd . span f

# Folds

foldl :: (a -> Char -> a) -> a -> Rope -> a #

Fold left

Since: 0.3.0.0

foldl' :: (a -> Char -> a) -> a -> Rope -> a #

A strict version of `foldl`

Since: 0.3.0.0

foldr :: (Char -> a -> a) -> a -> Rope -> a #

Fold right

Since: 0.3.0.0

# Special folds

any :: (Char -> Bool) -> Rope -> Bool #

Do any characters in the rope satisfy the predicate?

Since: 0.3.0.0

all :: (Char -> Bool) -> Rope -> Bool #

Do all characters in the rope satisfy the predicate?

Since: 0.3.0.0