lib: quoteIfNeeded should not escape the backslashes in unicode code points.

This commit is contained in:
Stephen Morgan 2020-10-07 15:30:28 +11:00 committed by Simon Michael
parent 08ee311875
commit 97545018f4
2 changed files with 15 additions and 2 deletions

View File

@ -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]

View File

@ -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