display non-simple commodity names with double-quotes
This ensures print's output remains parseable. The other commands also double-quote them, for consistency, like c++ ledger.
This commit is contained in:
parent
8257c98440
commit
586c824cac
@ -106,9 +106,10 @@ showAmount :: Amount -> String
|
|||||||
showAmount (Amount (Commodity {symbol="AUTO"}) _ _) = "" -- can appear in an error message
|
showAmount (Amount (Commodity {symbol="AUTO"}) _ _) = "" -- can appear in an error message
|
||||||
showAmount a@(Amount (Commodity {symbol=sym,side=side,spaced=spaced}) _ pri) =
|
showAmount a@(Amount (Commodity {symbol=sym,side=side,spaced=spaced}) _ pri) =
|
||||||
case side of
|
case side of
|
||||||
L -> printf "%s%s%s%s" sym space quantity price
|
L -> printf "%s%s%s%s" sym' space quantity price
|
||||||
R -> printf "%s%s%s%s" quantity space sym price
|
R -> printf "%s%s%s%s" quantity space sym' price
|
||||||
where
|
where
|
||||||
|
sym' = quoteCommoditySymbolIfNeeded sym
|
||||||
space = if spaced then " " else ""
|
space = if spaced then " " else ""
|
||||||
quantity = showAmount' a
|
quantity = showAmount' a
|
||||||
price = case pri of (Just pamt) -> " @ " ++ showMixedAmount pamt
|
price = case pri of (Just pamt) -> " @ " ++ showMixedAmount pamt
|
||||||
|
|||||||
@ -16,6 +16,9 @@ import Data.Map ((!))
|
|||||||
|
|
||||||
nonsimplecommoditychars = "0123456789-.@;\n \""
|
nonsimplecommoditychars = "0123456789-.@;\n \""
|
||||||
|
|
||||||
|
quoteCommoditySymbolIfNeeded s | any (`elem` nonsimplecommoditychars) s = "\"" ++ s ++ "\""
|
||||||
|
| otherwise = s
|
||||||
|
|
||||||
-- convenient amount and commodity constructors, for tests etc.
|
-- convenient amount and commodity constructors, for tests etc.
|
||||||
|
|
||||||
unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0}
|
unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ bin/hledger -f- print
|
|||||||
b
|
b
|
||||||
>>>2 /parse error.*unexpected "0"/
|
>>>2 /parse error.*unexpected "0"/
|
||||||
>>>= 1
|
>>>= 1
|
||||||
# 2. with quotes
|
# 2. with quotes, ok; quotes appear in print output
|
||||||
bin/hledger -f- print
|
bin/hledger -f- print
|
||||||
<<<
|
<<<
|
||||||
2010-04-05 x
|
2010-04-05 x
|
||||||
@ -15,6 +15,17 @@ bin/hledger -f- print
|
|||||||
b
|
b
|
||||||
>>>
|
>>>
|
||||||
2010/04/05 x
|
2010/04/05 x
|
||||||
a 10 DE0002635307
|
a 10 "DE0002635307"
|
||||||
b -10 DE0002635307
|
b -10 "DE0002635307"
|
||||||
|
|
||||||
|
# 3. and in other reports too, I guess
|
||||||
|
bin/hledger -f- balance
|
||||||
|
<<<
|
||||||
|
2010-04-05 x
|
||||||
|
a 10 "DE0002635307"
|
||||||
|
b
|
||||||
|
>>>
|
||||||
|
10 "DE0002635307" a
|
||||||
|
-10 "DE0002635307" b
|
||||||
|
--------------------
|
||||||
|
0 "DE0002635307"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user