Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
TextBuilderCore
Synopsis
- data TextBuilder = TextBuilder Int (forall s. MArray s -> Int -> ST s Int)
- isEmpty :: TextBuilder -> Bool
- toText :: TextBuilder -> Text
- string :: String -> TextBuilder
- text :: Text -> TextBuilder
- lazyText :: Text -> TextBuilder
- char :: Char -> TextBuilder
- unicodeCodepoint :: Int -> TextBuilder
- unsafeChars :: Int -> [Char] -> TextBuilder
- unsafeSeptets :: Int -> [Word8] -> TextBuilder
- unsafeReverseSeptets :: Int -> [Word8] -> TextBuilder
Documentation
data TextBuilder Source #
Composable specification of how to efficiently construct strict Text
.
Provides instances of Semigroup
and Monoid
, which have complexity of O(1).
Constructors
TextBuilder | |
Fields
|
Instances
Arbitrary TextBuilder Source # | |
Defined in TextBuilderCore | |
IsString TextBuilder Source # | |
Defined in TextBuilderCore Methods fromString :: String -> TextBuilder # | |
Monoid TextBuilder Source # | |
Defined in TextBuilderCore Methods mempty :: TextBuilder # mappend :: TextBuilder -> TextBuilder -> TextBuilder # mconcat :: [TextBuilder] -> TextBuilder # | |
Semigroup TextBuilder Source # | |
Defined in TextBuilderCore Methods (<>) :: TextBuilder -> TextBuilder -> TextBuilder # sconcat :: NonEmpty TextBuilder -> TextBuilder # stimes :: Integral b => b -> TextBuilder -> TextBuilder # | |
Show TextBuilder Source # | |
Defined in TextBuilderCore Methods showsPrec :: Int -> TextBuilder -> ShowS # show :: TextBuilder -> String # showList :: [TextBuilder] -> ShowS # | |
Eq TextBuilder Source # | |
Defined in TextBuilderCore |
Destructors
isEmpty :: TextBuilder -> Bool Source #
Check whether the builder is empty.
toText :: TextBuilder -> Text Source #
Execute the builder producing a strict text.
Constructors
Text
string :: String -> TextBuilder Source #
Construct from a list of characters.
text :: Text -> TextBuilder Source #
Strict text.
lazyText :: Text -> TextBuilder Source #
Lazy text.
Character
char :: Char -> TextBuilder Source #
Unicode character.
unicodeCodepoint :: Int -> TextBuilder Source #
Safe Unicode codepoint with invalid values replaced by the �
char (codepoint 0xfffd
),
which is the same as what Data.Text.
does.pack
Primitives
Arguments
:: Int | Maximum size of the provided list of characters. Warning: Must be greater than or equal to the length of the list. |
-> [Char] | |
-> TextBuilder |
Helper for constructing from char producers a bit more efficiently than via (text . fromString)
.
>>>
unsafeChars 3 "123"
"123"
>>>
unsafeChars 4 "123"
"123"
Arguments
:: Int | Maximum size of the byte array to allocate. Must be greater than or equal to the length of the list. Warning: If it is smaller, bad things will happen. We'll be writing outside of the allocated array. |
-> [Word8] | List of bytes to write. Warning: It is your responsibility to ensure that the bytes are smaller than 128. Otherwise the produced text will have a broken encoding. To ensure of optimization kicking in it is advised to construct the list using |
-> TextBuilder |
Provides a unified way to deal with the byte array regardless of the version of the text
library.
Keep in mind that prior to text-2.0
, the array was operating on Word16
values due to the library abstracting over UTF-16
.
Starting from text-2.0
, the array operates on Word8
values and the library abstracts over UTF-8
.
This function is useful for building ASCII values.
>>>
unsafeSeptets 3 (fmap (+48) [1, 2, 3])
"123"
>>>
unsafeSeptets 4 (fmap (+48) [1, 2, 3])
"123"
Arguments
:: Int | Precise amount of bytes in the list. Needs to be precise, because writing happens in reverse order. Warning: If it is smaller, bad things will happen. We'll be writing outside of the allocated array. |
-> [Word8] | List of bytes to write in reverse order. Warning: It is your responsibility to ensure that the bytes are smaller than 128. Otherwise the produced text will have a broken encoding. To ensure of optimization kicking in it is advised to construct the list using |
-> TextBuilder |
Same as unsafeSeptets
, but writes the bytes in reverse order and requires the size to be precise.
>>>
unsafeReverseSeptets 3 (fmap (+48) [1, 2, 3])
"321"