strings.lib: sequences of alpha and numeric chars

db4
Alex Chapman 2008-02-15 15:40:21 +11:00
parent 150b4c9272
commit 622a35ec9f
1 changed files with 26 additions and 1 deletions

View File

@ -1,4 +1,4 @@
USING: math arrays sequences kernel splitting strings ;
USING: math arrays sequences kernel random splitting strings ;
IN: strings.lib
: char>digit ( c -- i ) 48 - ;
@ -12,3 +12,28 @@ IN: strings.lib
: >Upper-dashes ( str -- str )
"-" 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 ;