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

Safe Haskell | None
Language | Haskell2010

Hledger.Utils.String

Contents

- misc
- single-line layout
- multi-line layout
- wide-character-aware layout

Description

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

Synopsis

- lowercase :: String -> String
- uppercase :: String -> String
- underline :: String -> String
- stripbrackets :: String -> String
- unbracket :: String -> String
- quoteIfNeeded :: String -> String
- singleQuoteIfNeeded :: String -> String
- escapeQuotes :: String -> String
- words' :: String -> [String]
- unwords' :: [String] -> String
- strip :: String -> String
- lstrip :: String -> String
- rstrip :: String -> String
- chomp :: String -> String
- elideLeft :: Int -> String -> String
- elideRight :: Int -> String -> String
- formatString :: Bool -> Maybe Int -> Maybe Int -> String -> String
- concatTopPadded :: [String] -> String
- concatBottomPadded :: [String] -> String
- concatOneLine :: [String] -> String
- vConcatLeftAligned :: [String] -> String
- vConcatRightAligned :: [String] -> String
- padtop :: Int -> String -> String
- padbottom :: Int -> String -> String
- padleft :: Int -> String -> String
- padright :: Int -> String -> String
- cliptopleft :: Int -> Int -> String -> String
- fitto :: Int -> Int -> String -> String
- charWidth :: Char -> Int
- strWidth :: String -> Int
- takeWidth :: Int -> String -> String
- fitString :: Maybe Int -> Maybe Int -> Bool -> Bool -> String -> String
- fitStringMulti :: Maybe Int -> Maybe Int -> Bool -> Bool -> String -> String
- padLeftWide :: Int -> String -> String
- padRightWide :: Int -> String -> String

# misc

lowercase :: String -> String Source #

uppercase :: String -> String Source #

underline :: String -> String Source #

stripbrackets :: String -> String Source #

unbracket :: String -> String Source #

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.

escapeQuotes :: String -> String Source #

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

# 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 trailing newlines/carriage returns.

elideLeft :: Int -> String -> String Source #

elideRight :: Int -> String -> String Source #

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

# multi-line layout

concatTopPadded :: [String] -> String Source #

Join several multi-line strings as side-by-side rectangular strings of the same height, top-padded. Treats wide characters as double width.

concatBottomPadded :: [String] -> String Source #

Join several multi-line strings as side-by-side rectangular strings of the same height, bottom-padded. Treats wide characters as double width.

concatOneLine :: [String] -> String Source #

Join multi-line strings horizontally, after compressing each of them to a single line with a comma and space between each original line.

vConcatLeftAligned :: [String] -> String Source #

Join strings vertically, left-aligned and right-padded.

vConcatRightAligned :: [String] -> String Source #

Join strings vertically, right-aligned and left-padded.

padtop :: Int -> String -> String Source #

Convert a multi-line string to a rectangular string top-padded to the specified height.

padbottom :: Int -> String -> String Source #

Convert a multi-line string to a rectangular string bottom-padded to the specified height.

padleft :: Int -> String -> String Source #

Convert a multi-line string to a rectangular string left-padded to the specified width. Treats wide characters as double width.

padright :: Int -> String -> String Source #

Convert a multi-line string to a rectangular string right-padded to the specified width. Treats wide characters as double width.

cliptopleft :: Int -> Int -> String -> String Source #

Clip a multi-line string to the specified width and height from the top left.

fitto :: Int -> Int -> String -> String Source #

Clip and pad a multi-line string to fill the specified width and height.

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

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

fitString :: Maybe Int -> Maybe Int -> Bool -> Bool -> String -> String Source #

General-purpose wide-char-aware single-line string 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.

fitStringMulti :: Maybe Int -> Maybe Int -> Bool -> Bool -> String -> String Source #

A version of fitString that works on multi-line strings, separate for now to avoid breakage. This will rewrite any line endings to unix newlines.

padLeftWide :: Int -> String -> String Source #

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

padRightWide :: Int -> String -> String 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).