Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
TextBuilderDev
Synopsis
- data TextBuilder
- toText :: TextBuilder -> Text
- buildText :: TextBuilder -> Text
- length :: TextBuilder -> Int
- null :: TextBuilder -> Bool
- putToStdOut :: TextBuilder -> IO ()
- putToStdErr :: TextBuilder -> IO ()
- putLnToStdOut :: TextBuilder -> IO ()
- putLnToStdErr :: TextBuilder -> IO ()
- force :: TextBuilder -> TextBuilder
- intercalate :: Foldable f => TextBuilder -> f TextBuilder -> TextBuilder
- intercalateMap :: Foldable f => TextBuilder -> (a -> TextBuilder) -> f a -> TextBuilder
- padFromLeft :: Int -> Char -> TextBuilder -> TextBuilder
- padFromRight :: Int -> Char -> TextBuilder -> TextBuilder
- text :: Text -> TextBuilder
- lazyText :: Text -> TextBuilder
- string :: String -> TextBuilder
- asciiByteString :: ByteString -> TextBuilder
- hexData :: ByteString -> TextBuilder
- char :: Char -> TextBuilder
- unicodeCodePoint :: Int -> TextBuilder
- utf16CodeUnits1 :: Word16 -> TextBuilder
- utf16CodeUnits2 :: Word16 -> Word16 -> TextBuilder
- utf8CodeUnits1 :: Word8 -> TextBuilder
- utf8CodeUnits2 :: Word8 -> Word8 -> TextBuilder
- utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> TextBuilder
- utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> TextBuilder
- decimal :: Integral a => a -> TextBuilder
- unsignedDecimal :: Integral a => a -> TextBuilder
- fixedUnsignedDecimal :: Integral a => Int -> a -> TextBuilder
- thousandSeparatedDecimal :: Integral a => Char -> a -> TextBuilder
- thousandSeparatedUnsignedDecimal :: Integral a => Char -> a -> TextBuilder
- dataSizeInBytesInDecimal :: Integral a => Char -> a -> TextBuilder
- unsignedBinary :: Integral a => a -> TextBuilder
- unsignedPaddedBinary :: (Integral a, FiniteBits a) => a -> TextBuilder
- finiteBitsUnsignedBinary :: FiniteBits a => a -> TextBuilder
- hexadecimal :: Integral a => a -> TextBuilder
- unsignedHexadecimal :: Integral a => a -> TextBuilder
- decimalDigit :: Integral a => a -> TextBuilder
- hexadecimalDigit :: Integral a => a -> TextBuilder
- fixedDouble :: Int -> Double -> TextBuilder
- doublePercent :: Int -> Double -> TextBuilder
- utcTimeInIso8601 :: UTCTime -> TextBuilder
- utcTimestampInIso8601 :: Int -> Int -> Int -> Int -> Int -> Int -> TextBuilder
- intervalInSeconds :: RealFrac seconds => seconds -> TextBuilder
- diffTimeCompact :: DiffTime -> TextBuilder
- picosecondsCompact :: Integer -> TextBuilder
- class IsomorphicToTextBuilder a where
- toTextBuilder :: a -> TextBuilder
- fromTextBuilder :: TextBuilder -> a
Documentation
data TextBuilder Source #
Specification of how to efficiently construct strict Text
.
Provides instances of Semigroup
and Monoid
, which have complexity of O(1).
Instances
Accessors
toText :: TextBuilder -> Text Source #
Execute the builder producing a strict text.
length :: TextBuilder -> Int Source #
Get the amount of characters.
null :: TextBuilder -> Bool Source #
Check whether the builder is empty.
Output IO
putToStdOut :: TextBuilder -> IO () Source #
Put builder, to stdout.
putToStdErr :: TextBuilder -> IO () Source #
Put builder, to stderr.
putLnToStdOut :: TextBuilder -> IO () Source #
Put builder, followed by a line, to stdout.
putLnToStdErr :: TextBuilder -> IO () Source #
Put builder, followed by a line, to stderr.
Constructors
Builder manipulators
force :: TextBuilder -> TextBuilder Source #
Run the builder and pack the produced text into a new builder.
Useful to have around builders that you reuse,
because a forced builder is much faster,
since it's virtually a single call memcopy
.
intercalate :: Foldable f => TextBuilder -> f TextBuilder -> TextBuilder Source #
Intercalate builders.
intercalateMap :: Foldable f => TextBuilder -> (a -> TextBuilder) -> f a -> TextBuilder Source #
Intercalate projecting values to builder.
padFromLeft :: Int -> Char -> TextBuilder -> TextBuilder Source #
Pad a builder from the left side to the specified length with the specified character.
padFromRight :: Int -> Char -> TextBuilder -> TextBuilder Source #
Pad a builder from the right side to the specified length with the specified character.
Textual
text :: Text -> TextBuilder Source #
Strict text.
lazyText :: Text -> TextBuilder Source #
Lazy text.
string :: String -> TextBuilder Source #
String.
asciiByteString :: ByteString -> TextBuilder Source #
ASCII byte string.
It's your responsibility to ensure that the bytes are in proper range, otherwise the produced text will be broken.
hexData :: ByteString -> TextBuilder Source #
Hexadecimal readable representation of binary data.
Character
char :: Char -> TextBuilder Source #
Unicode character.
Low-level character
unicodeCodePoint :: Int -> TextBuilder Source #
Unicode code point.
utf16CodeUnits1 :: Word16 -> TextBuilder Source #
Single code-unit UTF-16 character.
utf16CodeUnits2 :: Word16 -> Word16 -> TextBuilder Source #
Double code-unit UTF-16 character.
utf8CodeUnits1 :: Word8 -> TextBuilder Source #
Single code-unit UTF-8 character.
utf8CodeUnits2 :: Word8 -> Word8 -> TextBuilder Source #
Double code-unit UTF-8 character.
utf8CodeUnits3 :: Word8 -> Word8 -> Word8 -> TextBuilder Source #
Triple code-unit UTF-8 character.
utf8CodeUnits4 :: Word8 -> Word8 -> Word8 -> Word8 -> TextBuilder Source #
UTF-8 character out of 4 code units.
Integers
Decimal
decimal :: Integral a => a -> TextBuilder Source #
Decimal representation of an integral value.
unsignedDecimal :: Integral a => a -> TextBuilder Source #
Decimal representation of an unsigned integral value.
fixedUnsignedDecimal :: Integral a => Int -> a -> TextBuilder Source #
thousandSeparatedDecimal :: Integral a => Char -> a -> TextBuilder Source #
Decimal representation of an integral value with thousands separated by the specified character.
thousandSeparatedUnsignedDecimal :: Integral a => Char -> a -> TextBuilder Source #
Decimal representation of an unsigned integral value with thousands separated by the specified character.
dataSizeInBytesInDecimal :: Integral a => Char -> a -> TextBuilder Source #
Data size in decimal notation over amount of bytes.
Binary
unsignedBinary :: Integral a => a -> TextBuilder Source #
Unsigned binary number.
unsignedPaddedBinary :: (Integral a, FiniteBits a) => a -> TextBuilder Source #
Unsigned binary number.
finiteBitsUnsignedBinary :: FiniteBits a => a -> TextBuilder Source #
A less general but faster alternative to unsignedBinary
.
Hexadecimal
hexadecimal :: Integral a => a -> TextBuilder Source #
Hexadecimal representation of an integral value.
unsignedHexadecimal :: Integral a => a -> TextBuilder Source #
Unsigned hexadecimal representation of an integral value.
Digits
decimalDigit :: Integral a => a -> TextBuilder Source #
Decimal digit.
hexadecimalDigit :: Integral a => a -> TextBuilder Source #
Hexadecimal digit.
Real
Arguments
:: Int | Amount of decimals after point. |
-> Double | |
-> TextBuilder |
Double with a fixed number of decimal places.
Arguments
:: Int | Amount of decimals after point. |
-> Double | |
-> TextBuilder |
Double multiplied by 100 with a fixed number of decimal places applied and followed by a percent-sign.
Time
utcTimestampInIso8601 Source #
General template for formatting date values according to the ISO8601 standard. The format is the following:
2021-11-24T12:11:02Z
Integrations with various time-libraries can be easily derived from that.
intervalInSeconds :: RealFrac seconds => seconds -> TextBuilder Source #
Time interval in seconds.
The format is the following:
DD:HH:MM:SS
Directly applicable to DiffTime
and NominalDiffTime
.
diffTimeCompact :: DiffTime -> TextBuilder Source #
DiffTime in a compact decimal format based on picosecondsCompact
.
picosecondsCompact :: Integer -> TextBuilder Source #
Amount of picoseconds represented in a compact decimal format using suffixes.
E.g., the following is 1_230_000_000
picoseconds or 1.23 milliseconds or 1230 microseconds:
1230us
Classes
class IsomorphicToTextBuilder a where Source #
Evidence that there exists an unambiguous way to convert a type to and from TextBuilder.
Unlike conversion classes from other libs this class is lawful. The law is:
fromTextBuilder
.toTextBuilder
=id
This class does not provide implicit rendering, such as from integer to its decimal representation. There are multiple ways of representing an integer as text (e.g., hexadecimal, binary). The non-ambiguity is further enforced by the presence of the inverse conversion. In the integer case there is no way to read it from a textual form without a possibility of failing (e.g., when the input string cannot be parsed as an integer).
If you're looking for such conversion classes, this library is not a place for them, since there can be infinite amount of flavours of conversions. They are context-dependent and as such should be defined as part of the domain.
Instances
IsomorphicToTextBuilder Text Source # | |
Defined in TextBuilderDev | |
IsomorphicToTextBuilder Builder Source # | |
Defined in TextBuilderDev Methods toTextBuilder :: Builder -> TextBuilder Source # fromTextBuilder :: TextBuilder -> Builder Source # | |
IsomorphicToTextBuilder Text Source # | |
Defined in TextBuilderDev | |
IsomorphicToTextBuilder StrictBuilder Source # | |
Defined in TextBuilderDev Methods | |
IsomorphicToTextBuilder TextBuilder Source # | |
Defined in TextBuilderDev Methods | |
IsomorphicToTextBuilder String Source # | |
Defined in TextBuilderDev Methods toTextBuilder :: String -> TextBuilder Source # fromTextBuilder :: TextBuilder -> String Source # |