add some type signatures in Utils, helps ghci-web
This commit is contained in:
parent
293c9b2efa
commit
d2877a919a
@ -55,26 +55,34 @@ import Hledger.Utils.UTF8IOCompat (SystemString,fromSystemString,toSystemString,
|
|||||||
|
|
||||||
-- strings
|
-- strings
|
||||||
|
|
||||||
|
lowercase, uppercase :: String -> String
|
||||||
lowercase = map toLower
|
lowercase = map toLower
|
||||||
uppercase = map toUpper
|
uppercase = map toUpper
|
||||||
|
|
||||||
-- | Remove leading and trailing whitespace.
|
-- | Remove leading and trailing whitespace.
|
||||||
|
strip :: String -> String
|
||||||
strip = lstrip . rstrip
|
strip = lstrip . rstrip
|
||||||
|
|
||||||
-- | Remove leading whitespace.
|
-- | Remove leading whitespace.
|
||||||
|
lstrip :: String -> String
|
||||||
lstrip = dropWhile (`elem` " \t") :: String -> String -- XXX isSpace ?
|
lstrip = dropWhile (`elem` " \t") :: String -> String -- XXX isSpace ?
|
||||||
|
|
||||||
-- | Remove trailing whitespace.
|
-- | Remove trailing whitespace.
|
||||||
|
rstrip :: String -> String
|
||||||
rstrip = reverse . lstrip . reverse
|
rstrip = reverse . lstrip . reverse
|
||||||
|
|
||||||
-- | Remove trailing newlines/carriage returns.
|
-- | Remove trailing newlines/carriage returns.
|
||||||
|
chomp :: String -> String
|
||||||
chomp = reverse . dropWhile (`elem` "\r\n") . reverse
|
chomp = reverse . dropWhile (`elem` "\r\n") . reverse
|
||||||
|
|
||||||
|
stripbrackets :: String -> String
|
||||||
stripbrackets = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String
|
stripbrackets = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String
|
||||||
|
|
||||||
|
elideLeft :: Int -> String -> String
|
||||||
elideLeft width s =
|
elideLeft width s =
|
||||||
if length s > width then ".." ++ reverse (take (width - 2) $ reverse s) else s
|
if length s > width then ".." ++ reverse (take (width - 2) $ reverse s) else s
|
||||||
|
|
||||||
|
elideRight :: Int -> String -> String
|
||||||
elideRight width s =
|
elideRight width s =
|
||||||
if length s > width then take (width - 2) s ++ ".." else s
|
if length s > width then take (width - 2) s ++ ".." else s
|
||||||
|
|
||||||
@ -94,14 +102,17 @@ quoteIfSpaced s | isSingleQuoted s || isDoubleQuoted s = s
|
|||||||
|
|
||||||
-- | Double-quote this string if it contains whitespace, single quotes
|
-- | Double-quote this string if it contains whitespace, single quotes
|
||||||
-- or double-quotes, escaping the quotes as needed.
|
-- or double-quotes, escaping the quotes as needed.
|
||||||
|
quoteIfNeeded :: String -> String
|
||||||
quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars) = "\"" ++ escapeDoubleQuotes s ++ "\""
|
quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars) = "\"" ++ escapeDoubleQuotes s ++ "\""
|
||||||
| otherwise = s
|
| otherwise = s
|
||||||
|
|
||||||
-- | Single-quote this string if it contains whitespace or double-quotes.
|
-- | Single-quote this string if it contains whitespace or double-quotes.
|
||||||
-- No good for strings containing single quotes.
|
-- No good for strings containing single quotes.
|
||||||
|
singleQuoteIfNeeded :: String -> String
|
||||||
singleQuoteIfNeeded s | any (`elem` s) whitespacechars = "'"++s++"'"
|
singleQuoteIfNeeded s | any (`elem` s) whitespacechars = "'"++s++"'"
|
||||||
| otherwise = s
|
| otherwise = s
|
||||||
|
|
||||||
|
quotechars, whitespacechars :: [Char]
|
||||||
quotechars = "'\""
|
quotechars = "'\""
|
||||||
whitespacechars = " \t\n\r"
|
whitespacechars = " \t\n\r"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user