Module Base__Import.BytesLabels
Byte sequence operations.
- since
- 4.02.0
val get : bytes -> int -> char
get s n
returns the byte at indexn
in arguments
.Raise
Invalid_argument
ifn
is not a valid index ins
.
val set : bytes -> int -> char -> unit
set s n c
modifiess
in place, replacing the byte at indexn
withc
.Raise
Invalid_argument
ifn
is not a valid index ins
.
val create : int -> bytes
create n
returns a new byte sequence of lengthn
. The sequence is uninitialized and contains arbitrary bytes.Raise
Invalid_argument
ifn < 0
orn >
Sys
.max_string_length.
val make : int -> char -> bytes
make n c
returns a new byte sequence of lengthn
, filled with the bytec
.Raise
Invalid_argument
ifn < 0
orn >
Sys
.max_string_length.
val init : int -> f:(int -> char) -> bytes
init n f
returns a fresh byte sequence of lengthn
, with characteri
initialized to the result off i
.Raise
Invalid_argument
ifn < 0
orn >
Sys
.max_string_length.
val of_string : string -> bytes
Return a new byte sequence that contains the same bytes as the given string.
val to_string : bytes -> string
Return a new string that contains the same bytes as the given byte sequence.
val sub : bytes -> pos:int -> len:int -> bytes
sub s start len
returns a new byte sequence of lengthlen
, containing the subsequence ofs
that starts at positionstart
and has lengthlen
.Raise
Invalid_argument
ifstart
andlen
do not designate a valid range ofs
.
val sub_string : bytes -> pos:int -> len:int -> string
Same as
sub
but return a string instead of a byte sequence.
val extend : bytes -> left:int -> right:int -> bytes
extend s left right
returns a new byte sequence that contains the bytes ofs
, withleft
uninitialized bytes prepended andright
uninitialized bytes appended to it. Ifleft
orright
is negative, then bytes are removed (instead of appended) from the corresponding side ofs
.Raise
Invalid_argument
if the result length is negative or longer thanSys
.max_string_length bytes.- since
- 4.05.0
val fill : bytes -> pos:int -> len:int -> char -> unit
fill s start len c
modifiess
in place, replacinglen
characters withc
, starting atstart
.Raise
Invalid_argument
ifstart
andlen
do not designate a valid range ofs
.
val blit : src:bytes -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int -> unit
blit src srcoff dst dstoff len
copieslen
bytes from sequencesrc
, starting at indexsrcoff
, to sequencedst
, starting at indexdstoff
. It works correctly even ifsrc
anddst
are the same byte sequence, and the source and destination intervals overlap.Raise
Invalid_argument
ifsrcoff
andlen
do not designate a valid range ofsrc
, or ifdstoff
andlen
do not designate a valid range ofdst
.
val blit_string : src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int -> unit
blit src srcoff dst dstoff len
copieslen
bytes from stringsrc
, starting at indexsrcoff
, to byte sequencedst
, starting at indexdstoff
.Raise
Invalid_argument
ifsrcoff
andlen
do not designate a valid range ofsrc
, or ifdstoff
andlen
do not designate a valid range ofdst
.- since
- 4.05.0
val concat : sep:bytes -> bytes list -> bytes
concat sep sl
concatenates the list of byte sequencessl
, inserting the separator byte sequencesep
between each, and returns the result as a new byte sequence.
val cat : bytes -> bytes -> bytes
cat s1 s2
concatenatess1
ands2
and returns the result as new byte sequence.Raise
Invalid_argument
if the result is longer thanSys
.max_string_length bytes.- since
- 4.05.0
val iter : f:(char -> unit) -> bytes -> unit
iter f s
applies functionf
in turn to all the bytes ofs
. It is equivalent tof (get s 0); f (get s 1); ...; f (get s (length s - 1)); ()
.
val iteri : f:(int -> char -> unit) -> bytes -> unit
Same as
Bytes
.iter, but the function is applied to the index of the byte as first argument and the byte itself as second argument.
val map : f:(char -> char) -> bytes -> bytes
map f s
applies functionf
in turn to all the bytes ofs
and stores the resulting bytes in a new sequence that is returned as the result.
val mapi : f:(int -> char -> char) -> bytes -> bytes
mapi f s
callsf
with each character ofs
and its index (in increasing index order) and stores the resulting bytes in a new sequence that is returned as the result.
val trim : bytes -> bytes
Return a copy of the argument, without leading and trailing whitespace. The bytes regarded as whitespace are the ASCII characters
' '
,'\012'
,'\n'
,'\r'
, and'\t'
.
val escaped : bytes -> bytes
Return a copy of the argument, with special characters represented by escape sequences, following the lexical conventions of OCaml.
val index : bytes -> char -> int
index s c
returns the index of the first occurrence of bytec
ins
.Raise
Not_found
ifc
does not occur ins
.
val index_opt : bytes -> char -> int option
index_opt s c
returns the index of the first occurrence of bytec
ins
orNone
ifc
does not occur ins
.- since
- 4.05
val rindex : bytes -> char -> int
rindex s c
returns the index of the last occurrence of bytec
ins
.Raise
Not_found
ifc
does not occur ins
.
val rindex_opt : bytes -> char -> int option
rindex_opt s c
returns the index of the last occurrence of bytec
ins
orNone
ifc
does not occur ins
.- since
- 4.05
val index_from : bytes -> int -> char -> int
index_from s i c
returns the index of the first occurrence of bytec
ins
after positioni
.Bytes.index s c
is equivalent toBytes.index_from s 0 c
.Raise
Invalid_argument
ifi
is not a valid position ins
. RaiseNot_found
ifc
does not occur ins
after positioni
.
val index_from_opt : bytes -> int -> char -> int option
index_from _opts i c
returns the index of the first occurrence of bytec
ins
after positioni
orNone
ifc
does not occur ins
after positioni
.Bytes.index_opt s c
is equivalent toBytes.index_from_opt s 0 c
.Raise
Invalid_argument
ifi
is not a valid position ins
.- since
- 4.05
val rindex_from : bytes -> int -> char -> int
rindex_from s i c
returns the index of the last occurrence of bytec
ins
before positioni+1
.rindex s c
is equivalent torindex_from s (Bytes.length s - 1) c
.Raise
Invalid_argument
ifi+1
is not a valid position ins
. RaiseNot_found
ifc
does not occur ins
before positioni+1
.
val rindex_from_opt : bytes -> int -> char -> int option
rindex_from_opt s i c
returns the index of the last occurrence of bytec
ins
before positioni+1
orNone
ifc
does not occur ins
before positioni+1
.rindex_opt s c
is equivalent torindex_from s (Bytes.length s - 1) c
.Raise
Invalid_argument
ifi+1
is not a valid position ins
.- since
- 4.05
val contains_from : bytes -> int -> char -> bool
contains_from s start c
tests if bytec
appears ins
after positionstart
.contains s c
is equivalent tocontains_from s 0 c
.Raise
Invalid_argument
ifstart
is not a valid position ins
.
val rcontains_from : bytes -> int -> char -> bool
rcontains_from s stop c
tests if bytec
appears ins
before positionstop+1
.Raise
Invalid_argument
ifstop < 0
orstop+1
is not a valid position ins
.
val uppercase : bytes -> bytes
Return a copy of the argument, with all lowercase letters translated to uppercase, including accented letters of the ISO Latin-1 (8859-1) character set.
- deprecated
Functions operating on Latin-1 character set are deprecated.
val lowercase : bytes -> bytes
Return a copy of the argument, with all uppercase letters translated to lowercase, including accented letters of the ISO Latin-1 (8859-1) character set.
- deprecated
Functions operating on Latin-1 character set are deprecated.
val capitalize : bytes -> bytes
Return a copy of the argument, with the first character set to uppercase, using the ISO Latin-1 (8859-1) character set..
- deprecated
Functions operating on Latin-1 character set are deprecated.
val uncapitalize : bytes -> bytes
Return a copy of the argument, with the first character set to lowercase, using the ISO Latin-1 (8859-1) character set..
- deprecated
Functions operating on Latin-1 character set are deprecated.
val uppercase_ascii : bytes -> bytes
Return a copy of the argument, with all lowercase letters translated to uppercase, using the US-ASCII character set.
- since
- 4.05.0
val lowercase_ascii : bytes -> bytes
Return a copy of the argument, with all uppercase letters translated to lowercase, using the US-ASCII character set.
- since
- 4.05.0
val capitalize_ascii : bytes -> bytes
Return a copy of the argument, with the first character set to uppercase, using the US-ASCII character set.
- since
- 4.05.0
val uncapitalize_ascii : bytes -> bytes
Return a copy of the argument, with the first character set to lowercase, using the US-ASCII character set.
- since
- 4.05.0
val compare : t -> t -> int
The comparison function for byte sequences, with the same specification as
Stdlib.compare
. Along with the typet
, this functioncompare
allows the moduleBytes
to be passed as argument to the functorsSet
.Make andMap
.Make.
Iterators
val to_seq : t -> char Seq.t
Iterate on the string, in increasing index order. Modifications of the string during iteration will be reflected in the iterator.
- since
- 4.07
Binary encoding/decoding of integers
val get_uint8 : bytes -> int -> int
get_uint8 b i
isb
's unsigned 8-bit integer starting at byte indexi
.- since
- 4.08
val get_int8 : bytes -> int -> int
get_int8 b i
isb
's signed 8-bit integer starting at byte indexi
.- since
- 4.08
val get_uint16_ne : bytes -> int -> int
get_uint16_ne b i
isb
's native-endian unsigned 16-bit integer starting at byte indexi
.- since
- 4.08
val get_uint16_be : bytes -> int -> int
get_uint16_be b i
isb
's big-endian unsigned 16-bit integer starting at byte indexi
.- since
- 4.08
val get_uint16_le : bytes -> int -> int
get_uint16_le b i
isb
's little-endian unsigned 16-bit integer starting at byte indexi
.- since
- 4.08
val get_int16_ne : bytes -> int -> int
get_int16_ne b i
isb
's native-endian signed 16-bit integer starting at byte indexi
.- since
- 4.08
val get_int16_be : bytes -> int -> int
get_int16_be b i
isb
's big-endian signed 16-bit integer starting at byte indexi
.- since
- 4.08
val get_int16_le : bytes -> int -> int
get_int16_le b i
isb
's little-endian signed 16-bit integer starting at byte indexi
.- since
- 4.08
val get_int32_ne : bytes -> int -> int32
get_int32_ne b i
isb
's native-endian 32-bit integer starting at byte indexi
.- since
- 4.08
val get_int32_be : bytes -> int -> int32
get_int32_be b i
isb
's big-endian 32-bit integer starting at byte indexi
.- since
- 4.08
val get_int32_le : bytes -> int -> int32
get_int32_le b i
isb
's little-endian 32-bit integer starting at byte indexi
.- since
- 4.08
val get_int64_ne : bytes -> int -> int64
get_int64_ne b i
isb
's native-endian 64-bit integer starting at byte indexi
.- since
- 4.08
val get_int64_be : bytes -> int -> int64
get_int64_be b i
isb
's big-endian 64-bit integer starting at byte indexi
.- since
- 4.08
val get_int64_le : bytes -> int -> int64
get_int64_le b i
isb
's little-endian 64-bit integer starting at byte indexi
.- since
- 4.08
val set_uint8 : bytes -> int -> int -> unit
set_uint8 b i v
setsb
's unsigned 8-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int8 : bytes -> int -> int -> unit
set_int8 b i v
setsb
's signed 8-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_uint16_ne : bytes -> int -> int -> unit
set_uint16_ne b i v
setsb
's native-endian unsigned 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_uint16_be : bytes -> int -> int -> unit
set_uint16_be b i v
setsb
's big-endian unsigned 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_uint16_le : bytes -> int -> int -> unit
set_uint16_le b i v
setsb
's little-endian unsigned 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int16_ne : bytes -> int -> int -> unit
set_int16_ne b i v
setsb
's native-endian signed 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int16_be : bytes -> int -> int -> unit
set_int16_be b i v
setsb
's big-endian signed 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int16_le : bytes -> int -> int -> unit
set_int16_le b i v
setsb
's little-endian signed 16-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int32_ne : bytes -> int -> int32 -> unit
set_int32_ne b i v
setsb
's native-endian 32-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int32_be : bytes -> int -> int32 -> unit
set_int32_be b i v
setsb
's big-endian 32-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int32_le : bytes -> int -> int32 -> unit
set_int32_le b i v
setsb
's little-endian 32-bit integer starting at byte indexi
tov
.- since
- 4.08
val set_int64_ne : bytes -> int -> int64 -> unit
set_int64_ne b i v
setsb
's native-endian 64-bit integer starting at byte indexi
tov
.- since
- 4.08