Blame src/extString.mli

rpm-build 0f2925
(*
rpm-build 0f2925
 * ExtString - Additional functions for string manipulations.
rpm-build 0f2925
 * Copyright (C) 2003 Nicolas Cannasse
rpm-build 0f2925
 * 
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
rpm-build 0f2925
(** Additional functions for string manipulations. *)
rpm-build 0f2925
rpm-build 0f2925
open ExtBytes
rpm-build 0f2925
rpm-build 0f2925
exception Invalid_string
rpm-build 0f2925
rpm-build 0f2925
module String :
rpm-build 0f2925
  sig
rpm-build 0f2925
rpm-build 0f2925
  (** {6 New Functions} *)
rpm-build 0f2925
rpm-build 0f2925
  val init : int -> (int -> char) -> string
rpm-build 0f2925
  (** [init l f] returns the string of length [l] with the chars
rpm-build 0f2925
      f 0 , f 1 , f 2 ... f (l-1). *)
rpm-build 0f2925
rpm-build 0f2925
  val find : string -> string -> int
rpm-build 0f2925
  (** [find s x] returns the starting index of the string [x]
rpm-build 0f2925
      within the string [s] or raises [Invalid_string] if [x]
rpm-build 0f2925
      is not a substring of [s]. *)
rpm-build 0f2925
rpm-build 0f2925
  val find_from : string -> int -> string -> int
rpm-build 0f2925
  (** [find s i x] returns the starting index of the string [x]
rpm-build 0f2925
      within the string [s] (starting search from position [i]) or
rpm-build 0f2925
      raises [Invalid_string] if no such substring exists.
rpm-build 0f2925
      [find s x] is equivalent to [find_from s 0 x]. *)
rpm-build 0f2925
rpm-build 0f2925
  val split : string -> string -> string * string
rpm-build 0f2925
  (** [split s sep] splits the string [s] between the first
rpm-build 0f2925
      occurrence of [sep].
rpm-build 0f2925
      raises [Invalid_string] if the separator is not found. *)
rpm-build 0f2925
rpm-build 0f2925
  val nsplit : string -> string -> string list
rpm-build 0f2925
  (** [nsplit s sep] splits the string [s] into a list of strings
rpm-build 0f2925
    which are separated by [sep].
rpm-build 0f2925
                [nsplit "" _] returns the empty list.
rpm-build 0f2925
    @raise Invalid_string if [sep] is empty string.  *)
rpm-build 0f2925
rpm-build 0f2925
  val join : string -> string list -> string
rpm-build 0f2925
  (** Same as [concat] *)
rpm-build 0f2925
rpm-build 0f2925
  val slice : ?first:int -> ?last:int -> string -> string
rpm-build 0f2925
  (** [slice ?first ?last s] returns a "slice" of the string
rpm-build 0f2925
    which corresponds to the characters [s.[first]],
rpm-build 0f2925
    [s.[first+1]], ..., [s[last-1]]. Note that the character at
rpm-build 0f2925
    index [last] is {b not} included! If [first] is omitted it
rpm-build 0f2925
    defaults to the start of the string, i.e. index 0, and if
rpm-build 0f2925
    [last] is omitted is defaults to point just past the end of
rpm-build 0f2925
    [s], i.e. [length s].  Thus, [slice s] is equivalent to
rpm-build 0f2925
    [copy s].
rpm-build 0f2925
rpm-build 0f2925
    Negative indexes are interpreted as counting from the end of
rpm-build 0f2925
    the string. For example, [slice ~last:-2 s] will return the
rpm-build 0f2925
    string [s], but without the last two characters.
rpm-build 0f2925
rpm-build 0f2925
    This function {b never} raises any exceptions. If the
rpm-build 0f2925
    indexes are out of bounds they are automatically clipped.
rpm-build 0f2925
  *)
rpm-build 0f2925
rpm-build 0f2925
  val lchop : string -> string
rpm-build 0f2925
  (** Returns the same string but without the first character.
rpm-build 0f2925
      does nothing if the string is empty. *)
rpm-build 0f2925
rpm-build 0f2925
  val rchop : string -> string
rpm-build 0f2925
  (** Returns the same string but without the last character.
rpm-build 0f2925
     does nothing if the string is empty. *)
rpm-build 0f2925
rpm-build 0f2925
  val of_int : int -> string
rpm-build 0f2925
  (** Returns the string representation of an int. *)
rpm-build 0f2925
rpm-build 0f2925
  val of_float : float -> string
rpm-build 0f2925
  (** Returns the string representation of an float. *)
rpm-build 0f2925
rpm-build 0f2925
  val of_char : char -> string
rpm-build 0f2925
  (** Returns a string containing one given character. *)
rpm-build 0f2925
rpm-build 0f2925
  val to_int : string -> int
rpm-build 0f2925
  (** Returns the integer represented by the given string or
rpm-build 0f2925
      raises [Invalid_string] if the string does not represent an integer.*)
rpm-build 0f2925
rpm-build 0f2925
  val to_float : string -> float
rpm-build 0f2925
  (** Returns the float represented by the given string or
rpm-build 0f2925
      raises Invalid_string if the string does not represent a float. *)
rpm-build 0f2925
rpm-build 0f2925
  val ends_with : string -> string -> bool
rpm-build 0f2925
  (** [ends_with s x] returns true if the string [s] is ending with [x]. *)
rpm-build 0f2925
rpm-build 0f2925
  val starts_with : string -> string -> bool
rpm-build 0f2925
  (** [starts_with s x] return true if [s] is starting with [x]. *)
rpm-build 0f2925
rpm-build 0f2925
  val enum : string -> char Enum.t
rpm-build 0f2925
  (** Returns an enumeration of the characters of a string.*)
rpm-build 0f2925
rpm-build 0f2925
  val of_enum : char Enum.t -> string
rpm-build 0f2925
  (** Creates a string from a character enumeration. *)
rpm-build 0f2925
rpm-build 0f2925
  val map : (char -> char) -> string -> string
rpm-build 0f2925
  (** [map f s] returns a string where all characters [c] in [s] have been
rpm-build 0f2925
    replaced by [f c]. **)
rpm-build 0f2925
rpm-build 0f2925
  val mapi : (int -> char -> char) -> string -> string
rpm-build 0f2925
  (** [map f s] returns a string where all characters [c] in [s] have been replaced by [f i s.\[i\]]. **)
rpm-build 0f2925
rpm-build 0f2925
  val iteri : (int -> char -> unit) -> string -> unit
rpm-build 0f2925
  (** Call [f i s.\[i\]] for every position [i] in string *)
rpm-build 0f2925
rpm-build 0f2925
  val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a
rpm-build 0f2925
    (** [fold_left f a s] is
rpm-build 0f2925
        [f (... (f (f a s.[0]) s.[1]) ...) s.[n-1]] *)
rpm-build 0f2925
  val fold_right : (char -> 'a -> 'a) -> string -> 'a -> 'a
rpm-build 0f2925
    (** [fold_right f s b] is
rpm-build 0f2925
        [f s.[0] (f s.[1] (... (f s.[n-1] b) ...))] *)
rpm-build 0f2925
rpm-build 0f2925
  val explode : string -> char list
rpm-build 0f2925
    (** [explode s] returns the list of characters in the string [s]. *)
rpm-build 0f2925
  val implode : char list -> string
rpm-build 0f2925
    (** [implode cs] returns a string resulting from concatenating
rpm-build 0f2925
        the characters in the list [cs]. *)
rpm-build 0f2925
rpm-build 0f2925
  val strip : ?chars:string -> string -> string
rpm-build 0f2925
  (** Returns the string without the chars if they are at the beginning or
rpm-build 0f2925
    at the end of the string. By default chars are " \t\r\n". *)
rpm-build 0f2925
rpm-build 0f2925
  val exists : string -> string -> bool
rpm-build 0f2925
  (** [exists str sub] returns true if [sub] is a substring of [str] or
rpm-build 0f2925
    false otherwise. *)
rpm-build 0f2925
rpm-build 0f2925
  val replace_chars : (char -> string) -> string -> string
rpm-build 0f2925
  (** [replace_chars f s] returns a string where all chars [c] of [s] have been
rpm-build 0f2925
    replaced by the string returned by [f c]. *)
rpm-build 0f2925
rpm-build 0f2925
        val replace : str:string -> sub:string -> by:string -> bool * string
rpm-build 0f2925
        (** [replace ~str ~sub ~by] returns a tuple constisting of a boolean
rpm-build 0f2925
    and a string where the first occurrence of the string [sub]
rpm-build 0f2925
    within [str] has been replaced by the string [by]. The boolean
rpm-build 0f2925
    is true if a subtitution has taken place. *)
rpm-build 0f2925
rpm-build 0f2925
  (** Return a copy of the argument, without leading and trailing
rpm-build 0f2925
     whitespace.  The characters regarded as whitespace are: [' '],
rpm-build 0f2925
     ['\012'], ['\n'], ['\r'], and ['\t'].
rpm-build 0f2925
     (Note that it is different from {!strip} defaults). *)
rpm-build 0f2925
  val trim : string -> string
rpm-build 0f2925
rpm-build 0f2925
  (** {6 Compatibility Functions} *)
rpm-build 0f2925
rpm-build 0f2925
  val uppercase_ascii : string -> string
rpm-build 0f2925
  val lowercase_ascii : string -> string
rpm-build 0f2925
  val capitalize_ascii : string -> string
rpm-build 0f2925
  val uncapitalize_ascii : string -> string
rpm-build 0f2925
rpm-build 0f2925
  val split_on_char : char -> string -> string list
rpm-build 0f2925
rpm-build 0f2925
  (** {6 Older Functions} *)
rpm-build 0f2925
rpm-build 0f2925
  (** Please refer to the Ocaml Manual for documentation of these
rpm-build 0f2925
    functions. *)
rpm-build 0f2925
rpm-build 0f2925
  val length : string -> int
rpm-build 0f2925
  val get : string -> int -> char
rpm-build 0f2925
  val set : Bytes.t -> int -> char -> unit
rpm-build 0f2925
  val create : int -> Bytes.t
rpm-build 0f2925
  val make : int -> char -> string
rpm-build 0f2925
  val copy : string -> string
rpm-build 0f2925
  val sub : string -> int -> int -> string
rpm-build 0f2925
  val fill : Bytes.t -> int -> int -> char -> unit
rpm-build 0f2925
  val blit : string -> int -> Bytes.t -> int -> int -> unit
rpm-build 0f2925
  val concat : string -> string list -> string
rpm-build 0f2925
  val iter : (char -> unit) -> string -> unit
rpm-build 0f2925
  val escaped : string -> string
rpm-build 0f2925
  val index : string -> char -> int
rpm-build 0f2925
  val index_opt : string -> char -> int option
rpm-build 0f2925
  val rindex : string -> char -> int
rpm-build 0f2925
  val rindex_opt : string -> char -> int option
rpm-build 0f2925
  val index_from : string -> int -> char -> int
rpm-build 0f2925
  val index_from_opt : string -> int -> char -> int option
rpm-build 0f2925
  val rindex_from : string -> int -> char -> int
rpm-build 0f2925
  val rindex_from_opt : string -> int -> char -> int option
rpm-build 0f2925
  val contains : string -> char -> bool
rpm-build 0f2925
  val contains_from : string -> int -> char -> bool
rpm-build 0f2925
  val rcontains_from : string -> int -> char -> bool
rpm-build 0f2925
  val uppercase : string -> string
rpm-build 0f2925
  val lowercase : string -> string
rpm-build 0f2925
  val capitalize : string -> string
rpm-build 0f2925
  val uncapitalize : string -> string
rpm-build 0f2925
rpm-build 0f2925
  type t = string
rpm-build 0f2925
  val compare : t -> t -> int
rpm-build 0f2925
  val equal : t -> t -> bool
rpm-build 0f2925
rpm-build 0f2925
#if OCAML >= 407
rpm-build 0f2925
  (** [*_seq] functions were introduced in OCaml 4.07.0, and are _not_ implemented in extlib for older OCaml versions *)
rpm-build 0f2925
  val to_seq : t -> char Seq.t
rpm-build 0f2925
  val to_seqi : t -> (int * char) Seq.t
rpm-build 0f2925
  val of_seq : char Seq.t -> t
rpm-build 0f2925
#endif
rpm-build 0f2925
rpm-build 0f2925
  (**/**)
rpm-build 0f2925
rpm-build 0f2925
  external unsafe_get : string -> int -> char = "%string_unsafe_get"
rpm-build 0f2925
  val unsafe_set : Bytes.t -> int -> char -> unit
rpm-build 0f2925
  val unsafe_blit : string -> int -> Bytes.t -> int -> int -> unit
rpm-build 0f2925
  val unsafe_fill : Bytes.t -> int -> int -> char -> unit
rpm-build 0f2925
rpm-build 0f2925
  end