module StrExtras: sig end
String construction
|
val combine : string list -> string
val implode : char list -> string
val of_array : char array -> string
val map : (char -> char) -> string -> string
Array.map
, for strings. Returns a newly allocated
transformed string.val mapi : (char -> int -> char) -> string -> string
map
, but passes the index as well as the character.val subpos : string -> int -> int -> string
subpos string startp endp
returns the substring of string
starting at position start and ending at position end. subpos "foo."
0 2
returns "foo", for example.val repeat : string -> int -> string
repeat s n
returns a new string made up of n copies of s.
Processing characters
|
val iteri : (char -> int -> unit) -> string -> unit
String.iter
, but passes the index of the character as well.val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a
fold_left f x s
computes f (... (f (f x s.[0]) s.[1])
...) s.[n-1]
where n
is the length of the string s
.val fold_right : ('a -> char -> 'a) -> string -> 'a -> 'a
fold_right f s x
computes
f s.(0) (f s.(1) ( ... (f s.(n-1) x) ...))
,
where n
is the length of the string s
.val ensure : (char -> bool) -> string -> bool
ensure f s
returns true if f
is true for all characters in
s
. It stops after the first false result, making it more efficient
than StrExtras.fold_left
for validation.val ensure_range : (char -> bool) -> string -> int -> int -> bool
ensure_range f s i len
applies f
to the len
-gth characters in s
starting at index i
and returns true if f
is true for all the
characters, otherwise false.
String manipulation
|
val explode : string -> char list
val to_array : string -> char array
val center : ?pad:char -> ?trunc:bool -> string -> int -> string
center str length
returns str centered in a length-character
line. The default padding character is space. If trunc is true and the
string is longer than length, the string is truncated.val ljust : ?pad:char -> ?trunc:bool -> string -> int -> string
ljust str length
adds padding characters to the end of str if
needed so it is len characters long. The default padding character is a
space. If trunc is true, and the string is longer than length
characters, it is cut off. The default is to return a copy of string if
it is longer than length.val rjust : ?pad:char -> ?trunc:bool -> string -> int -> string
rjust
, but padding is added to the start of the string
if needed.typetrim_style =
[ `Both | `Left | `Right ]
trim
cuts characters from.val trim : ?style:trim_style -> string -> char -> string
trim string character
removes any leading and trailing
occurances of character from string. style controls wether they're
removed from just the front or back.val map_inplace : (char -> char) -> string -> unit
map
, but modifies the argument string.val mapi_inplace : (char -> int -> char) -> string -> unit
map_inplace
, but passes the index of the character as well.val rev : string -> string
Trimming off bits
|
val first_word : string -> string
val cut_first_char : string -> string
val cut_first_n : string -> int -> string
n
characters of a string and returns the rest.val cut_last_char : string -> string
val cut_last_n : string -> int -> string
n
characters of a string and returns the restval cut_first_word : string -> string
val split_at : str:string -> sep:char -> string
val chomp : string -> string
val right : string -> int -> string
val left : string -> int -> string
Capitalization
|
val uppercase : string -> string
String.uppercase
, but locale-dependantval lowercase : string -> string
String.lowercase
, but locale-dependantval capitalize : string -> string
String.capitalize
, but locale-dependantval uncapitalize : string -> string
String.uncapitalize
, but locale-dependantval titlecase : string -> string
Searching
|
val first_of : string -> string -> int
first_of needle haystack
returns the position of the first
occurance in haystack of a character in needle. Like C strcspn().Not_found
if no characters in needle are in haystackval first_of_from : string -> string -> int -> int
first_of_from needle haystack pos
returns the position of the first occurance in haystack (Starting at pos) of a character in needle.Not_found
if no characters in needle are in haystackval last_of : string -> string -> int
last_of needle haystack
returns the position of the last
occurance in haystack of a character in needle.Not_found
if no characters in needle are in haystackval last_of_from : string -> string -> int -> int
last_of_from needle haystack pos
returns the position of the
last occurance in haystack (Starting to look at pos) of a character in
needle.Not_found
if no characters in needle are in haystackval first_not_of : string -> string -> int
first_not_of needle haystack
returns the position of the first
occurance in haystack of a character that's not also in needle. Like C
strspn().Not_found
if all characters in needle are in haystackval first_not_of_from : string -> string -> int -> int
first_not_of_from needle haystack pos
returns the position of
the first occurance in haystack (Starting at pos) of a character
that's not also in needle.Not_found
if all characters in needle are in haystackval last_not_of : string -> string -> int
last_not_of needle haystack
returns the position of the last
occurance in haystack of a character that's not also in needle.Not_found
if all characters in needle are in haystackval last_not_of_from : string -> string -> int -> int
last_not_of_from needle haystack pos
returns the position of the
last occurance in haystack (Starting at pos) of a character that's not
also in needle.Not_found
if all characters in needle are in haystackval prefix : string -> string -> bool
prefix pref str
returns true if str starts with pref.val suffix : string -> string -> bool
suffix suf str
returns true if str ends with suf.val index_substr : string -> string -> int
index_substr needle haystack
returns the position in haystack
where needle starts.Not_found
if the substring isn't present.val index_substr_from : string -> string -> int -> int
index_substr_from needle haystack pos
returns the position in
haystack where needle starts, starting looking at pos.Not_found
if the substring isn't present.Invalid_argument
if the positition is outside of haystack.val match_substr : string -> string -> int -> bool
match_substr substr str pos
returns true if str contains substr
at position posInvalid_argument
if pos is out of rangemodule FastSearch: sig end
val common_prefix : string list -> string
common_prefix ["foobar"; "foobaz"; "food"]
returns "foo"
.
Replacing
|
val replace : string -> string -> string -> string
StrExtras.replace str old new
replaces every instance of old
with new
in str
and returns a new string with the changes.
Comparison
|
val collate : string -> string -> int
collate a b
compares two strings like String.compare
, but
using the `LC_COLLATE
locale via the C strcoll()
function.val compare_insensitive : string -> string -> int
compare_insensitive a b
compares two strings in a
case-insensitive manner, using the current `LC_CTYPE
locale.
Modules for comparision
|
These modules can be used as the input to functor like Map.Make
or
Hashtbl.Make
module Collate: sig end
StrExtras.collate
.
module CaseInsensitive: sig end
StrExtras.compare_insensitive
.