Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ICU for better Unicode sorting #1066

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hledger/Hledger/Cli/Commands/Descriptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Descriptions (
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid
#endif
import Data.List
import Data.List.Extra (nubSortBy)
import qualified Data.Text.ICU as T
import qualified Data.Text.IO as T

import Hledger
Expand All @@ -39,6 +40,6 @@ descriptions CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d ropts
ts = entriesReport ropts q j
descriptions = nub $ sort $ map tdescription ts
descriptions = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map tdescription ts

mapM_ T.putStrLn descriptions
5 changes: 3 additions & 2 deletions hledger/Hledger/Cli/Commands/Notes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Notes (
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid
#endif
import Data.List
import Data.List.Extra (nubSortBy)
import qualified Data.Text.ICU as T
import qualified Data.Text.IO as T

import Hledger
Expand All @@ -39,6 +40,6 @@ notes CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d ropts
ts = entriesReport ropts q j
notes = nub $ sort $ map transactionNote ts
notes = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map transactionNote ts

mapM_ T.putStrLn notes
5 changes: 3 additions & 2 deletions hledger/Hledger/Cli/Commands/Payees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Payees (
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid
#endif
import Data.List
import Data.List.Extra (nubSortBy)
import qualified Data.Text.ICU as T
import qualified Data.Text.IO as T

import Hledger
Expand All @@ -39,6 +40,6 @@ payees CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d ropts
ts = entriesReport ropts q j
payees = nub $ sort $ map transactionPayee ts
payees = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map transactionPayee ts

mapM_ T.putStrLn payees
2 changes: 2 additions & 0 deletions hledger/hledger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ library
, data-default >=0.5
, directory
, easytest >=0.2.1 && <0.3
, extra
, filepath
, hashable >=1.2.4
, haskeline >=0.6
Expand All @@ -179,6 +180,7 @@ library
, tabular >=0.2
, temporary
, text >=0.11
, text-icu
, time >=1.5
, timeit
, transformers
Expand Down
2 changes: 2 additions & 0 deletions hledger/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ dependencies:
- Decimal
- directory
- easytest >= 0.2.1 && <0.3
- extra
- filepath
- haskeline >=0.6
- megaparsec >=7.0.0 && <8
Expand All @@ -136,6 +137,7 @@ dependencies:
- tabular >=0.2
- temporary
- text >=0.11
- text-icu
- time >=1.5
- timeit
- transformers
Expand Down
8 changes: 8 additions & 0 deletions tests/accounts-sorting.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
2018/1/1
(a:k) 1

2018/1/1
(d:u) 1

2018/1/1
(d:ö) 1

$ hledger -f- acc
a:k
b:i
b:j
c
d:ö
d:u
>=


Expand Down