naturalcomp 0.0.2 → 0.0.3
raw patch · 4 files changed
+26/−7 lines, 4 files
Files
- .hg_archival.txt +2/−2
- Text/NaturalComp/Collation.hs +20/−2
- naturalcomp.cabal +1/−1
- tests/colltest.hs +3/−2
.hg_archival.txt view
@@ -1,5 +1,5 @@ repo: a17264ceea088a1ccab9c1c27a4909f450da3259-node: 5ef3b4bf8c8f525b7136b4ff4953aae8316dde3d+node: 97d444fd3bdccbb7fc66420be548507c96648845 branch: default latesttag: 0.0.1-latesttagdistance: 5+latesttagdistance: 7
Text/NaturalComp/Collation.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE ViewPatterns #-}+ {- | Module: Text.NaturalComp.Collation Copyright: 2013 Hironao Komatsu@@ -8,14 +10,30 @@ Natural order and Unicode-aware string comparison using rfc5051 module. -} -module Text.NaturalComp.Collation (naturalCollate) where+module Text.NaturalComp.Collation ( naturalCollate+ , unicodeCollate ) where import Data.Function (on) import Data.RFC5051 import Text.NaturalComp (naturalCompBy)-import Text.NaturalComp.Stringy (Stringy)+import Text.NaturalComp.Stringy (Stringy, uncons) -- | Natural order and Unicode-aware string collation naturalCollate :: Stringy s => s -> s -> Ordering naturalCollate = naturalCompBy (compareUnicode `on` return)++-- | Normal (not natural) Unicode collation that can be used for+-- Text and ByteString+unicodeCollate :: Stringy s => s -> s -> Ordering+unicodeCollate = unicodeCollateFull (compareUnicode `on` return) EQ+ where+ unicodeCollateFull :: Stringy s => (Char -> Char -> Ordering)+ -> Ordering -> s -> s -> Ordering+ unicodeCollateFull _ o (uncons -> Nothing) (uncons -> Nothing) = o+ unicodeCollateFull _ EQ (uncons -> Nothing) _ = LT+ unicodeCollateFull _ EQ _ (uncons -> Nothing) = GT+ unicodeCollateFull f EQ (uncons -> Just (x, xs))+ (uncons -> Just (y, ys)) =+ unicodeCollateFull f (f x y) xs ys+ unicodeCollateFull _ o _ _ = o
naturalcomp.cabal view
@@ -1,5 +1,5 @@ Name: naturalcomp-Version: 0.0.2+Version: 0.0.3 Synopsis: Natural-order string comparison Description: Natural order string comparison is needed when e.g. one wants to compare file names or strings of software version. It's
tests/colltest.hs view
@@ -8,9 +8,10 @@ a = "Abe Oeb abe abé oeb Ábe Äbe Ôeb ábe äbe ôeb" b = "Abe abe abé Ábe ábe Äbe äbe Oeb oeb Ôeb ôeb" -sortTest x y = assertEqual "" y $ unwords $ sortBy naturalCollate $ words x+sortTest f x y = assertEqual "" y $ unwords $ sortBy f $ words x -tests = TestList [ TestLabel "test1" $ TestCase $ sortTest a b ]+tests = TestList [ TestLabel "test1" $ TestCase $ sortTest naturalCollate a b+ , TestLabel "test2" $ TestCase $ sortTest unicodeCollate a b ] main = runTestTT tests