Safe Haskell | None |
---|---|
Language | Haskell2010 |
Here are the nice things from text that you get (thanks to a restrictive lower bound) but that aren't documented elsewhere in this module:
- The
takeWhileEnd
function. - An instance for
Semigroup
. - An instance for
printf
(i.e. you can use aText
as one ofprintf
's arguments). - An instance for
Binary
.
- module Data.Text
- module Data.Text.IO
- module Data.Text.Encoding
- type LText = Text
- toStrict :: ToStrict t => t -> Text
- toLazy :: ToLazy t => t -> LText
- toBuilder :: ToBuilder t => t -> Builder
- toString :: ToString t => t -> String
- show :: TextShow a => a -> Text
- show' :: Show a => a -> Text
- lshow :: TextShow a => a -> LText
- lshow' :: Show a => a -> LText
- bshow :: TextShow a => a -> Builder
- bshow' :: Show a => a -> Builder
- module Data.Text.Format
- module Data.Text.Buildable
- format :: Params ps => Format -> ps -> Text
- lformat :: Params ps => Format -> ps -> LText
- bformat :: Params ps => Format -> ps -> Builder
- data Builder :: *
- bsingleton :: Char -> Builder
- flush :: Builder
Standard modules from text
module Data.Text
module Data.Text.IO
module Data.Text.Encoding
Lazy Text
Conversion
Showing
show
is a fast variant of show
for Text
/ Builder
that only works for some types – it's very fast for Int
, etc, but doesn't work for types that you have defined yourself. (If you want more instances, import text-show-instances.)
show'
is a shortcut for pack.show
that works for everything with a Show
instance but is slower.
Strict Text
Lazy Text
Builder
Formatting
format
is a function similar to printf
in spirit. Don't forget to enable OverloadedStrings
if you want to use it!
>>>
format "{}+{}={}" (2, 2, 4)
"2+2=4"
If you have only one argument, use a list:
>>>
format "2+2={}" [4]
"2+2=4"
There are some formatting options available:
>>>
format "123 = 0x{}, pi = {}" (hex 123, fixed 5 pi)
"123 = 0x7b, pi = 3.14159"
For more formatters, see Data.Text.Format.
module Data.Text.Format
module Data.Text.Buildable
Builder
A Builder
is an efficient way to build lazy Text
values.
There are several functions for constructing builders, but only one
to inspect them: to extract any data, you have to turn them into
lazy Text
values using toLazyText
.
Internally, a builder constructs a lazy Text
by filling arrays
piece by piece. As each buffer is filled, it is 'popped' off, to
become a new chunk of the resulting lazy Text
. All this is
hidden from the user of the Builder
.