lib: more robust multi-line joining in csv parser

This commit is contained in:
Dmitry Astapov 2019-10-12 10:16:38 +01:00
parent 9440664fc4
commit 24bba96ea2
2 changed files with 3 additions and 3 deletions

View File

@ -77,9 +77,9 @@ rstrip = reverse . lstrip . reverse
chomp :: String -> String
chomp = reverse . dropWhile (`elem` "\r\n") . reverse
-- | Remove line breaks
-- | Remove consequtive line breaks, replacing them with single space
singleline :: String -> String
singleline = map (\c -> if c `elem` "\r\n" then ' ' else c)
singleline = unwords . filter (/="") . (map strip) . lines
stripbrackets :: String -> String
stripbrackets = dropWhile (`elem` "([") . reverse . dropWhile (`elem` "])") . reverse :: String -> String

View File

@ -145,7 +145,7 @@ $ printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescrip
>=0
# 14. multiline descriptions
$ printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,"Flubber Co\nCo\nCo",50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
$ printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,"Flubber Co\n\n\n\nCo\nCo\n\n\n\n\n",50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
2009/09/10 Flubber Co Co Co
assets:myacct $50
expense:unknown