factor/extra/strings/lib/lib.factor

34 lines
800 B
Factor
Raw Normal View History

2008-05-22 18:28:15 -04:00
USING: math math.ranges arrays sequences kernel random splitting
strings unicode.case ;
2007-09-20 18:09:08 -04:00
IN: strings.lib
2008-01-16 15:20:28 -05:00
: >Upper ( str -- str )
2008-05-22 18:43:51 -04:00
dup empty? [ unclip ch>upper prefix ] unless ;
2008-01-16 15:20:28 -05:00
: >Upper-dashes ( str -- str )
"-" split [ >Upper ] map "-" join ;
: lower-alpha-chars ( -- seq )
2008-05-22 18:28:15 -04:00
CHAR: a CHAR: z [a,b] ;
: upper-alpha-chars ( -- seq )
2008-05-22 18:28:15 -04:00
CHAR: A CHAR: Z [a,b] ;
: numeric-chars ( -- seq )
2008-05-22 18:28:15 -04:00
CHAR: 0 CHAR: 9 [a,b] ;
: alpha-chars ( -- seq )
lower-alpha-chars upper-alpha-chars append ;
: alphanumeric-chars ( -- seq )
alpha-chars numeric-chars append ;
: random-alpha-char ( -- ch )
alpha-chars random ;
: random-alphanumeric-char ( -- ch )
alphanumeric-chars random ;
: random-alphanumeric-string ( length -- str )
[ random-alphanumeric-char ] "" replicate-as ;