Skip to content

Commit

Permalink
imp: Add ' as possible digit separator
Browse files Browse the repository at this point in the history
It is used for Swiss Francs: CHF 1'000.
  • Loading branch information
ThreeFx committed Jan 19, 2023
1 parent 440f808 commit 05f3c69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion hledger-lib/Hledger/Read/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ disambiguateNumber msuggestedStyle (AmbiguousNumber grp1 sep grp2) =
-- Left (AmbiguousNumber "1" ',' "000")
-- >>> parseTest rawnumberp "1 000"
-- Right (WithSeparators ' ' ["1","000"] Nothing)
-- >>> parseTest rawnumberp "1'000"
-- Right (WithSeparators '\'' ["1","000"] Nothing)
--
rawnumberp :: TextParser m (Either AmbiguousNumber RawNumber)
rawnumberp = label "number" $ do
Expand Down Expand Up @@ -1142,7 +1144,7 @@ rawnumberp = label "number" $ do
pure $ NoSeparators grp1 (Just (decPt, mempty))

isDigitSeparatorChar :: Char -> Bool
isDigitSeparatorChar c = isDecimalMark c || c == ' '
isDigitSeparatorChar c = isDecimalMark c || c == ' ' || c == '\''

-- | Some kinds of number literal we might parse.
data RawNumber
Expand Down
6 changes: 4 additions & 2 deletions hledger/hledger.m4.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,11 @@ A *decimal mark* can be written as a period or a comma:

In the integer part of the quantity (left of the decimal mark), groups
of digits can optionally be separated by a *digit group mark* - a
space, comma, or period (different from the decimal mark):
space, comma, single quote, or period (different from the decimal mark):

$1,000,000.00
EUR 2.000.000,00
CHF 2'000'000.00
INR 9,99,99,999.00
1 000 000.9455

Expand Down Expand Up @@ -2192,9 +2193,10 @@ by 0 or more decimal digits.

A few more examples:
```journal
# number formats for $, EUR, INR and the no-symbol commodity:
# number formats for $, EUR, CHF, INR and the no-symbol commodity:
commodity $1,000.00
commodity EUR 1.000,00
commodity CHF 1'000.00
commodity INR 9,99,99,999.0
commodity 1 000 000.
```
Expand Down
13 changes: 13 additions & 0 deletions hledger/test/journal/numbers.test
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,16 @@ Balance changes in 2021:
===++===================================
a || -0.12345678901234567890123456 EUR
>>>=0

# 19. number begins with a separator char
hledger bal -f -
<<<
commodity 1'000.00 CHF

2017/1/1
a 1000 CHF
b -1000 CHF
>>>
1'000.00 CHF a
-1'000.00 CHF b
>>>=0

0 comments on commit 05f3c69

Please sign in to comment.