2008-02-18 20:08:15 -05:00
|
|
|
USING: math arrays sequences kernel random splitting strings unicode.case ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: strings.lib
|
|
|
|
|
|
|
|
: char>digit ( c -- i ) 48 - ;
|
|
|
|
|
|
|
|
: string>digits ( s -- seq ) [ char>digit ] { } map-as ;
|
2008-01-16 15:20:28 -05:00
|
|
|
|
|
|
|
: >Upper ( str -- str )
|
|
|
|
dup empty? [
|
2008-03-19 20:15:32 -04:00
|
|
|
unclip ch>upper 1string prepend
|
2008-01-16 15:20:28 -05:00
|
|
|
] unless ;
|
|
|
|
|
|
|
|
: >Upper-dashes ( str -- str )
|
|
|
|
"-" split [ >Upper ] map "-" join ;
|
2008-02-14 23:40:21 -05:00
|
|
|
|
|
|
|
: lower-alpha-chars ( -- seq )
|
|
|
|
26 [ CHAR: a + ] map ;
|
|
|
|
|
|
|
|
: upper-alpha-chars ( -- seq )
|
|
|
|
26 [ CHAR: A + ] map ;
|
|
|
|
|
|
|
|
: numeric-chars ( -- seq )
|
|
|
|
10 [ CHAR: 0 + ] map ;
|
|
|
|
|
|
|
|
: 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 )
|
|
|
|
[ drop random-alphanumeric-char ] map "" like ;
|
|
|
|
|