.TH "Stdlib.BytesLabels" 3o 2020-10-30 OCamldoc "OCaml library" .SH NAME Stdlib.BytesLabels \- no description .SH Module Module Stdlib.BytesLabels .SH Documentation .sp Module .BI "BytesLabels" : .B (module Stdlib__bytesLabels) .sp .sp .sp .sp .I val length : .B bytes -> int .sp Return the length (number of bytes) of the argument\&. .sp .I val get : .B bytes -> int -> char .sp .ft B get s n .ft R returns the byte at index .ft B n .ft R in argument .ft B s .ft R \&. .sp .B "Raises Invalid_argument" if .ft B n .ft R is not a valid index in .ft B s .ft R \&. .sp .I val set : .B bytes -> int -> char -> unit .sp .ft B set s n c .ft R modifies .ft B s .ft R in place, replacing the byte at index .ft B n .ft R with .ft B c .ft R \&. .sp .B "Raises Invalid_argument" if .ft B n .ft R is not a valid index in .ft B s .ft R \&. .sp .I val create : .B int -> bytes .sp .ft B create n .ft R returns a new byte sequence of length .ft B n .ft R \&. The sequence is uninitialized and contains arbitrary bytes\&. .sp .B "Raises Invalid_argument" if .ft B n < 0 .ft R or .ft B n > .ft R .ft B Sys\&.max_string_length .ft R \&. .sp .I val make : .B int -> char -> bytes .sp .ft B make n c .ft R returns a new byte sequence of length .ft B n .ft R , filled with the byte .ft B c .ft R \&. .sp .B "Raises Invalid_argument" if .ft B n < 0 .ft R or .ft B n > .ft R .ft B Sys\&.max_string_length .ft R \&. .sp .I val init : .B int -> f:(int -> char) -> bytes .sp .ft B init n f .ft R returns a fresh byte sequence of length .ft B n .ft R , with character .ft B i .ft R initialized to the result of .ft B f i .ft R \&. .sp .B "Raises Invalid_argument" if .ft B n < 0 .ft R or .ft B n > .ft R .ft B Sys\&.max_string_length .ft R \&. .sp .I val empty : .B bytes .sp A byte sequence of size 0\&. .sp .I val copy : .B bytes -> bytes .sp Return a new byte sequence that contains the same bytes as the argument\&. .sp .I val of_string : .B string -> bytes .sp Return a new byte sequence that contains the same bytes as the given string\&. .sp .I val to_string : .B bytes -> string .sp Return a new string that contains the same bytes as the given byte sequence\&. .sp .I val sub : .B bytes -> pos:int -> len:int -> bytes .sp .ft B sub s start len .ft R returns a new byte sequence of length .ft B len .ft R , containing the subsequence of .ft B s .ft R that starts at position .ft B start .ft R and has length .ft B len .ft R \&. .sp .B "Raises Invalid_argument" if .ft B start .ft R and .ft B len .ft R do not designate a valid range of .ft B s .ft R \&. .sp .I val sub_string : .B bytes -> pos:int -> len:int -> string .sp Same as .ft B sub .ft R but return a string instead of a byte sequence\&. .sp .I val extend : .B bytes -> left:int -> right:int -> bytes .sp .ft B extend s left right .ft R returns a new byte sequence that contains the bytes of .ft B s .ft R , with .ft B left .ft R uninitialized bytes prepended and .ft B right .ft R uninitialized bytes appended to it\&. If .ft B left .ft R or .ft B right .ft R is negative, then bytes are removed (instead of appended) from the corresponding side of .ft B s .ft R \&. .sp .B "Since" 4.05.0 .sp .B "Raises Invalid_argument" if the result length is negative or longer than .ft B Sys\&.max_string_length .ft R bytes\&. .sp .I val fill : .B bytes -> pos:int -> len:int -> char -> unit .sp .ft B fill s start len c .ft R modifies .ft B s .ft R in place, replacing .ft B len .ft R characters with .ft B c .ft R , starting at .ft B start .ft R \&. .sp .B "Raises Invalid_argument" if .ft B start .ft R and .ft B len .ft R do not designate a valid range of .ft B s .ft R \&. .sp .I val blit : .B src:bytes -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int -> unit .sp .ft B blit src srcoff dst dstoff len .ft R copies .ft B len .ft R bytes from sequence .ft B src .ft R , starting at index .ft B srcoff .ft R , to sequence .ft B dst .ft R , starting at index .ft B dstoff .ft R \&. It works correctly even if .ft B src .ft R and .ft B dst .ft R are the same byte sequence, and the source and destination intervals overlap\&. .sp .B "Raises Invalid_argument" if .ft B srcoff .ft R and .ft B len .ft R do not designate a valid range of .ft B src .ft R , or if .ft B dstoff .ft R and .ft B len .ft R do not designate a valid range of .ft B dst .ft R \&. .sp .I val blit_string : .B src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int -> unit .sp .ft B blit src srcoff dst dstoff len .ft R copies .ft B len .ft R bytes from string .ft B src .ft R , starting at index .ft B srcoff .ft R , to byte sequence .ft B dst .ft R , starting at index .ft B dstoff .ft R \&. .sp .B "Since" 4.05.0 .sp .B "Raises Invalid_argument" if .ft B srcoff .ft R and .ft B len .ft R do not designate a valid range of .ft B src .ft R , or if .ft B dstoff .ft R and .ft B len .ft R do not designate a valid range of .ft B dst .ft R \&. .sp .I val concat : .B sep:bytes -> bytes list -> bytes .sp .ft B concat sep sl .ft R concatenates the list of byte sequences .ft B sl .ft R , inserting the separator byte sequence .ft B sep .ft R between each, and returns the result as a new byte sequence\&. .sp .I val cat : .B bytes -> bytes -> bytes .sp .ft B cat s1 s2 .ft R concatenates .ft B s1 .ft R and .ft B s2 .ft R and returns the result as new byte sequence\&. .sp .B "Since" 4.05.0 .sp .B "Raises Invalid_argument" if the result is longer than .ft B Sys\&.max_string_length .ft R bytes\&. .sp .I val iter : .B f:(char -> unit) -> bytes -> unit .sp .ft B iter f s .ft R applies function .ft B f .ft R in turn to all the bytes of .ft B s .ft R \&. It is equivalent to .ft B f (get s 0); f (get s 1); \&.\&.\&.; f (get s .br \& (length s \- 1)); () .ft R \&. .sp .I val iteri : .B f:(int -> char -> unit) -> bytes -> unit .sp Same as .ft B Bytes\&.iter .ft R , but the function is applied to the index of the byte as first argument and the byte itself as second argument\&. .sp .I val map : .B f:(char -> char) -> bytes -> bytes .sp .ft B map f s .ft R applies function .ft B f .ft R in turn to all the bytes of .ft B s .ft R and stores the resulting bytes in a new sequence that is returned as the result\&. .sp .I val mapi : .B f:(int -> char -> char) -> bytes -> bytes .sp .ft B mapi f s .ft R calls .ft B f .ft R with each character of .ft B s .ft R and its index (in increasing index order) and stores the resulting bytes in a new sequence that is returned as the result\&. .sp .I val trim : .B bytes -> bytes .sp Return a copy of the argument, without leading and trailing whitespace\&. The bytes regarded as whitespace are the ASCII characters .ft B \&' \&' .ft R , .ft B \&'\(rs012\&' .ft R , .ft B \&'\(rsn\&' .ft R , .ft B \&'\(rsr\&' .ft R , and .ft B \&'\(rst\&' .ft R \&. .sp .I val escaped : .B bytes -> bytes .sp Return a copy of the argument, with special characters represented by escape sequences, following the lexical conventions of OCaml\&. .sp .I val index : .B bytes -> char -> int .sp .ft B index s c .ft R returns the index of the first occurrence of byte .ft B c .ft R in .ft B s .ft R \&. .sp .B "Raises Not_found" if .ft B c .ft R does not occur in .ft B s .ft R \&. .sp .I val index_opt : .B bytes -> char -> int option .sp .ft B index_opt s c .ft R returns the index of the first occurrence of byte .ft B c .ft R in .ft B s .ft R or .ft B None .ft R if .ft B c .ft R does not occur in .ft B s .ft R \&. .sp .B "Since" 4.05 .sp .I val rindex : .B bytes -> char -> int .sp .ft B rindex s c .ft R returns the index of the last occurrence of byte .ft B c .ft R in .ft B s .ft R \&. .sp .B "Raises Not_found" if .ft B c .ft R does not occur in .ft B s .ft R \&. .sp .I val rindex_opt : .B bytes -> char -> int option .sp .ft B rindex_opt s c .ft R returns the index of the last occurrence of byte .ft B c .ft R in .ft B s .ft R or .ft B None .ft R if .ft B c .ft R does not occur in .ft B s .ft R \&. .sp .B "Since" 4.05 .sp .I val index_from : .B bytes -> int -> char -> int .sp .ft B index_from s i c .ft R returns the index of the first occurrence of byte .ft B c .ft R in .ft B s .ft R after position .ft B i .ft R \&. .ft B Bytes\&.index s c .ft R is equivalent to .ft B Bytes\&.index_from s 0 c .ft R \&. .sp .B "Raises Invalid_argument" if .ft B i .ft R is not a valid position in .ft B s .ft R \&. .sp .B "Raises Not_found" if .ft B c .ft R does not occur in .ft B s .ft R after position .ft B i .ft R \&. .sp .I val index_from_opt : .B bytes -> int -> char -> int option .sp .ft B index_from _opts i c .ft R returns the index of the first occurrence of byte .ft B c .ft R in .ft B s .ft R after position .ft B i .ft R or .ft B None .ft R if .ft B c .ft R does not occur in .ft B s .ft R after position .ft B i .ft R \&. .ft B Bytes\&.index_opt s c .ft R is equivalent to .ft B Bytes\&.index_from_opt s 0 c .ft R \&. .sp .B "Since" 4.05 .sp .B "Raises Invalid_argument" if .ft B i .ft R is not a valid position in .ft B s .ft R \&. .sp .I val rindex_from : .B bytes -> int -> char -> int .sp .ft B rindex_from s i c .ft R returns the index of the last occurrence of byte .ft B c .ft R in .ft B s .ft R before position .ft B i+1 .ft R \&. .ft B rindex s c .ft R is equivalent to .ft B rindex_from s (Bytes\&.length s \- 1) c .ft R \&. .sp .B "Raises Invalid_argument" if .ft B i+1 .ft R is not a valid position in .ft B s .ft R \&. .sp .B "Raises Not_found" if .ft B c .ft R does not occur in .ft B s .ft R before position .ft B i+1 .ft R \&. .sp .I val rindex_from_opt : .B bytes -> int -> char -> int option .sp .ft B rindex_from_opt s i c .ft R returns the index of the last occurrence of byte .ft B c .ft R in .ft B s .ft R before position .ft B i+1 .ft R or .ft B None .ft R if .ft B c .ft R does not occur in .ft B s .ft R before position .ft B i+1 .ft R \&. .ft B rindex_opt s c .ft R is equivalent to .ft B rindex_from s (Bytes\&.length s \- 1) c .ft R \&. .sp .B "Since" 4.05 .sp .B "Raises Invalid_argument" if .ft B i+1 .ft R is not a valid position in .ft B s .ft R \&. .sp .I val contains : .B bytes -> char -> bool .sp .ft B contains s c .ft R tests if byte .ft B c .ft R appears in .ft B s .ft R \&. .sp .I val contains_from : .B bytes -> int -> char -> bool .sp .ft B contains_from s start c .ft R tests if byte .ft B c .ft R appears in .ft B s .ft R after position .ft B start .ft R \&. .ft B contains s c .ft R is equivalent to .ft B contains_from .br \& s 0 c .ft R \&. .sp .B "Raises Invalid_argument" if .ft B start .ft R is not a valid position in .ft B s .ft R \&. .sp .I val rcontains_from : .B bytes -> int -> char -> bool .sp .ft B rcontains_from s stop c .ft R tests if byte .ft B c .ft R appears in .ft B s .ft R before position .ft B stop+1 .ft R \&. .sp .B "Raises Invalid_argument" if .ft B stop < 0 .ft R or .ft B stop+1 .ft R is not a valid position in .ft B s .ft R \&. .sp .I val uppercase : .B bytes -> bytes .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp 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\&. .sp .I val lowercase : .B bytes -> bytes .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp 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\&. .sp .I val capitalize : .B bytes -> bytes .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp Return a copy of the argument, with the first character set to uppercase, using the ISO Latin\-1 (8859\-1) character set\&.\&. .sp .I val uncapitalize : .B bytes -> bytes .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp Return a copy of the argument, with the first character set to lowercase, using the ISO Latin\-1 (8859\-1) character set\&.\&. .sp .I val uppercase_ascii : .B bytes -> bytes .sp Return a copy of the argument, with all lowercase letters translated to uppercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val lowercase_ascii : .B bytes -> bytes .sp Return a copy of the argument, with all uppercase letters translated to lowercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val capitalize_ascii : .B bytes -> bytes .sp Return a copy of the argument, with the first character set to uppercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val uncapitalize_ascii : .B bytes -> bytes .sp Return a copy of the argument, with the first character set to lowercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I type t = .B bytes .sp An alias for the type of byte sequences\&. .sp .I val compare : .B t -> t -> int .sp The comparison function for byte sequences, with the same specification as .ft B compare .ft R \&. Along with the type .ft B t .ft R , this function .ft B compare .ft R allows the module .ft B Bytes .ft R to be passed as argument to the functors .ft B Set\&.Make .ft R and .ft B Map\&.Make .ft R \&. .sp .I val equal : .B t -> t -> bool .sp The equality function for byte sequences\&. .sp .B "Since" 4.05.0 .sp .PP .SS Iterators .PP .I val to_seq : .B t -> char Seq.t .sp Iterate on the string, in increasing index order\&. Modifications of the string during iteration will be reflected in the iterator\&. .sp .B "Since" 4.07 .sp .I val to_seqi : .B t -> (int * char) Seq.t .sp Iterate on the string, in increasing order, yielding indices along chars .sp .B "Since" 4.07 .sp .I val of_seq : .B char Seq.t -> t .sp Create a string from the generator .sp .B "Since" 4.07 .sp .PP .SS Binary encoding/decoding of integers .PP .PP The functions in this section binary encode and decode integers to and from byte sequences\&. .sp All following functions raise .ft B Invalid_argument .ft R if the space needed at index .ft B i .ft R to decode or encode the integer is not available\&. .sp Little\-endian (resp\&. big\-endian) encoding means that least (resp\&. most) significant bytes are stored first\&. Big\-endian is also known as network byte order\&. Native\-endian encoding is either little\-endian or big\-endian depending on .ft B Sys\&.big_endian .ft R \&. .sp 32\-bit and 64\-bit integers are represented by the .ft B int32 .ft R and .ft B int64 .ft R types, which can be interpreted either as signed or unsigned numbers\&. .sp 8\-bit and 16\-bit integers are represented by the .ft B int .ft R type, which has more bits than the binary encoding\&. These extra bits are handled as follows: .sp \-Functions that decode signed (resp\&. unsigned) 8\-bit or 16\-bit integers represented by .ft B int .ft R values sign\-extend (resp\&. zero\-extend) their result\&. .sp \-Functions that encode 8\-bit or 16\-bit integers represented by .ft B int .ft R values truncate their input to their least significant bytes\&. .PP .I val get_uint8 : .B bytes -> int -> int .sp .ft B get_uint8 b i .ft R is .ft B b .ft R \&'s unsigned 8\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int8 : .B bytes -> int -> int .sp .ft B get_int8 b i .ft R is .ft B b .ft R \&'s signed 8\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_uint16_ne : .B bytes -> int -> int .sp .ft B get_uint16_ne b i .ft R is .ft B b .ft R \&'s native\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_uint16_be : .B bytes -> int -> int .sp .ft B get_uint16_be b i .ft R is .ft B b .ft R \&'s big\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_uint16_le : .B bytes -> int -> int .sp .ft B get_uint16_le b i .ft R is .ft B b .ft R \&'s little\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int16_ne : .B bytes -> int -> int .sp .ft B get_int16_ne b i .ft R is .ft B b .ft R \&'s native\-endian signed 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int16_be : .B bytes -> int -> int .sp .ft B get_int16_be b i .ft R is .ft B b .ft R \&'s big\-endian signed 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int16_le : .B bytes -> int -> int .sp .ft B get_int16_le b i .ft R is .ft B b .ft R \&'s little\-endian signed 16\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int32_ne : .B bytes -> int -> int32 .sp .ft B get_int32_ne b i .ft R is .ft B b .ft R \&'s native\-endian 32\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int32_be : .B bytes -> int -> int32 .sp .ft B get_int32_be b i .ft R is .ft B b .ft R \&'s big\-endian 32\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int32_le : .B bytes -> int -> int32 .sp .ft B get_int32_le b i .ft R is .ft B b .ft R \&'s little\-endian 32\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int64_ne : .B bytes -> int -> int64 .sp .ft B get_int64_ne b i .ft R is .ft B b .ft R \&'s native\-endian 64\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int64_be : .B bytes -> int -> int64 .sp .ft B get_int64_be b i .ft R is .ft B b .ft R \&'s big\-endian 64\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val get_int64_le : .B bytes -> int -> int64 .sp .ft B get_int64_le b i .ft R is .ft B b .ft R \&'s little\-endian 64\-bit integer starting at byte index .ft B i .ft R \&. .sp .B "Since" 4.08 .sp .I val set_uint8 : .B bytes -> int -> int -> unit .sp .ft B set_uint8 b i v .ft R sets .ft B b .ft R \&'s unsigned 8\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int8 : .B bytes -> int -> int -> unit .sp .ft B set_int8 b i v .ft R sets .ft B b .ft R \&'s signed 8\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_uint16_ne : .B bytes -> int -> int -> unit .sp .ft B set_uint16_ne b i v .ft R sets .ft B b .ft R \&'s native\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_uint16_be : .B bytes -> int -> int -> unit .sp .ft B set_uint16_be b i v .ft R sets .ft B b .ft R \&'s big\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_uint16_le : .B bytes -> int -> int -> unit .sp .ft B set_uint16_le b i v .ft R sets .ft B b .ft R \&'s little\-endian unsigned 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int16_ne : .B bytes -> int -> int -> unit .sp .ft B set_int16_ne b i v .ft R sets .ft B b .ft R \&'s native\-endian signed 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int16_be : .B bytes -> int -> int -> unit .sp .ft B set_int16_be b i v .ft R sets .ft B b .ft R \&'s big\-endian signed 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int16_le : .B bytes -> int -> int -> unit .sp .ft B set_int16_le b i v .ft R sets .ft B b .ft R \&'s little\-endian signed 16\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int32_ne : .B bytes -> int -> int32 -> unit .sp .ft B set_int32_ne b i v .ft R sets .ft B b .ft R \&'s native\-endian 32\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int32_be : .B bytes -> int -> int32 -> unit .sp .ft B set_int32_be b i v .ft R sets .ft B b .ft R \&'s big\-endian 32\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int32_le : .B bytes -> int -> int32 -> unit .sp .ft B set_int32_le b i v .ft R sets .ft B b .ft R \&'s little\-endian 32\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int64_ne : .B bytes -> int -> int64 -> unit .sp .ft B set_int64_ne b i v .ft R sets .ft B b .ft R \&'s native\-endian 64\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int64_be : .B bytes -> int -> int64 -> unit .sp .ft B set_int64_be b i v .ft R sets .ft B b .ft R \&'s big\-endian 64\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp .I val set_int64_le : .B bytes -> int -> int64 -> unit .sp .ft B set_int64_le b i v .ft R sets .ft B b .ft R \&'s little\-endian 64\-bit integer starting at byte index .ft B i .ft R to .ft B v .ft R \&. .sp .B "Since" 4.08 .sp