hledger-lib-0.16: Core data types, parsers and utilities for the hledger accounting tool.

Hledger.Utils

Description

Standard imports and utilities which are useful everywhere, or needed low in the module hierarchy. This is the bottom of hledger's module graph.

Synopsis

Documentation

quoteIfSpaced :: String -> StringSource

Wrap a string in single quotes, and -prefix any embedded single quotes, if it contains whitespace and is not already single- or double-quoted.

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

unwords' :: [String] -> StringSource

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

stripquotes :: String -> StringSource

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

concatTopPadded :: [String] -> StringSource

Join multi-line strings as side-by-side rectangular strings of the same height, top-padded.

concatBottomPadded :: [String] -> StringSource

Join multi-line strings as side-by-side rectangular strings of the same height, bottom-padded.

vConcatRightAligned :: [String] -> StringSource

Compose strings vertically and right-aligned.

padtop :: Int -> String -> StringSource

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

padbottom :: Int -> String -> StringSource

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

padleft :: Int -> String -> StringSource

Convert a multi-line string to a rectangular string left-padded to the specified width.

padright :: Int -> String -> StringSource

Convert a multi-line string to a rectangular string right-padded to the specified width.

cliptopleft :: Int -> Int -> String -> StringSource

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

fitto :: Int -> Int -> String -> StringSource

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

type PlatformString = StringSource

A platform string is a string value from or for the operating system, such as a file path or command-line argument (or environment variable's name or value ?). On some platforms (such as unix) these are not real unicode strings but have some encoding such as UTF-8. This alias does no type enforcement but aids code clarity.

fromPlatformString :: PlatformString -> StringSource

Convert a possibly encoded platform string to a real unicode string. We decode the UTF-8 encoding recommended for unix systems (cf http:www.dwheeler.comessaysfixing-unix-linux-filenames.html) and leave anything else unchanged.

toPlatformString :: String -> PlatformStringSource

Convert a unicode string to a possibly encoded platform string. On unix we encode with the recommended UTF-8 (cf http:www.dwheeler.comessaysfixing-unix-linux-filenames.html) and elsewhere we leave it unchanged.

error' :: String -> aSource

A version of error that's better at displaying unicode.

userError' :: String -> IOErrorSource

A version of userError that's better at displaying unicode.

difforzero :: (Num a, Ord a) => a -> a -> aSource

splitAtElement :: Eq a => a -> [a] -> [[a]]Source

leaves :: Tree a -> [a]Source

List just the leaf nodes of a tree

subtreeat :: Eq a => a -> Tree a -> Maybe (Tree a)Source

get the sub-tree rooted at the first (left-most, depth-first) occurrence of the specified node value

subtreeinforest :: Eq a => a -> [Tree a] -> Maybe (Tree a)Source

get the sub-tree for the specified node value in the first tree in forest in which it occurs.

treeprune :: Int -> Tree a -> Tree aSource

remove all nodes past a certain depth

treemap :: (a -> b) -> Tree a -> Tree bSource

apply f to all tree nodes

treefilter :: (a -> Bool) -> Tree a -> Tree aSource

remove all subtrees whose nodes do not fulfill predicate

treeany :: (a -> Bool) -> Tree a -> BoolSource

is predicate true in any node of tree ?

showtree :: Show a => Tree a -> StringSource

show a compact ascii representation of a tree

showforest :: Show a => Forest a -> StringSource

show a compact ascii representation of a forest

strace :: Show a => a -> aSource

trace (print on stdout at runtime) a showable expression (for easily tracing in the middle of a complex expression)

ltrace :: Show a => String -> a -> aSource

labelled trace - like strace, with a label prepended

mtrace :: (Monad m, Show a) => a -> m aSource

monadic trace - like strace, but works as a standalone line in a monad

tracewith :: (a -> String) -> a -> aSource

trace an expression using a custom show function

choice' :: [GenParser tok st a] -> GenParser tok st aSource

Backtracking choice, use this when alternatives share a prefix. Consumes no input if all choices fail.

tname :: Test -> StringSource

Get a Test's label, or the empty string.

tflatten :: Test -> [Test]Source

Flatten a Test containing TestLists into a list of single tests.

tfilter :: (Test -> Bool) -> Test -> TestSource

Filter TestLists in a Test, recursively, preserving the structure.

is :: (Eq a, Show a) => a -> a -> AssertionSource

Simple way to assert something is some expected value, with no label.

assertParse :: Either ParseError a -> AssertionSource

Assert a parse result is successful, printing the parse error on failure.

assertParseFailure :: Either ParseError a -> AssertionSource

Assert a parse result is successful, printing the parse error on failure.

assertParseEqual :: (Show a, Eq a) => Either ParseError a -> a -> AssertionSource

Assert a parse result is some expected value, printing the parse error on failure.

applyN :: Int -> (a -> a) -> a -> aSource

Apply a function the specified number of times. Possibly uses O(n) stack ?

trace :: String -> a -> a

When called, trace outputs the string in its first argument, before returning the second argument as its result. The trace function is not referentially transparent, and should only be used for debugging, or for monitoring execution. Some implementations of trace may decorate the string that's output to indicate that you're tracing. The function is implemented on top of putTraceMsg.