1 ! Copyright (C) 2008, 2010 Doug Coleman, Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel make math math.order math.parser
4 sequences sorting sorting.functor strings unicode ;
9 : cut-find ( sequence pred -- before after )
10 [ drop ] [ find drop ] 2bi dup [ cut ] when ; inline
12 : cut3 ( sequence pred -- first mid last )
13 [ cut-find ] keep [ not ] compose cut-find ; inline
15 : find-sequences ( sequence pred quot -- sequences )
27 : find-numbers ( sequence -- sequence' )
28 [ digit? ] [ string>number ] find-sequences ;
30 ! For comparing integers or sequences
33 : <alphanum> ( obj -- alphanum )
37 : <alphanum-insensitive> ( obj -- alphanum )
39 swap dup string? [ collation-key/nfd drop ] when >>obj ; inline
43 2dup [ integer? ] bi@ xor [
44 drop integer? +lt+ +gt+ ?
49 << "human" [ find-numbers [ <alphanum> ] map ] define-sorting >>
50 << "humani" [ find-numbers [ <alphanum-insensitive> ] map ] define-sorting >>
52 : human-sort ( seq -- seq' ) [ human<=> ] sort ;
53 : humani-sort ( seq -- seq' ) [ humani<=> ] sort ;