jon.recoil.org

Module Ocamlformat_stdlib.StringSource

include module type of Base.String
Sourcemodule type Utf = Base.String.Utf

Interface for Unicode encodings, such as UTF-8. Written with an abstract type, and specialized below.

Sourcemodule type Utf_as_string = Base.String.Utf_as_string

Iterface for Unicode encodings, specialized for string representation.

An extension of the standard StringLabels. If you open Base, you'll get these extensions in the String module.

Sourcetype t = string
Sourceval globalize : t @ local -> t
include Sexplib0.Sexpable.S__stack with type t := t
include Sexplib0.Sexpable.Of_sexp with type t := t
include Sexplib0.Sexpable.Sexp_of__stack with type t := t
Sourceval t_sexp_grammar : t Sexplib0.Sexp_grammar.t @@ portable
Sourceval sub : t -> pos:int -> len:int -> t @@ portable
Sourceval unsafe_sub : t @ local -> pos:int -> len:int -> t @ unique @@ portable

sub with no bounds checking, and always returns a new copy

Sourceval subo : ?pos:int -> ?len:int -> t -> t @@ portable
Sourceval copy : t @ local -> t @ unique @@ portable
include Base.Indexed_container.S0_with_creators__stack with type t := t with type elt = char
include Base.Container.S0__''value''__stack with type t := t with type elt = char
include sig ... end
Sourcetype elt = char
include sig ... end
include sig ... end

These are all like their equivalents in Container except that an index starting at 0 is added as the first argument to f.

Sourceval iteri : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> unit) @ local) @ local -> unit
Sourceval existsi : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> bool
Sourceval for_alli : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> bool
Sourceval counti : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> int
Sourceval foldi : ('a : value mod separable) 'p1 'p2 'acc. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> init:'acc -> f: (int -> ('acc -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'acc) @ local) @ local) @ local -> 'acc
Sourceval iteri_until : ('a : value mod separable) 'p1 'p2 'final. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> (unit, 'final) Container.Continue_or_stop.t) @ local) @ local -> finish:(int -> 'final) @ local -> 'final
Sourceval find_mapi : ('a : value mod separable) 'p1 'p2 'b. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'b option) @ local) @ local -> 'b option
Sourceval foldi_until : ('a : value mod separable) 'p1 'p2 'acc 'final. ('a, _, _) Base.String.{t}41/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> init:'acc -> f: (int -> ('acc -> ('a Base.String.{elt}42/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> ('acc, 'final) Container.Continue_or_stop.t) @ local) @ local) @ local -> finish:(int -> ('acc -> 'final) @ local) @ local -> 'final
Sourceval findi : ('a : value mod separable) 'p1 'p2. ('a, 'p1, 'p2) t -> f:(int -> ('a elt -> bool) @ local) @ local -> (int * 'a elt) option
include Base.Container.S0_with_creators__''value''__stack with type t := t with type elt := elt
include sig ... end
include sig ... end
Sourceval is_empty : ('a : value mod separable) 'p1 'p2. t @ local -> bool
Sourceval iter : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> unit) @ local -> unit

iter must allow exceptions raised in f to escape, terminating the iteration cleanly. The same holds for all functions below taking an f.

Sourceval exists : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> bool

Returns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.

Sourceval for_all : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> bool

Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.

Sourceval count : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> int

Returns the number of elements for which the provided function evaluates to true.

Sourceval find : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> elt option

Returns as an option the first element for which f evaluates to true.

Sourceval to_list : ('a : value mod separable) 'p1 'p2. t -> elt list
Sourceval min_elt : ('a : value mod separable) 'p1 'p2. t -> compare:(elt -> (elt -> int) @ local) @ local -> elt option

Returns a min (resp. max) element from the collection using the provided compare function. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold. Returns None iff the collection is empty.

Sourceval max_elt : ('a : value mod separable) 'p1 'p2. t -> compare:(elt -> (elt -> int) @ local) @ local -> elt option
Sourceval sum : ('a : value mod separable) 'sum 'p1 'p2. (module Container.Summable with type t = 'sum) -> t -> f:(elt -> 'sum) @ local -> 'sum

Returns the sum of f i for all i in the container. The order in which the elements will be summed is unspecified.

Sourceval iter_until : ('a : value mod separable) 'p1 'p2 'final. t -> f:(elt -> (unit, 'final) Container.Continue_or_stop.t) @ local -> finish:(unit -> 'final) @ local -> 'final

iter_until t ~f ~finish is a short-circuiting version of iter. If f returns Stop x the computation ceases and returns x. If f always returns Continue () the final result is computed by finish.

Sourceval fold : ('a : value mod separable) 'p1 'p2 'acc. t -> init:'acc -> f:('acc -> (elt -> 'acc) @ local) @ local -> 'acc

fold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t.

Sourceval fold_result : ('a : value mod separable) 'p1 'p2 'acc 'e. t -> init:'acc -> f:('acc -> (elt -> ('acc, 'e) result) @ local) @ local -> ('acc, 'e) result

fold_result t ~init ~f is a short-circuiting version of fold that runs in the Result monad. If f returns an Error _, that value is returned without any additional invocations of f.

Sourceval find_map : ('a : value mod separable) 'p1 'p2 'b. t -> f:(elt -> 'b option) @ local -> 'b option

Returns the first evaluation of f that returns Some, and returns None if there is no such element.

include sig ... end
Sourceval fold_until : ('a : value mod separable) 'p1 'p2 'acc 'final. t -> init:'acc -> f: ('acc -> (elt -> ('acc, 'final) Container.Continue_or_stop.t) @ local) @ local -> finish:('acc -> 'final) @ local -> 'final

fold_until t ~init ~f ~finish is a short-circuiting version of fold. If f returns Stop _ the computation ceases and results in that value. If f returns Continue _, the fold will proceed. If f never returns Stop _, the final result is computed by finish.

Example:

  type maybe_negative =
    | Found_negative of int
    | All_nonnegative of { sum : int }

  (** [first_neg_or_sum list] returns the first negative number in [list], if any,
      otherwise returns the sum of the list. *)
  let first_neg_or_sum =
    List.fold_until ~init:0
      ~f:(fun sum x ->
        if x < 0
        then Stop (Found_negative x)
        else Continue (sum + x))
      ~finish:(fun sum -> All_nonnegative { sum })
  ;;

  let x = first_neg_or_sum [1; 2; 3; 4; 5]
  val x : maybe_negative = All_nonnegative {sum = 15}

  let y = first_neg_or_sum [1; 2; -3; 4; 5]
  val y : maybe_negative = Found_negative -3
include sig ... end
Sourceval of_list : ('a : value mod separable) 'p1 'p2. elt list -> t
Sourceval filter : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> t

filter t ~f returns all the elements of t that satisfy the predicate f.

Sourceval partition_tf : ('a : value mod separable) 'p1 'p2. t -> f:(elt -> bool) @ local -> t * t

partition_tf t ~f returns a pair t1, t2, where t1 is all elements of t that satisfy f, and t2 is all elements of t that do not satisfy f. The "tf" suffix is mnemonic to remind readers that the result is (trues, falses).

include sig ... end
Sourceval map : ('a : value mod separable) 'p1 'p2 ('b : value mod separable). t -> f:(elt -> elt) @ local -> t

map f (of_list [a1; ...; an]) applies f to a1, a2, ..., an, in order, and builds a result equivalent to of_list [f a1; ...; f an].

Sourceval filter_map : ('a : value mod separable) 'p1 'p2 ('b : value mod separable). t -> f:(elt -> elt option) @ local -> t

filter_map t ~f applies f to every x in t. The result contains every y for which f x returns Some y.

include sig ... end
Sourceval partition_map : ('a : value mod separable) 'p1 'p2 ('b : value mod separable) ('c : value mod separable). t -> f:(elt -> (elt, elt) Base__.Either0.t) @ local -> t * t

partition_map t ~f partitions t according to f.

Sourceval to_array : t -> elt array
Sourceval of_array : elt array -> t
Sourceval init : ('a : value mod separable) 'p1 'p2. int -> f: (int -> 'a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)) @ local -> ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

init n ~f is equivalent to of_list [f 0; f 1; ...; f (n-1)]. It raises an exception if n < 0.

Sourceval filteri : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)
Sourceval partitioni_tf : ('a : value mod separable) 'p1 'p2. ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) * ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

partitioni_tf t ~f is like partition_tf. Additionally, it passes the index as an argument.

Sourceval mapi : ('a : value mod separable) 'p1 'p2 ('b : value mod separable). ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'b Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)) @ local) @ local -> ('b, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

mapi is like map. Additionally, it passes in the index of each element as the first argument to the mapped function.

Sourceval filter_mapi : ('a : value mod separable) 'p1 'p2 ('b : value mod separable). ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'b Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) option) @ local) @ local -> ('b, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

filter_mapi is like filter_map. Additionally, it passes in the index of each element as the first argument to the mapped function.

Sourceval partition_mapi : ('a : value mod separable) 'p1 'p2 ('b : value mod separable) ('c : value mod separable). ('a, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> ('b Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca), 'c Base.String.{elt}291/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)) Base__.Either0.t) @ local) @ local -> ('b, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) * ('c, _, _) Base.String.{t}290/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

partition_mapi t ~f is like partition_map. Additionally, it passes the index as an argument.

include Base.Identifiable.S__local__portable with type t := t
include Ppx_hash_lib.Hashable.S with type t := t
include Sexplib0.Sexpable.S with type t := t
include Sexplib0.Sexpable.Of_sexp with type t := t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
include Sexplib0.Sexpable.Sexp_of with type t := t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
include Base.Stringable.S with type t := t
include Base.Stringable.Of_stringable with type t := t
Sourceval of_string : string -> t
include Base.Stringable.To_stringable with type t := t
Sourceval to_string : t -> string
include Base.Comparable.S__local__portable with type t := t
include Base.Comparisons.S__local with type t := t
include Base.Comparisons.Infix with type t := t
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int

compare t1 t2 returns 0 if t1 is equal to t2, a negative integer if t1 is less than t2, and a positive integer if t1 is greater than t2.

Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval ascending : t -> t -> int @@ portable

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

Sourceval descending : t -> t -> int @@ portable
Sourceval between : t -> low:t -> high:t -> bool @@ portable

between t ~low ~high means low <= t <= high

Sourceval clamp_exn : t -> min:t -> max:t -> t @@ portable

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

Sourceval clamp : t -> min:t -> max:t -> t Base.Or_error.t @@ portable
include Base.Comparator.S__portable with type t := t
Sourcetype comparator_witness : value mod portable = Base.String.comparator_witness
include Base.Pretty_printer.S with type t := t
Sourceval pp : Base.Formatter.t -> t -> unit
Sourceval hashable : t Base.Hashable.t
include Base.Invariant.S with type t := t
Sourceval invariant : t -> unit
Sourceval max_length : int @@ portable

Maximum length of a string.

Sourceval mem : t @ local -> char -> bool @@ portable
Sourceval length : t -> int @@ portable
Sourceval get : t -> int -> char @@ portable
Sourceval unsafe_get : string -> int -> char @@ portable

unsafe_get t i is like get t i but does not perform bounds checking. The caller must ensure that it is a memory-safe operation.

Sourceval make : int -> char -> t @@ portable
Sourceval (^) : t @ local -> t @ local -> t @@ portable

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.

Sourceval append : t @ local -> t @ local -> t @@ portable
Sourceval concat : ?sep:t -> t list @ local -> t @@ portable

Concatenates all strings in the list using separator sep (with a default separator "").

Sourceval escaped : t -> t @@ portable

Special characters are represented by escape sequences, following the lexical conventions of OCaml.

Sourceval contains : ?pos:int -> ?len:int -> t @ local -> char -> bool @@ portable
Sourceval uppercase : t -> t @@ portable

Operates on the whole string using the US-ASCII character set, e.g. uppercase "foo" = "FOO".

Sourceval lowercase : t -> t @@ portable

Operates on the whole string using the US-ASCII character set, e.g. lowercase "FOO" = "foo".

Sourceval capitalize : t -> t @@ portable

Operates on just the first character using the US-ASCII character set, e.g. capitalize "foo" = "Foo".

Sourceval uncapitalize : t -> t @@ portable
Sourcemodule Caseless = Base.String.Caseless

Caseless compares and hashes strings ignoring case, so that for example Caseless.equal "OCaml" "ocaml" and Caseless.("apple" < "Banana") are true.

index gives the index of the first appearance of char in the string when searching from left to right, or None if it's not found. rindex does the same but searches from the right.

For example, String.index "Foo" 'o' is Some 1 while String.rindex "Foo" 'o' is Some 2.

The _exn versions return the actual index (instead of an option) when char is found, and raise Stdlib.Not_found or Not_found_s otherwise.

Sourceval index : t @ local -> char -> int option @@ portable
Sourceval index_exn : t @ local -> char -> int @@ portable
Sourceval index_from : t @ local -> int -> char -> int option @@ portable
Sourceval index_from_exn : t @ local -> int -> char -> int @@ portable
Sourceval rindex : t @ local -> char -> int option @@ portable
Sourceval rindex_exn : t @ local -> char -> int @@ portable
Sourceval rindex_from : t @ local -> int -> char -> int option @@ portable
Sourceval rindex_from_exn : t @ local -> int -> char -> int @@ portable
Sourceval to_sequence : t -> char Base.Sequence.t @@ portable

Produce a sequence of the characters in a string.

Sourceval of_sequence : char Base.Sequence.t -> t @@ portable

Read the characters in a full sequence and produce a string.

Sourcemodule Search_pattern = Base.String.Search_pattern

Substring search and replace functions. They use the Knuth-Morris-Pratt algorithm (KMP) under the hood.

Sourceval substr_index : ?pos:int -> t @ local -> pattern:t @ local -> int option @@ portable

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.

Sourceval substr_index_exn : ?pos:int -> t @ local -> pattern:t -> int @@ portable
Sourceval substr_index_all : t @ local -> may_overlap:bool -> pattern:t @ local -> int list @@ portable
Sourceval substr_replace_first : ?pos:int -> t -> pattern:t @ local -> with_:t @ local -> t @@ portable
Sourceval substr_replace_all : t -> pattern:t @ local -> with_:t @ local -> t @@ portable

As with Search_pattern.replace_all, the result may still contain pattern.

Sourceval is_substring : t @ local -> substring:t @ local -> bool @@ portable

is_substring ~substring:"bar" "foo bar baz" is true.

Sourceval is_substring_at : t @ local -> pos:int -> substring:t @ local -> bool @@ portable

is_substring_at "foo bar baz" ~pos:4 ~substring:"bar" is true.

Sourceval to_list_rev : t -> char list @@ portable

Returns the reversed list of characters contained in a list.

Sourceval rev : t -> t @@ portable

rev t returns t in reverse order.

Sourceval is_suffix : t @ local -> suffix:t @ local -> bool @@ portable

is_suffix s ~suffix returns true if s ends with suffix.

Sourceval is_prefix : t @ local -> prefix:t @ local -> bool @@ portable

is_prefix s ~prefix returns true if s starts with prefix.

Sourceval lsplit2_exn : t -> on:char -> t * t @@ portable

If the string s contains the character on, then lsplit2_exn s ~on returns a pair containing s split around the first appearance of on (from the left). Raises Stdlib.Not_found or Not_found_s when on cannot be found in s.

Sourceval rsplit2_exn : t -> on:char -> t * t @@ portable

If the string s contains the character on, then rsplit2_exn s ~on returns a pair containing s split around the first appearance of on (from the right). Raises Stdlib.Not_found or Not_found_s when on cannot be found in s.

Sourceval lsplit2 : t -> on:char -> (t * t) option @@ portable

lsplit2 s ~on optionally returns s split into two strings around the first appearance of on from the left.

Sourceval rsplit2 : t -> on:char -> (t * t) option @@ portable

rsplit2 s ~on optionally returns s split into two strings around the first appearance of on from the right.

Sourceval split : t -> on:char -> t list @@ portable

split s ~on returns a list of substrings of s that are separated by on. Consecutive on characters will cause multiple empty strings in the result. Splitting the empty string returns a list of the empty string, not the empty list.

Sourceval split_on_chars : t -> on:char list -> t list @@ portable

split_on_chars s ~on returns a list of all substrings of s that are separated by one of the chars from on. on are not grouped. So a grouping of on in the source string will produce multiple empty string splits in the result.

Sourceval lstrip : ?drop:(char -> bool) @ local -> t -> t @@ portable

lstrip ?drop s returns a string with consecutive chars satisfying drop (by default white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the beginning of s.

Sourceval rstrip : ?drop:(char -> bool) @ local -> t -> t @@ portable

rstrip ?drop s returns a string with consecutive chars satisfying drop (by default white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the end of s.

Sourceval strip : ?drop:(char -> bool) @ local -> t -> t @@ portable

strip ?drop s returns a string with consecutive chars satisfying drop (by default white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the beginning and end of s.

Sourceval split_lines : t -> t list @@ portable

split_lines t returns the list of lines that comprise t. The lines do not include the trailing "\n" or "\r\n".

Sourceval lfindi : ?pos:int -> t @ local -> f:(int -> (char -> bool) @ local) @ local -> int option @@ portable

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.

Sourceval rfindi : ?pos:int -> t @ local -> f:(int -> (char -> bool) @ local) @ local -> int option @@ portable

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.

Sourceval concat_map : ?sep:t -> t -> f:(char -> t) @ local -> t @@ portable

Like map, but allows the replacement of a single character with zero or two or more characters.

Sourceval concat_mapi : ?sep:t -> t -> f:(int -> (char -> t) @ local) @ local -> t @@ portable
Sourceval tr : target:char -> replacement:char -> t -> t @@ portable

tr ~target ~replacement s replaces every instance of target in s with replacement.

Sourceval tr_multi : target:t -> replacement:t -> (t -> t) Base.Staged.t @@ portable

tr_multi ~target ~replacement returns a function that replaces every instance of a character in target with the corresponding character in replacement.

If replacement is shorter than target, it is lengthened by repeating its last character. Empty replacement is illegal unless target also is.

If target contains multiple copies of the same character, the last corresponding replacement character is used. Note that character ranges are not supported, so ~target:"a-z" means the literal characters 'a', '-', and 'z'.

Sourceval chop_suffix_exn : t -> suffix:t -> t @@ portable

chop_suffix_exn s ~suffix returns s without the trailing suffix, raising Invalid_argument if suffix is not a suffix of s.

Sourceval chop_prefix_exn : t -> prefix:t -> t @@ portable

chop_prefix_exn s ~prefix returns s without the leading prefix, raising Invalid_argument if prefix is not a prefix of s.

Sourceval chop_suffix : t -> suffix:t -> t option @@ portable
Sourceval chop_prefix : t -> prefix:t -> t option @@ portable
Sourceval chop_suffix_if_exists : t -> suffix:t -> t @@ portable

chop_suffix_if_exists s ~suffix returns s without the trailing suffix, or just s if suffix isn't a suffix of s.

Equivalent to chop_suffix s ~suffix |> Option.value ~default:s, but avoids allocating the intermediate option.

Sourceval chop_prefix_if_exists : t -> prefix:t -> t @@ portable

chop_prefix_if_exists s ~prefix returns s without the leading prefix, or just s if prefix isn't a prefix of s.

Equivalent to chop_prefix s ~prefix |> Option.value ~default:s, but avoids allocating the intermediate option.

Sourceval suffix : t -> int -> t @@ portable

suffix s n returns the longest suffix of s of length less than or equal to n.

Sourceval prefix : t -> int -> t @@ portable

prefix s n returns the longest prefix of s of length less than or equal to n.

Sourceval drop_suffix : t -> int -> t @@ portable

drop_suffix s n drops the longest suffix of s of length less than or equal to n.

Sourceval drop_prefix : t -> int -> t @@ portable

drop_prefix s n drops the longest prefix of s of length less than or equal to n.

Sourceval common_suffix : t list -> t @@ portable

Produces the longest common suffix, or "" if the list is empty.

Sourceval common_prefix : t list -> t @@ portable

Produces the longest common prefix, or "" if the list is empty.

Sourceval common_suffix_length : t list -> int @@ portable

Produces the length of the longest common suffix, or 0 if the list is empty.

Sourceval common_prefix_length : t list -> int @@ portable

Produces the length of the longest common prefix, or 0 if the list is empty.

Sourceval common_suffix2 : t -> t -> t @@ portable

Produces the longest common suffix.

Sourceval common_prefix2 : t -> t -> t @@ portable

Produces the longest common prefix.

Sourceval common_suffix2_length : t -> t -> int @@ portable

Produces the length of the longest common suffix.

Sourceval common_prefix2_length : t -> t -> int @@ portable

Produces the length of the longest common prefix.

Sourceval concat_array : ?sep:t @ local -> t array @ local -> t @@ portable

concat_array sep ar like String.concat, but operates on arrays.

Sourceval concat_lines : ?crlf:bool -> string list -> string @@ portable

Builds a multiline text from a list of lines. Each line is terminated and then concatenated.

  # String.concat_lines ["one two"; "three four"; "five"]
  - : string = "one two\nthree four\nfive\n"
  # String.concat_lines ~crlf:true ["one two"; "three four"; "five"]
  - : string = "one two\r\nthree four\r\nfive\r\n"
Sourceval hash : t -> int @@ portable

Slightly faster hash function on strings.

Sourceval of_char : char -> t @@ portable
Sourceval of_char_list : char list @ local -> t @@ portable
Sourceval pad_left : ?char:char -> string -> len:int -> string @@ portable

pad_left ?char s ~len returns s padded to the length len by adding characters char to the beginning of the string. If s is already longer than len it is returned unchanged.

Sourceval pad_right : ?char:char -> string -> len:int -> string @@ portable

pad_right ?char ~s len returns s padded to the length len by adding characters char to the end of the string. If s is already longer than len it is returned unchanged.

Sourceval edit_distance : string -> string -> int @@ portable

Reports the Levenshtein edit distance between two strings. Computes the minimum number of single-character insertions, deletions, and substitutions needed to transform one into the other.

For strings of length M and N, its time complexity is O(M*N) and its space complexity is O(min(M,N)).

Sourcemodule Escaping = Base.String.Escaping

Operations for escaping and unescaping strings, with parameterized escape and escapeworthy characters. Escaping/unescaping using this module is more efficient than using Pcre. Benchmark code can be found in core/benchmarks/string_escaping.ml.

UTF-8 encoding. See Utf interface.

Sourcemodule Utf16le = Base.String.Utf16le

UTF-16 little-endian encoding. See Utf interface.

Sourcemodule Utf16be = Base.String.Utf16be

UTF-16 big-endian encoding. See Utf interface.

Sourcemodule Utf32le = Base.String.Utf32le

UTF-32 little-endian encoding. See Utf interface.

Sourcemodule Utf32be = Base.String.Utf32be

UTF-32 big-endian encoding. See Utf interface.

Sourceval starts_with_whitespace : string -> bool

starts_with_whitespace s holds if s is non empty and starts with a whitespace character.

Sourceval ends_with_whitespace : string -> bool

ends_with_whitespace s holds if s is non empty and ends with a whitespace character.

Sourceval indent_of_line : string -> int option

indent_of_line s is the indentation at the beginning of s. Returns None if the first line of the string is only whitespaces or is empty.