mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-29 05:11:33 +03:00
lib: quoteIfNeeded should not escape the backslashes in unicode code points.
This commit is contained in:
parent
08ee311875
commit
97545018f4
@ -118,13 +118,17 @@ underline s = s' ++ replicate (length s) '-' ++ "\n"
|
||||
-- | Double-quote this string if it contains whitespace, single quotes
|
||||
-- or double-quotes, escaping the quotes as needed.
|
||||
quoteIfNeeded :: String -> String
|
||||
quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = show s
|
||||
quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = showChar '"' $ escapeQuotes s "\""
|
||||
| otherwise = s
|
||||
where
|
||||
escapeQuotes [] x = x
|
||||
escapeQuotes ('"':cs) x = showString "\\\"" $ escapeQuotes cs x
|
||||
escapeQuotes (c:cs) x = showChar c $ escapeQuotes cs x
|
||||
|
||||
-- | Single-quote this string if it contains whitespace or double-quotes.
|
||||
-- No good for strings containing single quotes.
|
||||
singleQuoteIfNeeded :: String -> String
|
||||
singleQuoteIfNeeded s | any (`elem` s) whitespacechars = "'"++s++"'"
|
||||
singleQuoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars) = "'"++s++"'"
|
||||
| otherwise = s
|
||||
|
||||
quotechars, whitespacechars, redirectchars :: [Char]
|
||||
|
@ -6,3 +6,12 @@ hledger -f - register τράπ
|
||||
>>>
|
||||
2009-01-01 проверка τράπεζα 10 руб 10 руб
|
||||
>>>=0
|
||||
|
||||
hledger -f - balance -N " ét"
|
||||
<<<
|
||||
2020-09-19 Test
|
||||
assets:a ét 5
|
||||
assets:b
|
||||
>>>
|
||||
5 assets:a ét
|
||||
>>>=0
|
||||
|
Loading…
Reference in New Issue
Block a user