aerial.utils.string

Various supplementary string functions not included in the standard
Clojure ecosystem or some that are but which now have broken
argument order in terms of threading. Most of this stuff really
should be in clojure.string, but for unknown reasons isn't.

butlast

(butlast n s)
Returns s without the last n characters.  Returns an empty string
if n is greater than the length of s.

codepoints

(codepoints s)
Returns a sequence of integer Unicode code points in s.  Handles
Unicode supplementary characters (above U+FFFF) correctly.

digits?

(digits? s)
Test and return whether S is a string of only digits 0-9.  If so,
return generalized boolean else return nil/false

drop

(drop n s)
Drops first n characters from s.  Returns an empty string if n is
greater than the length of s.

get

(get s i)
Gets the i'th character in string.

map

(map f coll)
Apply f to each element of coll, concatenate all results into a
String.

partition-stg

(partition-stg n stg)(partition-stg n step stg)(partition-stg n step pad stg)
Returns a sequence of strings of n chars each, at offsets step
apart. If step is not supplied, defaults to n, i.e. the partitions
do not overlap. If a pad collection (a string or other collection
of chars) is supplied, use its characters as necessary to complete
last partition upto n characters. In case there are not enough
padding chars, return a partition with less than n characters.

repeat

(repeat n s)
Returns a new String containing s repeated n times.

replace

(replace match replacement s)
Replaces all instance of match with replacement in s.

match/replacement can be:

string / string
char / char
pattern / (string or function of match).

See also replace-first.

The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.  If you wish your replacement
string r to be used literally, use (re-quote-replacement r) as the
replacement argument.  See also documentation for
java.util.regex.Matcher's appendReplacement method.

Example:
(clojure.string/replace "Almost Pig Latin" #"\b(\w)(\w+)\b" "$2$1ay")
-> "lmostAay igPay atinLay"

replace-first

(replace-first match replacement s)
Replaces the first instance of match with replacement in s.

match/replacement can be:

char / char
string / string
pattern / (string or function of match).

See also replace.

The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.  If you wish your replacement
string r to be used literally, use (re-quote-replacement r) as the
replacement argument.  See also documentation for
java.util.regex.Matcher's appendReplacement method.

Example:
(clojure.string/replace-first "swap first two words"
                              #"(\w+)(\s+)(\w+)" "$3$2$1")
-> "first swap two words"

replace-re

(replace-re re replacement s)
Replaces all matches of re with replacement in s.

reverse

(reverse s)
Reverse string S. Return S' s.t. S'[i] = S[l-i]

sliding-take

(sliding-take n stg)(sliding-take d n stg)
Sliding window take for strings. N is the "window" size to slide
across STG. D is the slide displacement and defaults to 1.

split

(split re s)(split re limit s)
Splits string on a regular expression.  Optional argument limit is
the maximum number of splits. Not lazy. Returns vector of the splits.

string-equal?

(string-equal? l r)
Case insensitve string comparison.  Usable as a sort comparator

string-greater?

(string-greater? l r)
Case insensitve string comparison.  Usable as a sort comparator

string-less?

(string-less? l r)
Case insensitve string comparison.  Usable as a sort comparator

substring

(substring stg start)(substring stg start end)
Return the substring defined as stg[start..end-1] where start and
end are zero based. If end < 0, ret stg[start..(+ (count stg)
end)]. In the two argument case, takes end = (count stg)

 Ex:

 (substring "0123456789" 1 5)  => "1234"
 (substring "0123456789" 3)    => "3456789"
 (substring "0123456789" 1 -2) => "1234567"

substring?

(substring? substring s)
True if s contains the substring.

tail

(tail n s)
Returns the last n characters of s.

take

(take n s)
Take first n characters from s, up to the length of s.