package base

  1. Overview
  2. No Docs
Full standard library replacement for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.17.3.tar.gz
md5=2100b0ed13fecf43be86ed45c5b2cc4d
sha512=628610caff7e124631870fa1e29661caac28bdfdb18750ee43b868037da3d65d6dd9023b4be7c4c52405679efb5e865a6632d95606a22b28a36636a6bf706ef3

doc/src/base/buffer.ml.html

Source file buffer.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
open! Import
include Buffer_intf
include Stdlib.Buffer

let contents_bytes = to_bytes
let add_substring t s ~pos ~len = add_substring t s pos len
let add_subbytes t s ~pos ~len = add_subbytes t s pos len
let sexp_of_t t = sexp_of_string (contents t)
let caml_buffer_length = (Stdlib.Obj.magic (Stdlib.Buffer.length : t -> int) : t -> int)

let caml_buffer_blit =
  (Stdlib.Obj.magic
     (Stdlib.Buffer.blit : Stdlib.Buffer.t -> int -> Bytes.t -> int -> int -> unit)
    : Stdlib.Buffer.t -> int -> Bytes.t -> int -> int -> unit)
;;

module To_bytes =
  Blit.Make_distinct
    (struct
      type nonrec t = t

      let length = caml_buffer_length
    end)
    (struct
      type t = Bytes.t

      let create ~len = Bytes.create len
      let length = Bytes.length

      let unsafe_blit ~src ~src_pos ~dst ~dst_pos ~len =
        caml_buffer_blit src src_pos dst dst_pos len
      ;;
    end)

include To_bytes
module To_string = Blit.Make_to_string (Stdlib.Buffer) (To_bytes)