hledger-lib-1.2: Core data types, parsers and functionality for the hledger accounting tools

Safe Haskell | None
Language | Haskell2010

Hledger.Utils.Text

Description

Text formatting helpers, ported from String as needed. There may be better alternatives out there.

Synopsis

- textstrip :: Text -> Text
- textlstrip :: Text -> Text
- textrstrip :: Text -> Text
- textElideRight :: Int -> Text -> Text
- quoteIfSpaced :: Text -> Text
- quotechars :: [Char]
- whitespacechars :: [Char]
- escapeDoubleQuotes :: Text -> Text
- escapeSingleQuotes :: Text -> Text
- stripquotes :: Text -> Text
- isSingleQuoted :: Text -> Bool
- isDoubleQuoted :: Text -> Bool
- textUnbracket :: Text -> Text
- textConcatTopPadded :: [Text] -> Text
- difforzero :: (Num a, Ord a) => a -> a -> a
- fitText :: Maybe Int -> Maybe Int -> Bool -> Bool -> Text -> Text
- textPadLeftWide :: Int -> Text -> Text
- textPadRightWide :: Int -> Text -> Text
- textTakeWidth :: Int -> Text -> Text
- textWidth :: Text -> Int

# Documentation

textstrip :: Text -> Text Source #

Remove leading and trailing whitespace.

textlstrip :: Text -> Text Source #

Remove leading whitespace.

textrstrip :: Text -> Text Source #

Remove trailing whitespace.

textElideRight :: Int -> 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.

quotechars :: [Char] Source #

whitespacechars :: [Char] Source #

escapeDoubleQuotes :: Text -> Text Source #

escapeSingleQuotes :: Text -> Text Source #

stripquotes :: Text -> Text Source #

Strip one matching pair of single or double quotes on the ends of a string.

isSingleQuoted :: Text -> Bool Source #

isDoubleQuoted :: Text -> Bool Source #

textUnbracket :: Text -> Text Source #

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.

difforzero :: (Num a, Ord a) => a -> a -> a Source #

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.

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).

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 "りんご" = "り".

textWidth :: Text -> Int Source #

Calculate the designated render width of a string, taking into account wide characters and line breaks (the longest line within a multi-line string determines the width ).