mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-05-06 17:34:23 -04:00
byte_slice: add clear and of_string
This commit is contained in:
parent
c02c76eb0b
commit
749f973528
2 changed files with 12 additions and 0 deletions
|
|
@ -21,6 +21,12 @@ let create ?(off = 0) ?len bs =
|
|||
let[@inline] unsafe_of_string ?off ?len s =
|
||||
create ?off ?len (Bytes.unsafe_of_string s)
|
||||
|
||||
let[@inline] of_string s = create (Bytes.of_string s)
|
||||
|
||||
let[@inline] clear self =
|
||||
self.off <- 0;
|
||||
self.len <- 0
|
||||
|
||||
let[@inline] len self = self.len
|
||||
let[@inline] contents self = Bytes.sub_string self.bs self.off self.len
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ val unsafe_of_string : ?off:int -> ?len:int -> string -> t
|
|||
This is unsafe because mutating the bytes is forbidden
|
||||
(just like with {!Bytes.unsafe_of_string} *)
|
||||
|
||||
val of_string : string -> t
|
||||
(** [of_string s] makes a slice from a copy of [s]. Safe to mutate. *)
|
||||
|
||||
val clear : t -> unit
|
||||
(** [clear sl] resets [off] and [len] to 0. *)
|
||||
|
||||
val len : t -> int
|
||||
(** Access the length *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue