>(newstring 5 #\a)
"aaaaa"
>(whitec #\tab)
t
>(whitec " ")
nil
>(nonwhite #\tab)
nil
>(nonwhite #\a)
t
>(letter #\A)
t
>(letter #2円)
nil
>(alphadig #\A)
t
>(alphadig #2円)
t
>(punc #\.)
t
>(punc #\a)
nil
>(punc ".")
nil
>(downcase "abcDEF123")
"abcdef123"
>(downcase #\A)
#\a
>(downcase 'abcDEF123)
abcdef123
>(upcase "abcDEF123")
"ABCDEF123"
>(upcase #\a)
#\A
>(upcase 'abcDEF123)
ABCDEF123
>(ellipsize "Too long" 6)
"Too lo..."
>(rand-string 10)
"FPEMMZuVrt"
>(string 2 'a '(#\b #\c))
"2abc"
>(let str "abcde"
(recstring
(fn (idx) (if (is (str idx) #\c) (+ 10 idx)))
str))
12
>(w/bars (pr "a") 42 (pr "b") (pr "c") nil) a | b | c nil
w/bars.
>bar*
" | "
str into tokens based on the separator (default whitec). sep is either a predicate function on a character, or a character.
>(tokens " cat dog bird lizard\nrat\tmouse")
("cat" "dog" "bird" "lizard" "rat" "mouse")
>(tokens "foo.bar..baz" #\.)
("foo" "bar" "baz")
>(tokens "a!bc%de@f" (fn (c) (pos c "!@%")))
("a" "bc" "de" "f")
>(urldecode "abc+def %c2%a9")
"abc def ©"
seq starting at offset start begins with pat.
Because of the macro expansion, pat must be a literal string or list of characters and not a variable. seq can be a string or list of characters.
>(litmatch "abc" "abcde")
t
>(litmatch "abc" "xabcde")
nil
>(litmatch "abc" "xabcde" 1)
t
>(litmatch (#\a #\b #\c) "abcde")
t
seq ends with pat.
Because of the macro expansion, pat must be a literal string or list of characters and not a variable. seq can be a string or list of characters.
>(endmatch "abc" "abcde")
nil
>(endmatch "cde" "abcde")
t
>(endmatch (#\c #\d #\e) "abcde")
t
pat is a string or list of characters, return the index (from start) where pat appears in seq. If pat is a predicate function on one character, it is applied to the characters of seq (starting from start), and returns the index of the first true result. seq is a string or list of characters.
>(posmatch "abc" "junk")
nil
>(posmatch "a" "banana" 2)
3
>(posmatch (fn (c) (in c #\a #\b)) "foobar")
3
>(posmatch '(#\a #\b) '(#\c #\a #\b))
1
pat is a subsequence of seq, starting at start. Both pat and seq can be strings or lists of characters. findsubseq is similar to posmatch, except it doesn't accept a function for pat.
>(findsubseq "abc" "fooabcbar")
3
>(findsubseq "abc" "x")
nil
>(findsubseq "an" "banana" 2)
3
seq from offset start onwards starts with pat. pat and seq can be strings or lists of characters. headmatch will die if pat is longer than seq and matches up to the end of seq.
>(headmatch "abc" "abcde")
t
>(headmatch "cd" "abcde")
nil
>(headmatch "cd" "abcde" 2)
t
>(headmatch '(#\a #\b) '(#\a #\b #\c))
t
seq begins with pat. begins is the same as headmatch with the first two arguments reversed, except begins doesn't die if matching goes past the end of seq.
>(begins "abcde" "abc")
t
>(begins "abc" "abcde")
nil
>(begins "abcde" "cd" 2)
t
new for old in seq. new can be any printable object. old and seq can be strings or lists of characters.
>(subst "bar" "foo" "catfood dogfood")
"catbard dogbard"
>(subst '(1 2) "a" "banana")
"b(1 2)n(1 2)n(1 2)"
seq. pairs is a list of pairs of old and new values.
>(multisubst '(("a" 1) ("b" "B")) "banana")
"B1n1n1"
str is blank (whitespace).
>(blank "a b")
nil
>(blank " ")
t
>(blank '(#\space #\tab #\newline))
t
str. where can have the value 'front, to trim the front of the string (currently broken); 'end, to trim the end of the string; or 'both to trim both ends of the string. If specified, test is either a character or a predicate function on characters.
>(trim " abc " 'end)
" abc"
>(trim " abc " 'both)
"abc"
>(trim "aabcaa" 'both #\a)
"bc"
>(trim "aabcaa" 'both (fn (_) (in _ #\a #\b)))
"c"
digits is the number of digits after the decimal point, trail-zeros is a Boolean indicating if trailing zeros should be included, and init-zero is a Boolean indicating if there should be a 0 before the decimal point.
>(num 123456)
"123,456"
>(num -123456)
"-123,456"
>(num 1.2345 2)
"1.23"
>(num 1.2 4 t)
"1.2000"
>(num 0.3 4 t t)
"0.3000"
>(pluralize 2 "fox")
"foxs"
>(pluralize '() "fish")
"fishs"
>(plural 2 "fox")
"2 foxs"
>(plural '() "fish")
" fishs"
>(halve "ab cd ef")
("ab" " cd ef")
>(halve "abc")
("abc")
>(positions #\a "That abacus")
(2 5 7)
>(positions odd '(1 2 4 5 7))
(0 3 4)
>(lines "a b\nc d\n\ne f")
("a b" "c d" "" "e f")
>(urlencode "abc")
"%61%62%63"
>(urlencode "☃")
"%2603"
>(nonblank "a b")
"a b"
>(nonblank "\n\t ")
nil
Copyright 2008 Ken Shirriff.