Safe Haskell | None |
---|---|
Language | Haskell2010 |
Text formatting helpers, ported from String as needed. There may be better alternatives out there.
Synopsis
- textUnbracket :: Text -> Text
- wrap :: Text -> Text -> Text -> Text
- textChomp :: Text -> Text
- quoteIfSpaced :: Text -> Text
- textQuoteIfNeeded :: Text -> Text
- escapeDoubleQuotes :: Text -> Text
- stripquotes :: Text -> Text
- textElideRight :: Int -> Text -> Text
- formatText :: Bool -> Maybe Int -> Maybe Int -> Text -> Text
- textConcatTopPadded :: [Text] -> Text
- textConcatBottomPadded :: [Text] -> Text
- fitText :: Maybe Int -> Maybe Int -> Bool -> Bool -> Text -> Text
- linesPrepend :: Text -> Text -> Text
- linesPrepend2 :: Text -> Text -> Text -> Text
- unlinesB :: [Builder] -> Builder
- data WideBuilder = WideBuilder {}
- wbToText :: WideBuilder -> Text
- wbUnpack :: WideBuilder -> String
- textWidth :: Text -> Int
- textTakeWidth :: Int -> Text -> Text
- textPadLeftWide :: Int -> Text -> Text
- textPadRightWide :: Int -> Text -> Text
- readDecimal :: Text -> Integer
- tests_Text :: TestTree
Documentation
textUnbracket :: Text -> Text Source #
quoteIfSpaced :: Text -> Text Source #
Wrap a string in double quotes, and -prefix any embedded single quotes, if it contains whitespace and is not already single- or double-quoted.
textQuoteIfNeeded :: Text -> Text Source #
escapeDoubleQuotes :: Text -> Text Source #
stripquotes :: Text -> Text Source #
Strip one matching pair of single or double quotes on the ends of a string.
formatText :: Bool -> Maybe Int -> Maybe Int -> Text -> Text Source #
Clip and pad a string to a minimum & maximum width, andor leftright justify it. Works on multi-line strings too (but will rewrite non-unix line endings).
textConcatTopPadded :: [Text] -> Text Source #
Join several multi-line strings as side-by-side rectangular strings of the same height, top-padded. Treats wide characters as double width.
textConcatBottomPadded :: [Text] -> Text Source #
Join several multi-line strings as side-by-side rectangular strings of the same height, bottom-padded. Treats wide characters as double width.
fitText :: Maybe Int -> Maybe Int -> Bool -> Bool -> Text -> Text Source #
General-purpose wide-char-aware single-line text layout function. It can left- or right-pad a short string to a minimum width. It can left- or right-clip a long string to a maximum width, optionally inserting an ellipsis (the third argument). It clips and pads on the right when the fourth argument is true, otherwise on the left. It treats wide characters as double width.
linesPrepend2 :: Text -> Text -> Text -> Text Source #
Add a prefix to the first line of a string, and a different prefix to the remaining lines.
unlinesB :: [Builder] -> Builder Source #
Join a list of Text Builders with a newline after each item.
data WideBuilder Source #
Helper for constructing Builders while keeping track of text width.
Instances
Semigroup WideBuilder Source # | |
Defined in Text.WideString (<>) :: WideBuilder -> WideBuilder -> WideBuilder # sconcat :: NonEmpty WideBuilder -> WideBuilder # stimes :: Integral b => b -> WideBuilder -> WideBuilder # | |
Monoid WideBuilder Source # | |
Defined in Text.WideString mempty :: WideBuilder # mappend :: WideBuilder -> WideBuilder -> WideBuilder # mconcat :: [WideBuilder] -> WideBuilder # |
wbToText :: WideBuilder -> Text Source #
Convert a WideBuilder to a strict Text.
wbUnpack :: WideBuilder -> String Source #
Convert a WideBuilder to a String.
textWidth :: Text -> Int Source #
Calculate the render width of a string, considering wide characters (counted as double width)
textTakeWidth :: Int -> Text -> Text Source #
Double-width-character-aware string truncation. Take as many characters as possible from a string without exceeding the specified width. Eg textTakeWidth 3 "りんご" = "り".
textPadLeftWide :: Int -> Text -> Text Source #
Left-pad a text to the specified width. Treats wide characters as double width. Works on multi-line texts too (but will rewrite non-unix line endings).
textPadRightWide :: Int -> Text -> Text Source #
Right-pad a string to the specified width. Treats wide characters as double width. Works on multi-line strings too (but will rewrite non-unix line endings).
readDecimal :: Text -> Integer Source #
Read a decimal number from a Text. Assumes the input consists only of digit characters.