Library
Module
Module type
Parameter
Class
Class type
A read-only bigstring.
type t = private bigstring
val empty : t
empty
is an empty bigstring.
val length : t -> int
length bstr
is the number of bytes in bstr
.
val get : t -> int -> char
get bstr i
is the byte of bstr
' at index i
. This is equivalent to the bstr.{i}
notation.
val get_int8 : t -> int -> int
get_int8 bstr i
is bstr
's signed 8-bit integer starting at byte index i
.
val get_uint8 : t -> int -> int
get_uint8 bstr i
is bstr
's unsigned 8-bit integer starting at byte index i
.
val get_uint16_ne : t -> int -> int
get_int16_ne bstr i
is bstr
's native-endian unsigned 16-bit integer starting at byte index i
.
val get_uint16_le : t -> int -> int
get_int16_le bstr i
is bstr
's little-endian unsigned 16-bit integer starting at byte index i
.
val get_uint16_be : t -> int -> int
get_int16_be bstr i
is bstr
's big-endian unsigned 16-bit integer starting at byte index i
.
val get_int16_ne : t -> int -> int
get_int16_ne bstr i
is bstr
's native-endian signed 16-bit integer starting at byte index i
.
val get_int16_le : t -> int -> int
get_int16_le bstr i
is bstr
's little-endian signed 16-bit integer starting at byte index i
.
val get_int16_be : t -> int -> int
get_int16_be bstr i
is bstr
's big-endian signed 16-bit integer starting at byte index i
.
val get_int32_ne : t -> int -> int32
get_int32_ne bstr i
is bstr
's native-endian 32-bit integer starting at byte index i
.
val get_int32_le : t -> int -> int32
get_int32_le bstr i
is bstr
's little-endian 32-bit integer starting at byte index i
.
val get_int32_be : t -> int -> int32
get_int32_be bstr i
is bstr
's big-endian 32-bit integer starting at byte index i
.
val get_int64_ne : t -> int -> int64
get_int64_ne bstr i
is bstr
's native-endian 64-bit integer starting at byte index i
.
val get_int64_le : t -> int -> int64
get_int64_le bstr i
is bstr
's little-endian 64-bit integer starting at byte index i
.
val get_int64_be : t -> int -> int64
get_int64_be bstr i
is bstr
's big-endian 64-bit integer starting at byte index i
.
sub bstr ~off ~len
does not allocate a bigstring, but instead returns a new view into bstr
starting at off
, and with length len
.
Note that this does not allocate a new buffer, but instead shares the buffer of bstr
with the newly-returned bigstring.
val sub_string : t -> off:int -> len:int -> string
sub_string bstr ~off ~len
returns a string of length len
containing the bytes of t
starting at off
.
val to_string : t -> string
to_string bstr
is equivalent to sub_string bstr ~off:0 ~len:(length bstr)
.
val blit_to_bytes : t -> src_off:int -> bytes -> dst_off:int -> len:int -> unit
blit_to_bytes src ~src_off dst ~dst_off ~len
copies len
bytes from src
, starting at index src_off
, to byte sequence dst
, starting at index dst_off
.
val is_empty : t -> bool
is_empty bstr
is length bstr = 0
.
val is_prefix : affix:string -> t -> bool
is_prefix ~affix bstr
is true
iff affix.[idx] = bstr.{idx}
for all indices idx
of affix
.
val is_infix : affix:string -> t -> bool
is_infix ~affix bstr
is true
iff there exists an index j
in bstr
such that for all indices i
of affix
we have affix.[i] = bstr.{j + i}
.
val is_suffix : affix:string -> t -> bool
is_suffix ~affix bstr
is true
iff affix.[n - idx] = bstr.{m - idx}
for all indices idx
of affix
with n = String.length affix - 1
and m = length bstr - 1
.
val for_all : (char -> bool) -> t -> bool
for_all p bstr
is true
iff for all indices idx
of bstr
, p bstr.{idx} = true
.
val exists : (char -> bool) -> t -> bool
exists p bstr
is true
iff there exists an index idx
of bstr
with p bstr.{idx} = true
.
with_range ~first ~len bstr
are the consecutive bytes of bstr
whose indices exist in the range [first
;first + len - 1
].
first
defaults to 0
and len
to max_int
. Note that first
can be any integer and len
any positive integer.
with_index_range ~first ~last bstr
are the consecutive bytes of bstr
whose indices exists in the range [first
;last
].
first
defaults to 0
and last
to length bstr - 1
.
Note that both first
and last
can be any integer. If first > last
the interval is empty and the empty bigstring is returned.
trim ~drop bstr
is bstr
with prefix and suffix bytes satisfying drop
in bstr
removed. drop
defaults to fun chr -> chr = ' '
.
span ~rev ~min ~max ~sat bstr
is (l, r)
where:
rev
is false
(default), l
is at least min
and at most max
consecutive sat
satisfying initial bytes of bstr
or empty
if there are no such bytes. r
are the remaining bytes of bstr
.rev
is true
, r
is at least min
and at most max
consecutive sat
satisfying final bytes of bstr
or empty
if there are no such bytes. l
are the remaining bytes of bstr
.If max
is unspecified the span is unlimited. If min
is unspecified it defaults to 0
. If min > max
the condition can't be satisfied and the left or right span, depending on rev
, is always empty. sat
defaults to Fun.const true
.
take ~rev ~min ~max ~sat bstr
is the matching span of span
without the remaining one. In other words:
(if rev then snd else fst) @@ span ~rev ~min ~max ~sat bstr