Fix parsing

This commit is contained in:
Luca Molteni 2018-07-01 15:32:28 +02:00
parent 4fc2374b2b
commit 1146ed0941
2 changed files with 20 additions and 2 deletions

View File

@ -52,7 +52,7 @@ stringopt :: String -> RawOpts -> String
stringopt name = fromMaybe "" . maybestringopt name
maybecharopt :: String -> RawOpts -> Maybe Char
maybecharopt name rawopts = lookup name rawopts >>= readMay
maybecharopt name rawopts = lookup name rawopts >>= headMay
listofstringopt :: String -> RawOpts -> [String]
listofstringopt name rawopts = [v | (k,v) <- rawopts, k==name]

View File

@ -31,6 +31,24 @@
>>>2
>>>=0
# 20. reading CSV with in-field and out-field
printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescription %%2\namount-in %%3\namount-out %%4\ncurrency $\n' >t.$$.csv.rules ; hledger --separator ';' -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
<<<
10/2009/09;Flubber Co🎅;50;
11/2009/09;Flubber Co🎅;;50
>>>
2009/09/10 Flubber Co🎅
Assets:MyAccount $50
income:unknown $-50
2009/09/11 Flubber Co🎅
Assets:MyAccount $-50
expenses:unknown $50
>>>2
>>>=0
# 3. handle conditions assigning multiple fields
printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\nif Flubber\n account2 acct\n comment cmt' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
>>>
@ -91,4 +109,4 @@
expense:other $-60
>>>2
>>>=0
>>>=0