module StrExtras: sig end
String construction
|
val combine : string list -> stringval implode : char list -> stringval of_array : char array -> stringval map : (char -> char) -> string -> stringArray.map, for strings. Returns a newly allocated
transformed string.val mapi : (char -> int -> char) -> string -> stringmap, but passes the index as well as the character.val subpos : string -> int -> int -> stringsubpos 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 -> stringrepeat s n returns a new string made up of n copies of s.
Processing characters
|
val iteri : (char -> int -> unit) -> string -> unitString.iter, but passes the index of the character as well.val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'afold_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 -> 'afold_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 -> boolensure 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 -> boolensure_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 listval to_array : string -> char arrayval center : ?pad:char -> ?trunc:bool -> string -> int -> stringcenter 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 -> stringljust 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 -> stringrjust, 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 -> stringtrim 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 -> unitmap, but modifies the argument string.val mapi_inplace : (char -> int -> char) -> string -> unitmap_inplace, but passes the index of the character as well.val rev : string -> string
Trimming off bits
|
val first_word : string -> stringval cut_first_char : string -> stringval cut_first_n : string -> int -> stringn characters of a string and returns the rest.val cut_last_char : string -> stringval cut_last_n : string -> int -> stringn characters of a string and returns the restval cut_first_word : string -> stringval split_at : str:string -> sep:char -> stringval chomp : string -> stringval right : string -> int -> stringval left : string -> int -> string
Capitalization
|
val uppercase : string -> stringString.uppercase, but locale-dependantval lowercase : string -> stringString.lowercase, but locale-dependantval capitalize : string -> stringString.capitalize, but locale-dependantval uncapitalize : string -> stringString.uncapitalize, but locale-dependantval titlecase : string -> string
Searching
|
val first_of : string -> string -> intfirst_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 -> intfirst_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 -> intlast_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 -> intlast_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 -> intfirst_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 -> intfirst_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 -> intlast_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 -> intlast_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 -> boolprefix pref str returns true if str starts with pref.val suffix : string -> string -> boolsuffix suf str returns true if str ends with suf.val index_substr : string -> string -> intindex_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 -> intindex_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 -> boolmatch_substr substr str pos returns true if str contains substr
at position posInvalid_argument if pos is out of rangemodule FastSearch: sig endval common_prefix : string list -> stringcommon_prefix ["foobar"; "foobaz"; "food"]
returns "foo".
Replacing
|
val replace : string -> string -> string -> stringStrExtras.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 -> intcollate a b compares two strings like String.compare, but
using the `LC_COLLATE locale via the C strcoll()
function.val compare_insensitive : string -> string -> intcompare_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 endStrExtras.collate.
module CaseInsensitive: sig endStrExtras.compare_insensitive.