HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulehledger-lib-1.52.4GHC2021

Hledger.Utils.String

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

  • 27 values
valuetakeEnd :: Int -> [a] -> [a]
#

Take elements from the end of a list.

misc

10 declarations
valuequoteIfNeeded :: String -> String
#

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

Single-quote this string if it contains whitespace or double-quotes. Does not work for strings containing single quotes.

Try to single- and backslash-quote a string as needed to make it usable as an argument on a (sh/bash) shell command line. At least, well enough to handle common currency symbols, like $. Probably broken in many ways.

Example3 expressions
quoteForCommandLine "a""a"quoteForCommandLine "\"""'\"'"quoteForCommandLine "$""'$'"
valuewords' :: String -> [String]
#

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.

valuestripAnsi :: String -> String
#

Strip ANSI escape sequences from a string.

Example1 expression
stripAnsi "\ESC[31m-1\ESC[m""-1"

single-line layout

12 declarations
valuestrip1Char :: Char -> Char -> String -> String
#

Strip the given starting and ending character from the start and end of a string if both are present.

valuestripBy :: (Char -> Bool) -> String -> String
#

Strip a run of zero or more characters matching the predicate from the start and end of a string.

valuestrip1By :: (Char -> Bool) -> String -> String
#

Strip a single balanced enclosing pair of a character matching the predicate from the start and end of a string.

valuechomp1 :: String -> String
#

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

valueformatString :: Bool -> Maybe Int -> Maybe Int -> String -> String
#

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

4 declarations
valuecharWidth :: Char -> Int
#

Returns width of a character in a monospace font: 0 for a combining character, 1 for a regular character, 2 for an East Asian wide character. Ambiguous characters are treated as width 1.

valuestrWidthAnsi :: String -> Int
#

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.

valuetakeWidth :: Int -> String -> String
#

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