Module Prime_string
Amendment to the standard library String structure.
The original String structure is not included, include Unprime_string for a full replacement.
Construction and Conversion
Iteration over Elements
val fold : (char -> 'a -> 'a) -> string -> 'a -> 'afold f sisf s.[n - 1] ∘ ... ∘ f s[0]wheren = length s.
val foldi : (int -> char -> 'a -> 'a) -> string -> 'a -> 'afoldi f sisf (n - 1) s.[n - 1] ∘ ... ∘ f 0 s[0]wheren = length s.
val count : (char -> bool) -> string -> intcount f sis the number of occurrences of a characters inswhich fulfilf.
Search Primitives
val skip_while : (char -> bool) -> string -> int -> intskip_while f sincrements a position until it reaches the end ofsor it points to a character inson whichfreturns false. In other words ifj = skip_while f s i, thenslice i j sis the largest substring starting ation whichfis constant true.
val skip_until : (char -> bool) -> string -> int -> intskip_until fis an optimisation ofskip_while (not ∘ f).
val rskip_while : (char -> bool) -> string -> int -> intrskip_while f sdecrements a position as long as the result points to a character inson whichfis true.
val rskip_until : (char -> bool) -> string -> int -> intrskip_until fis an optimization ofrskip_while (not ∘ f).
Substring Predicates
Slicing
val slice : int -> int -> string -> stringslice i j sis the slice ofsfrom positioniup to but not includingj.
val slice_from : int -> string -> stringslice_from i sis a shortcut forslice i (String.length s) s.
val cut_affix : string -> string -> (string * string) optioncut_affix afx sreturns the substrings before and after the leftmost occurrence ofafxinsorNoneifafxdoes not occur ins.
val rcut_affix : string -> string -> (string * string) optionrcut_affix afx sreturns the substrings before and after the rightmost occurrence ofafxinsorNoneifafxdoes not occur ins.
val chop_affix : string -> string -> string listchop_affix afx sreturns the substrings before, between, and after matches ofafxins, except forchop_affix afx "", which always gives[]. In other wordschop_affix afxprovides a primitive way of extracting the operands of an infix operatorafx. Ifafxcan overlap, it is unspecified which match is used.
val cut_consecutive : (char -> bool) -> string -> (string * string) optioncut_consecutive f sreturns the substrings before and after the leftmost consecutive sequence of bytes satisfyingf, orNoneif notString.exists f s.
val rcut_consecutive : (char -> bool) -> string -> (string * string) optioncut_consecutive f sreturns the substrings before and after the rightmost consecutive sequence of bytes satisfyingf, orNoneif notString.exists f s.
val chop_consecutive : (char -> bool) -> string -> string listchop_consecutive f sreturns the non-empty substrings before, between, and after consecutive sequences of bytescfor whichf cis true. In particularchop_consecutive Char.is_spaceis suitable for splitting words separated by ASCII white-spaces.