From 94776f6841c6d85131848dab3efbd773dde4c168 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sun, 1 Jun 2008 13:50:12 -0500 Subject: [PATCH] Collation cleanup and test added --- extra/unicode/collation/collation-tests.factor | 3 +++ extra/unicode/collation/collation.factor | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/extra/unicode/collation/collation-tests.factor b/extra/unicode/collation/collation-tests.factor index b4a54bb11d..16ac50d5a9 100755 --- a/extra/unicode/collation/collation-tests.factor +++ b/extra/unicode/collation/collation-tests.factor @@ -24,6 +24,9 @@ IN: unicode.collation.tests [ t t f f ] [ "hello" "HELLO" test-equality ] unit-test [ t t t f ] [ "hello" "h e l l o." test-equality ] unit-test [ t t t t ] [ "hello" "\0hello\0" test-equality ] unit-test +[ { "good bye" "goodbye" "hello" "HELLO" } ] +[ { "HELLO" "goodbye" "good bye" "hello" } sort-strings ] +unit-test parse-test 2 [ [ test-two ] assoc-each ] with-null-writer diff --git a/extra/unicode/collation/collation.factor b/extra/unicode/collation/collation.factor index 441339d677..f71a58be85 100755 --- a/extra/unicode/collation/collation.factor +++ b/extra/unicode/collation/collation.factor @@ -154,18 +154,13 @@ PRIVATE> 0 insensitive= ; ) - 2dup [ second ] bi@ <=> dup +eq+ = - [ drop <=> ] [ 2nip ] if ; - : w/collation-key ( str -- {str,key} ) - dup collation-key 2array ; + [ collation-key ] keep 2array ; PRIVATE> : sort-strings ( strings -- sorted ) [ w/collation-key ] map - [ compare-collation ] sort - keys ; + natural-sort values ; : string<=> ( str1 str2 -- <=> ) - [ w/collation-key ] bi@ compare-collation ; + [ w/collation-key ] compare ;