strings.lib: sequences of alpha and numeric chars
parent
150b4c9272
commit
622a35ec9f
|
@ -1,4 +1,4 @@
|
||||||
USING: math arrays sequences kernel splitting strings ;
|
USING: math arrays sequences kernel random splitting strings ;
|
||||||
IN: strings.lib
|
IN: strings.lib
|
||||||
|
|
||||||
: char>digit ( c -- i ) 48 - ;
|
: char>digit ( c -- i ) 48 - ;
|
||||||
|
@ -12,3 +12,28 @@ IN: strings.lib
|
||||||
|
|
||||||
: >Upper-dashes ( str -- str )
|
: >Upper-dashes ( str -- str )
|
||||||
"-" split [ >Upper ] map "-" join ;
|
"-" split [ >Upper ] map "-" join ;
|
||||||
|
|
||||||
|
: 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 ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue