HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulehledger-lib-1.52.4GHC2021

Hledger.Utils.String

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

Contents
  1. misc
  2. single-line layout
  3. wide-character-aware layout
Synopsis

misc

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

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.

Strip ANSI escape sequences from a string.

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

single-line layout

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.

wide-character-aware layout

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.

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