Module String_extended
Extensions to Core.Core_String.
val collate : string -> string -> intcollate s1 s2sorts 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):
- Non_numerical chunks are compared using lexicographical ordering.
- Numerical chunks are compared based on the values of the represented ints and the number of trailing zeros.
It is a total order.
val unescaped : ?strict:bool -> string -> stringunescaped sis the inverse operation ofescaped: it takes a string where all the special characters are escaped following the lexical convention of OCaml and returns an unescaped copy. Thestrictswitch is on by default and makes the function treat illegal backslashes as errors. Whenstrictisfalseevery illegal backslash except escaped numeral greater than255is copied literally. The aforementioned numerals still raise errors. This mimics the behaviour of the ocaml lexer.
val unescaped_res : ?strict:bool -> string -> (string, int * string) Core_kernel.Result.tSame as
unescapedbut instead of raisingFailure _returns an error message with the position in the string in case of failure.
val squeeze : string -> stringsqueeze strreduces all sequences of spaces, newlines, tabs, and carriage returns to single spaces.
val is_substring_deprecated : substring:string -> string -> boolUse Core.String.is_substring instead of this function. This wrapper is here (for now) to maintain bug compatibility.
val pad_left : ?char:char -> string -> int -> stringpad_left ~char s lenReturnsspadded to the lengthlenby adding characterscharto the left of the string. If s is already longer thanlenit is returned unchanged.
val pad_right : ?char:char -> string -> int -> stringval line_break : len:int -> string -> string listdeprecated in favour of word_wrap
val word_wrap : ?trailing_nl:bool -> ?soft_limit:int -> ?hard_limit:int -> ?nl:string -> string -> stringword_wrap ~soft_limit sWraps the string so that it fits the length
soft_limit. It doesn't break words unless we go overhard_limit.if
nlis passed it is inserted instead of the normal newline character.
val edit_distance : ?transpose:unit -> string -> string -> intGives 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
transposeargument, it also considers transpositions (Damerau-Levenshtein distance).