From 3b0661c1156a665ab46bf92950865b6bf1ec3540 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 10 Jul 2019 17:36:57 +0300 Subject: [PATCH 1/2] descriptions: Leverage ICU to get better description/payee/note sorting --- hledger/Hledger/Cli/Commands/Descriptions.hs | 5 +++-- hledger/Hledger/Cli/Commands/Notes.hs | 5 +++-- hledger/Hledger/Cli/Commands/Payees.hs | 5 +++-- hledger/hledger.cabal | 2 ++ hledger/package.yaml | 2 ++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Descriptions.hs b/hledger/Hledger/Cli/Commands/Descriptions.hs index e13d373cab1..9cf41e47cb2 100644 --- a/hledger/Hledger/Cli/Commands/Descriptions.hs +++ b/hledger/Hledger/Cli/Commands/Descriptions.hs @@ -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 @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Notes.hs b/hledger/Hledger/Cli/Commands/Notes.hs index ae942381514..7d95d2d7139 100644 --- a/hledger/Hledger/Cli/Commands/Notes.hs +++ b/hledger/Hledger/Cli/Commands/Notes.hs @@ -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 @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Payees.hs b/hledger/Hledger/Cli/Commands/Payees.hs index f958a8e4b6b..d14fee2b2a9 100644 --- a/hledger/Hledger/Cli/Commands/Payees.hs +++ b/hledger/Hledger/Cli/Commands/Payees.hs @@ -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 @@ -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 diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index af6a202de8a..f67eeeee267 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -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 @@ -179,6 +180,7 @@ library , tabular >=0.2 , temporary , text >=0.11 + , text-icu , time >=1.5 , timeit , transformers diff --git a/hledger/package.yaml b/hledger/package.yaml index b341efb5ee6..81ce3e1c512 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -119,6 +119,7 @@ dependencies: - Decimal - directory - easytest >= 0.2.1 && <0.3 +- extra - filepath - haskeline >=0.6 - megaparsec >=7.0.0 && <8 @@ -136,6 +137,7 @@ dependencies: - tabular >=0.2 - temporary - text >=0.11 +- text-icu - time >=1.5 - timeit - transformers From b894b5a84df66b7d43a40cf252a044ce1db976f8 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 15 Jul 2019 11:16:38 +0300 Subject: [PATCH 2/2] tests: Add Unicode in alphabetical account sorting --- tests/accounts-sorting.test | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/accounts-sorting.test b/tests/accounts-sorting.test index b2ba3d10bea..09a8e2e6bee 100644 --- a/tests/accounts-sorting.test +++ b/tests/accounts-sorting.test @@ -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 >=