]> gitweb.factorcode.org Git - factor.git/commitdiff
Collation cleanup and test added
authorDaniel Ehrenberg <littledan@pool-226-177.res.carleton.edu>
Sun, 1 Jun 2008 18:50:12 +0000 (13:50 -0500)
committerDaniel Ehrenberg <littledan@pool-226-177.res.carleton.edu>
Sun, 1 Jun 2008 18:50:12 +0000 (13:50 -0500)
extra/unicode/collation/collation-tests.factor
extra/unicode/collation/collation.factor

index b4a54bb11de61843e5835cbdb49db3fc6d07ae47..16ac50d5a960ea660104461ea5d44078bc0543b8 100755 (executable)
@@ -24,6 +24,9 @@ IN: unicode.collation.tests
 [ t t f f ] [ "hello" "HELLO" test-equality ] unit-test\r
 [ t t t f ] [ "hello" "h e l l o." test-equality ] unit-test\r
 [ t t t t ] [ "hello" "\0hello\0" test-equality ] unit-test\r
+[ { "good bye" "goodbye" "hello" "HELLO" } ]\r
+[ { "HELLO" "goodbye" "good bye" "hello" } sort-strings ]\r
+unit-test\r
 \r
 parse-test 2 <clumps>\r
 [ [ test-two ] assoc-each ] with-null-writer\r
index 441339d677952282579ed357b78e05ea0e9eef43..f71a58be85f2bdf65b5eb52a2788b7597598fcbc 100755 (executable)
@@ -154,18 +154,13 @@ PRIVATE>
     0 insensitive= ;\r
 \r
 <PRIVATE\r
-: compare-collation ( {str1,key} {str2,key} -- <=> )\r
-    2dup [ second ] bi@ <=> dup +eq+ =\r
-    [ drop <=> ] [ 2nip ] if ;\r
-\r
 : w/collation-key ( str -- {str,key} )\r
-    dup collation-key 2array ;\r
+    [ collation-key ] keep 2array ;\r
 PRIVATE>\r
 \r
 : sort-strings ( strings -- sorted )\r
     [ w/collation-key ] map\r
-    [ compare-collation ] sort\r
-    keys ;\r
+    natural-sort values ;\r
 \r
 : string<=> ( str1 str2 -- <=> )\r
-    [ w/collation-key ] bi@ compare-collation ;\r
+    [ w/collation-key ] compare ;\r