hledger-lib-1.22.2: A reusable library providing the core functionality of hledger
Safe HaskellNone



String formatting helpers, starting to get a bit out of control.



takeEnd :: Int -> [a] -> [a] Source #

Take elements from the end of a list.


quoteIfNeeded :: String -> String Source #

Double-quote this string if it contains whitespace, single quotes or double-quotes, escaping the quotes as needed.

singleQuoteIfNeeded :: String -> String Source #

Single-quote this string if it contains whitespace or double-quotes. No good for strings containing single quotes.

words' :: String -> [String] Source #

Quote-aware version of words - don't split on spaces which are inside quotes. NB correctly handles "a'b" but not "'a'". Can raise an error if parsing fails.

unwords' :: [String] -> String Source #

Quote-aware version of unwords - single-quote strings which contain whitespace

stripAnsi :: String -> String Source #

Strip ANSI escape sequences from a string.

>>> stripAnsi "\ESC[31m-1\ESC[m"

single-line layout

strip :: String -> String Source #

Remove leading and trailing whitespace.

lstrip :: String -> String Source #

Remove leading whitespace.

rstrip :: String -> String Source #

Remove trailing whitespace.

chomp :: String -> String Source #

Remove all trailing newlines/carriage returns.

chomp1 :: String -> String Source #

Remove all trailing newline/carriage returns, leaving just one trailing newline.

singleline :: String -> String Source #

Remove consecutive line breaks, replacing them with single space

formatString :: Bool -> Maybe Int -> Maybe Int -> String -> String 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).

wide-character-aware layout

charWidth :: Char -> Int Source #

Get the designated render width of a character: 0 for a combining character, 1 for a regular character, 2 for a wide character. (Wide characters are rendered as exactly double width in apps and fonts that support it.) (From Pandoc.)

strWidth :: String -> Int Source #

Calculate the render width of a string, considering wide characters (counted as double width)

strWidthAnsi :: String -> Int Source #

Like strWidth, but also strips ANSI escape sequences before calculating the width.

This is no longer used in code, as widths are calculated before adding ANSI escape sequences, but is being kept around for now.

takeWidth :: Int -> String -> String Source #

Double-width-character-aware string truncation. Take as many characters as possible from a string without exceeding the specified width. Eg takeWidth 3 "りんご" = "り".