module Bigstring:sig
..end
A "bigstring" here is simply a bigarray of chars. It can be used instead
of regular strings when IO involve calling C (or another language),
when very large strings are required, or for memory-mapping.
type'a
gen =unit -> 'a option
type'a
sequence =('a -> unit) -> unit
type'a
printer =Format.formatter -> 'a -> unit
A "bigstring" here is simply a bigarray of chars. It can be used instead
of regular strings when IO involve calling C (or another language),
when very large strings are required, or for memory-mapping.
typet =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
val create : int -> t
val empty : t
val init : int -> (int -> char) -> t
init n f
is the string f 0, f 1, ..., f (n-1)
.val fill : t -> char -> unit
val fill_slice : t -> char -> int -> int -> unit
fill_slice s c i len
is the same as fill (sub s i len) c
, it
fills the slice from i
to i+len-1
of s
with the char c
val size : t -> int
val length : t -> int
Bigstring.size
.val get : t -> int -> char
Invalid_argument
if the index is invalidval unsafe_get : t -> int -> char
Bigstring.get
, but without bound check. Can fail arbitrarily (including
segfault) if used improperly.val set : t -> int -> char -> unit
Invalid_argument
if the index is invalidval unsafe_set : t -> int -> char -> unit
Bigstring.set
, but without bound check. Can fail arbitrarily (including
segfault) if used improperly.val blit : t -> int -> t -> int -> int -> unit
blit s1 i1 s2 i2 len
means that elements from s1
whose indices
range from i1
to i1+len-1
are copied into the slots of s2
whose indices range from i2
to i2+len-1
. This is similar to
String.blit
or Bytes.blit
or Array.blit
.val copy : t -> t
val sub : t -> int -> int -> t
sub s i len
takes a slice of length len
from the string s
, starting
at offset i
. The slice shares the same memory as s
, meaning that
modifications of the slice will modify s
as well.
Slicing is cheap since it does not involve copying the whole range.Invalid_argument
if i, len
doesn't designate a valid substringval fold : ('a -> char -> 'a) -> 'a -> t -> 'a
val foldi : ('a -> int -> char -> 'a) -> 'a -> t -> 'a
val iter : (char -> unit) -> t -> unit
val iteri : (int -> char -> unit) -> t -> unit
val equal : t -> t -> bool
val compare : t -> t -> int
val to_bytes : t -> Bytes.t
val of_bytes : Bytes.t -> t
val of_bytes_slice : Bytes.t -> int -> int -> t
val sub_bytes : t -> int -> int -> Bytes.t
val blit_to_bytes : t -> int -> Bytes.t -> int -> int -> unit
val blit_of_bytes : Bytes.t -> int -> t -> int -> int -> unit
val blit_of_buffer : Buffer.t -> int -> t -> int -> int -> unit
val to_string : t -> string
val of_string : string -> t
val of_string_slice : string -> int -> int -> t
val of_buffer : Buffer.t -> t
of_buffer b
creates a string that contains the same as b
val of_gen : char gen -> t
val sub_string : t -> int -> int -> string
val blit_of_string : string -> int -> t -> int -> int -> unit
val to_seq : t -> char sequence
val to_gen : t -> char gen
val to_seq_slice : t -> int -> int -> char sequence
val to_gen_slice : t -> int -> int -> char gen
val to_buffer : t -> Buffer.t -> unit
val print : t printer
val concat : string -> t list -> t
concat set l
concatenates the list l
, inserting sep
between
each pair of string.val map : f:(char -> char) -> t -> t
val mapi : f:(int -> char -> char) -> t -> t
val lowercase : t -> t
Char.lowercase
)val uppercase : t -> t
Char.uppercase
)val trim : t -> t
trim s
returns a slice of s
without the leading and trailing
whitespaces, where whitespaces are defined identically to String.trim
.
note that it does not copy the substring, but returns a slice!s
, or empty if s
is totally composed of whitespacesval index : t -> c:char -> int
index s ~c
returns the index of the first
occurrence of character c
in string s
.Not_found
if c
does not occurr in s
val rindex : t -> c:char -> int
rindex s ~c
returns the index of the last
occurrence of character c
in string s
.Not_found
if c
does not occurr in s
val index_pred : f:(char -> bool) -> t -> int
index_pred ~f s
returns the index of the first char in s
that
satisfies s
.Not_found
if no character in s
satisfies p
val rindex_pred : f:(char -> bool) -> t -> int
rindex_pred ~f s
returns the index of the last char in s
that
satisfies s
.Not_found
if no character in s
satisfies p
val contains : t -> c:char -> bool
String.contains s c
tests if character c
appears in the string s
.val for_all : f:(char -> bool) -> t -> bool
val exists : f:(char -> bool) -> t -> bool
val split : by:char -> t -> t list
split s ~by
splits s
along the occurrences of by
.val split_gen : by:char -> t -> t gen
Bigstring.split
but returns a generatorval lines : t -> t list
lines s
returns a list of the lines of s
(splits along '\n')val lines_gen : t -> t gen
lines_gen s
returns a generator of the lines of s
(splits along '\n')
where every line is a slice of s
val with_map_file : ?pos:int64 ->
?len:int ->
?mode:int ->
?flags:Pervasives.open_flag list ->
?shared:bool -> string -> (t -> 'a) -> 'a
with_map_file name f
maps the file into memory, opening it, and
call f
with a slice pos.... pos+len
of the bytes of the file
where len
is the length of the file if not provided.
When f
returns, the file is closed.pos
: offset in the file (default 0)mode
: the mode for the file, if it's createdflags
: opening flags (default rdonly)
see Bigarray.Array1.map_file
for more detailsshared
: if true, modifications are shared between processes that
have mapped this file (requires the filedescr to be open in write mode).val map_file_descr : ?pos:int64 -> ?shared:bool -> Unix.file_descr -> int -> t
map_file_descr descr len
is a lower-level access to an underlying file descriptor.shared
: if true, modifications are shared between processes that
have mapped this file (requires the filedescr to be open in write mode).
see Bigarray.Array1.map_file
for more details