| Copyright | (c) Dong Han 2017-2019 |
|---|---|
| License | BSD |
| Maintainer | winterland1989@gmail.com |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Std.Data.TextBuilder
Contents
Description
UTF8 compatible textual builders.
Synopsis
- newtype TextBuilder a = TextBuilder {}
- buildText :: TextBuilder a -> Text
- stringUTF8 :: String -> TextBuilder ()
- charUTF8 :: Char -> TextBuilder ()
- string7 :: String -> TextBuilder ()
- char7 :: Char -> TextBuilder ()
- text :: Text -> TextBuilder ()
- data IFormat = IFormat {}
- defaultIFormat :: IFormat
- data Padding
- int :: (Integral a, Bounded a) => a -> TextBuilder ()
- intWith :: (Integral a, Bounded a) => IFormat -> a -> TextBuilder ()
- integer :: Integer -> TextBuilder ()
- hex :: (FiniteBits a, Integral a) => a -> TextBuilder ()
- heX :: (FiniteBits a, Integral a) => a -> TextBuilder ()
- data FFormat
- double :: Double -> TextBuilder ()
- doubleWith :: FFormat -> Maybe Int -> Double -> TextBuilder ()
- float :: Float -> TextBuilder ()
- floatWith :: FFormat -> Maybe Int -> Float -> TextBuilder ()
- scientific :: Scientific -> TextBuilder ()
- scientificWith :: FFormat -> Maybe Int -> Scientific -> TextBuilder ()
Textual Builder
newtype TextBuilder a Source #
Buidlers which guarantee UTF-8 encoding, thus can be used to build text directly.
Notes on IsString instance: It's recommended to use IsString instance instead of stringUTF8
or string7 since there's a rewrite rule to turn encoding loop into a memcpy, which is much faster.
Different from 'Builder ()', 'TextBuilder ()''s IsString instance will gives desired UTF8 guarantees:
- "NUL" will be written directly as
x00. xD800~xDFFFwill be replaced by replacement char.
Constructors
| TextBuilder | |
Instances
buildText :: TextBuilder a -> Text Source #
Basic UTF8 builders
stringUTF8 :: String -> TextBuilder () Source #
Turn String into TextBuilder with UTF8 encoding
Illegal codepoints will be written as replacementChars. This function will be rewritten into a memcpy if possible, (running a fast UTF-8 validation at runtime first).
charUTF8 :: Char -> TextBuilder () Source #
Turn Char into TextBuilder with UTF8 encoding
Illegal codepoints will be written as replacementChars.
string7 :: String -> TextBuilder () Source #
Turn String into TextBuilder with ASCII7 encoding
Codepoints beyond '\x7F' will be chopped.
char7 :: Char -> TextBuilder () Source #
Turn Char into TextBuilder with ASCII7 encoding
Codepoints beyond '\x7F' will be chopped.
text :: Text -> TextBuilder () Source #
Numeric builders
Integral type formatting
Integral formatting options.
Constructors
| IFormat | |
defaultIFormat :: IFormat Source #
defaultIFormat = IFormat 0 NoPadding False Decimal
Constructors
| NoPadding | |
| ZeroPadding | |
| LeftSpacePadding | |
| RightSpacePadding |
Fixded size hexidecimal formatting
hex :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #
Format a FiniteBits Integral type into hex nibbles.
heX :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #
The UPPERCASED version of hex.
IEEE float formating
Control the rendering of floating point numbers.
Constructors
| Exponent | Scientific notation (e.g. |
| Fixed | Standard decimal notation. |
| Generic | Use decimal notation for values between |
Instances
| Enum FFormat Source # | |
| Read FFormat Source # | |
| Show FFormat Source # | |
double :: Double -> TextBuilder () Source #
Decimal encoding of an IEEE Double.
Using standard decimal notation for arguments whose absolute value lies
between 0.1 and 9,999,999, and scientific notation otherwise.
Arguments
| :: FFormat | |
| -> Maybe Int | Number of decimal places to render. |
| -> Double | |
| -> TextBuilder () |
Format double-precision float using drisu3 with dragon4 fallback.
float :: Float -> TextBuilder () Source #
Decimal encoding of an IEEE Float.
Using standard decimal notation for arguments whose absolute value lies
between 0.1 and 9,999,999, and scientific notation otherwise.
Arguments
| :: FFormat | |
| -> Maybe Int | Number of decimal places to render. |
| -> Float | |
| -> TextBuilder () |
Format single-precision float using drisu3 with dragon4 fallback.
scientific :: Scientific -> TextBuilder () Source #
A Builder which renders a scientific number to full
precision, using standard decimal notation for arguments whose
absolute value lies between 0.1 and 9,999,999, and scientific
notation otherwise.
Arguments
| :: FFormat | |
| -> Maybe Int | Number of decimal places to render. |
| -> Scientific | |
| -> TextBuilder () |
Like scientific but provides rendering options.