! Copyright (C) 2008, 2010 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors fry kernel make math math.order math.parser
-sequences sorting.functor strings unicode.case
-unicode.categories unicode.collation ;
+USING: accessors kernel make math math.order math.parser
+sequences sorting.functor strings unicode ;
IN: sorting.human
: cut-find ( sequence pred -- before after )
[ digit? ] [ string>number ] find-sequences ;
! For comparing integers or sequences
-TUPLE: hybrid obj ;
+TUPLE: alphanum obj ;
-: <hybrid> ( obj -- hybrid )
- hybrid new
+: <alphanum> ( obj -- alphanum )
+ alphanum new
swap >>obj ; inline
-: <hybrid-insensitive> ( obj -- hybrid )
- hybrid new
- swap dup string? [ w/collation-key ] when >>obj ; inline
+: <alphanum-insensitive> ( obj -- alphanum )
+ alphanum new
+ swap dup string? [ collation-key/nfd drop ] when >>obj ; inline
-M: hybrid <=>
+M: alphanum <=>
[ obj>> ] bi@
2dup [ integer? ] bi@ xor [
drop integer? +lt+ +gt+ ?
<=>
] if ;
-<< "human" [ find-numbers [ <hybrid> ] map ] define-sorting >>
-<< "humani" [ find-numbers [ <hybrid-insensitive> ] map ] define-sorting >>
+<< "human" [ find-numbers [ <alphanum> ] map ] define-sorting >>
+<< "humani" [ find-numbers [ <alphanum-insensitive> ] map ] define-sorting >>