include StringLabels


type t = string



let of_seq g = Buffer.contents (Stdcompat__buffer.of_seq g)

let to_seq s = Stdcompat__tools.vec_to_seq length unsafe_get s

let to_seqi s = Stdcompat__tools.vec_to_seqi length unsafe_get s



let lowercase_ascii = lowercase

let uppercase_ascii = uppercase

let capitalize_ascii = capitalize

let uncapitalize_ascii = uncapitalize

let equal : t -> t -> bool = ( = )

let split_on_char ~sep s =
  let previous_index = ref (length s) in
  let accu = ref [] in
  for i = length s - 1 downto 0 do
    if unsafe_get s i = sep then
      begin
        accu := sub s (i + 1) (!previous_index - i - 1) :: !accu;
        previous_index := i
      end
  done;
  sub s 0 !previous_index :: !accu

let index_opt s c =
  Stdcompat__tools.option_find (index s) c

let rindex_opt s c =
  Stdcompat__tools.option_find (rindex s) c

let index_from_opt s i c =
  Stdcompat__tools.option_find (index_from s i) c

let rindex_from_opt s i c =
  Stdcompat__tools.option_find (rindex_from s i) c



let init n ~f =
  let s = create n in
  for i = 0 to n - 1 do
    s.[i] <- f i
  done;
  s

let mapi ~f s =
  init (length s) (fun i -> f i (unsafe_get s i))



let iteri ~f s =
  for i = 0 to length s - 1 do
    f i (unsafe_get s i)
  done

let map ~f s =
  init (length s) (fun i -> f (unsafe_get s i))

let trim s =
  Stdcompat__string.trim s



let compare : t -> t -> int = compare

