Caseless
compares and hashes strings ignoring case, so that for example
Caseless.equal "OCaml" "ocaml"
and Caseless.("apple" < "Banana")
are true
, and
Caseless.Map
, Caseless.Table
lookup and Caseless.Set
membership is
case-insensitive.
String append. Also available unqualified, but re-exported here for documentation purposes.
Note that a ^ b
must copy both a
and b
into a newly-allocated result string, so
a ^ b ^ c ^ ... ^ z
is quadratic in the number of strings. String.concat
does not
have this problem -- it allocates the result buffer only once. The Rope
module
provides a data structure which uses a similar trick to achieve fast concatenation at
either end of a string.
Substring search and replace convenience functions. They call Search_pattern.create
and then forget the preprocessed pattern when the search is complete. pos < 0
or
pos >= length t
result in no match (hence substr_index
returns None
and
substr_index_exn
raises). may_overlap
indicates whether to report overlapping
matches, see Search_pattern.index_all
.
Returns the reversed list of characters contained in a list.
nget s i
Gets the char at normalized position i
in s
.
nset s i c
Sets the char at normalized position i
to c
.
lfindi ?pos t ~f
returns the smallest i >= pos
such that f i t.[i]
, if there is
such an i
. By default, pos = 0
.
rfindi ?pos t ~f
returns the largest i <= pos
such that f i t.[i]
, if there is
such an i
. By default pos = length t - 1
.
Warning: the following strip functions have copy-on-write semantics (i.e. they may return the same string passed in)
foldi
works similarly to fold
, but also pass in index of each character to f
tr_inplace target replacement s
destructively modifies s (in place!)
replacing every instance of target
in s
with replacement
.
slightly faster hash function on strings
is_empty s
returns true
iff s
is empty (i.e. its length is 0).
gen' ?length char_gen
generates strings using the given distributions for string
length and each character.
collate s1 s2
sorts string in an order that's usaully more suited for human
consumption by treating ints specially, e.g. it will output:
["rfc1.txt";"rfc822.txt";"rfc2086.txt"]
.
It works by splitting the strings in numerical and non-numerical chunks and comparing chunks two by two from left to right (and starting on a non numerical chunk):
It is a total order.
unescaped s
is the inverse operation of escaped
: it takes a string where
all the special characters are escaped following the lexical convention of
OCaml and returns an unescaped copy.
The strict
switch is on by default and makes the function treat illegal
backslashes as errors.
When strict
is false
every illegal backslash except escaped numeral
greater than 255
is copied literally. The aforementioned numerals still
raise errors. This mimics the behaviour of the ocaml lexer.
Same as unescaped
but instead of raising Failure _
returns an error
message with the position in the string in case of failure.
squeeze str
reduces all sequences of spaces, newlines, tables, and
* carriage returns to single spaces.
Use Core.Std.String.is_substring instead of this function. This wrapper is here (for now) to maintain bug compatibility.
pad_left ~char s len
Returns s
padded to the length len
by adding characters char
to the
left of the string. If s is already longer than len
it is returned unchanged.
word_wrap ~soft_limit s
Wraps the string so that it fits the length soft_limit
. It doesn't break
words unless we go over hard_limit
.
if nl
is passed it is inserted instead of the normal newline character.
Gives the Levenshtein distance between 2 strings, which is the number of insertions,
deletions, and substitutions necessary to turn either string into the other. With the
transpose
argument, it alsos considers transpositions (Damerau-Levenshtein
distance).