package slice

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Slice_bytesSource

Slices on bytes.

This module implements Slice.S: it offers exactly the same API as Slice_bstr (and mirrors Bstr), so that the same code can be used regardless of the underlying byte sequence.

Unlike Bytes.sub, sub and shift do not copy: they share the underlying bytes with the given slice.

include Slice.S with type buf = bytes
Sourcetype buf = bytes
Sourcetype nonrec t = buf Slice.t
include Slice.R with type buf := buf and type t := t
Sourceval create : int -> t

create len is a fresh t of length len. Its contents are reset to zero (bytes are set to '\000').

Sourceval make : ?off:int -> ?len:int -> buf -> t

make ~off ~len buf is the view of buf which starts at off (defaults to 0) and which is len bytes long (defaults to length buf - off). The buffer is not copied.

Sourceval init : int -> (int -> char) -> t

init len fn is t of length len with index idx holding the character fn idx (called in increasing index order).

Sourceval empty : t

An empty t.

Sourceval length : t -> int

length t is the length (number of bytes/characters) of t.

Sourceval is_empty : t -> bool

is_empty t is length t = 0.

Sourceval chop : ?rev:bool -> t -> char option

chop t is Some (get t idx) with idx = 0 if rev = false (default) or idx = length t - 1 if rev = true. None is returned if t is empty.

Sourceval hash : t -> int
Sourceval equal : t -> t -> bool
Sourceval constant_equal : t -> t -> bool
Sourceval compare : t -> t -> int
Sourceval get : t -> int -> char

get t i is the byte of t at index i.

Bounds are the ones of the slice, not the ones of the underlying buffer: a slice never gives access to a byte which is outside of its own range.

Sourceval unsafe_get : t -> int -> char

unsafe_get t i is get without any bound checking.

Sourceval get_int8 : t -> int -> int

get_int8 bstr i is bstr's signed 8-bit integer starting at byte index i.

Sourceval get_uint8 : t -> int -> int

get_uint8 bstr i is bstr's unsigned 8-bit integer starting at byte index i.

Sourceval get_uint16_ne : t -> int -> int

get_uint16_ne slice i is slice's native-endian unsigned 16-bit integer starting at byte index i.

Sourceval get_uint16_le : t -> int -> int

get_uint16_le slice i is slice's little-endian unsigned 16-bit integer starting at byte index i.

Sourceval get_uint16_be : t -> int -> int

get_uint16_be slice i is slice's big-endian unsigned 16-bit integer starting at byte index i.

Sourceval get_int16_ne : t -> int -> int

get_int16_ne slice i is slice's native-endian signed 16-bit integer starting at byte index i.

Sourceval get_int16_le : t -> int -> int

get_int16_le slice i is slice's little-endian signed 16-bit integer starting at byte index i.

Sourceval get_int16_be : t -> int -> int

get_int16_be slice i is slice's big-endian signed 16-bit integer starting at byte index i.

Sourceval get_int32_ne : t -> int -> int32

get_int32_ne slice i is slice's native-endian 32-bit integer starting at byte index i.

Sourceval get_int32_le : t -> int -> int32

get_int32_le slice i is slice's little-endian 32-bit integer starting at byte index i.

Sourceval get_int32_be : t -> int -> int32

get_int32_be slice i is slice's big-endian 32-bit integer starting at byte index i.

Sourceval get_int64_ne : t -> int -> int64

get_int64_ne slice i is slice's native-endian 64-bit integer starting at byte index i.

Sourceval get_int64_le : t -> int -> int64

get_int64_le slice i is slice's little-endian 64-bit integer starting at byte index i.

Sourceval get_int64_be : t -> int -> int64

get_int64_be slice i is slice's big-endian 64-bit integer starting at byte index i.

Sourceval filter : (char -> bool) -> t -> t

filter sat slice is a fresh slice made of the bytes of slice that satisfy sat, in the same order.

Sourceval filter_map : (char -> char option) -> t -> t

filter_map fn t is a fresh slice made of the bytes of t as mapped by fn, in the same order.

Sourceval map : (char -> char) -> t -> t
Sourceval mapi : (int -> char -> char) -> t -> t
Sourceval fold_left : ('a -> char -> 'a) -> 'a -> t -> 'a
Sourceval fold_right : (char -> 'a -> 'a) -> t -> 'a -> 'a
Sourceval iter : (char -> unit) -> t -> unit
Sourceval iteri : (int -> char -> unit) -> t -> unit
Sourceval hex : t -> string
Sourceval overlap : t -> t -> (int * int * int) option
Sourceval append : t -> t -> t
Sourceval starts_with : prefix:string -> t -> bool
Sourceval is_prefix : affix:string -> t -> bool

is_prefix ~affix slice is true iff affix.[idx] = get slice idx for all indices idx of affix.

Sourceval ends_with : suffix:string -> t -> bool
Sourceval is_suffix : affix:string -> t -> bool

is_suffix ~affix slice is true iff affix.[n - idx] = get slice (m - idx) for all indices idx of affix with n = String.length affix - 1 and m = length slice - 1.

Sourceval is_infix : affix:string -> t -> bool

is_infix ~affix slice is true iff there exists an index j in slice such that for all indices i of affix we have affix.[i] = get t (j + i).

Sourceval for_all : (char -> bool) -> t -> bool
Sourceval exists : (char -> bool) -> t -> bool
Sourceval trim : ?drop:(char -> bool) -> t -> t
Sourceval span : ?rev:bool -> ?min:int -> ?max:int -> ?sat:(char -> bool) -> t -> t * t
Sourceval take : ?rev:bool -> ?min:int -> ?max:int -> ?sat:(char -> bool) -> t -> t
Sourceval drop : ?rev:bool -> ?min:int -> ?max:int -> ?sat:(char -> bool) -> t -> t
Sourceval shift : t -> int -> t
Sourceval sub : t -> off:int -> len:int -> t
Sourceval split_on_char : char -> t -> t list
Sourceval cut : ?rev:bool -> sep:string -> t -> (t * t) option
Sourceval cuts : ?rev:bool -> ?empty:bool -> sep:string -> t -> t list
Sourceval index : t -> ?off:int -> ?len:int -> char -> int option
Sourceval contains : t -> ?off:int -> ?len:int -> char -> bool
Sourceval concat : string -> t list -> t
Sourceval extend : t -> int -> int -> t
Sourceval copy : t -> t
Sourceval sub_string : t -> off:int -> len:int -> string
Sourceval to_string : t -> string
Sourceval of_string : string -> t
Sourceval string : ?off:int -> ?len:int -> string -> t
Sourceval blit_to_bytes : t -> ?src_off:int -> bytes -> dst_off:int -> len:int -> unit
Sourceval with_range : ?first:int -> ?len:int -> t -> t
Sourceval with_index_range : ?first:int -> ?last:int -> t -> t
Sourceval to_seq : t -> char Seq.t
Sourceval to_seqi : t -> (int * char) Seq.t
Sourceval of_seq : char Seq.t -> t
include Slice.W with type t := t
Sourceval set : t -> int -> char -> unit
Sourceval unsafe_set : t -> int -> char -> unit
Sourceval set_int8 : t -> int -> int -> unit
Sourceval set_uint8 : t -> int -> int -> unit
Sourceval set_uint16_ne : t -> int -> int -> unit
Sourceval set_uint16_le : t -> int -> int -> unit
Sourceval set_uint16_be : t -> int -> int -> unit
Sourceval set_int16_ne : t -> int -> int -> unit
Sourceval set_int16_le : t -> int -> int -> unit
Sourceval set_int16_be : t -> int -> int -> unit
Sourceval set_int32_ne : t -> int -> int32 -> unit
Sourceval set_int32_le : t -> int -> int32 -> unit
Sourceval set_int32_be : t -> int -> int32 -> unit
Sourceval set_int64_ne : t -> int -> int64 -> unit
Sourceval set_int64_le : t -> int -> int64 -> unit
Sourceval set_int64_be : t -> int -> int64 -> unit
Sourceval fill : t -> ?off:int -> ?len:int -> char -> unit
Sourceval blit : t -> t -> unit
Sourceval blit_from_bytes : bytes -> src_off:int -> t -> ?dst_off:int -> int -> unit
Sourceval blit_from_string : string -> src_off:int -> t -> ?dst_off:int -> int -> unit