1 ! Copyright (C) 2008, 2010 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel make math math.order math.parser
4 sequences sorting.functor strings unicode ;
7 : cut-find ( sequence pred -- before after )
8 [ drop ] [ find drop ] 2bi dup [ cut ] when ; inline
10 : cut3 ( sequence pred -- first mid last )
11 [ cut-find ] keep [ not ] compose cut-find ; inline
13 : find-sequences ( sequence pred quot -- sequences )
23 : find-numbers ( sequence -- sequence' )
24 [ digit? ] [ string>number ] find-sequences ;
26 ! For comparing integers or sequences
29 : <alphanum> ( obj -- alphanum )
33 : <alphanum-insensitive> ( obj -- alphanum )
35 swap dup string? [ collation-key/nfd drop ] when >>obj ; inline
39 2dup [ integer? ] bi@ xor [
40 drop integer? +lt+ +gt+ ?
45 << "human" [ find-numbers [ <alphanum> ] map ] define-sorting >>
46 << "humani" [ find-numbers [ <alphanum-insensitive> ] map ] define-sorting >>