1 ! Copyright (C) 2008, 2010 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors fry kernel make math math.order math.parser
4 sequences sorting.functor strings unicode.case
5 unicode.categories unicode.collation ;
8 : cut-find ( sequence pred -- before after )
9 [ drop ] [ find drop ] 2bi dup [ cut ] when ; inline
11 : cut3 ( sequence pred -- first mid last )
12 [ cut-find ] keep [ not ] compose cut-find ; inline
14 : find-sequences ( sequence pred quot -- sequences )
24 : find-numbers ( sequence -- sequence' )
25 [ digit? ] [ string>number ] find-sequences ;
27 ! For comparing integers or sequences
30 : <hybrid> ( obj -- hybrid )
34 : <hybrid-insensitive> ( obj -- hybrid )
36 swap dup string? [ w/collation-key ] when >>obj ; inline
40 2dup [ integer? ] bi@ xor [
41 drop integer? +lt+ +gt+ ?
46 << "human" [ find-numbers [ <hybrid> ] map ] define-sorting >>
47 << "humani" [ find-numbers [ <hybrid-insensitive> ] map ] define-sorting >>