package slice
A Slice type for bigstrings and bytes
Install
Dune Dependency
Authors
Maintainers
Sources
bstr-0.0.1.tbz
sha256=05701fb60e9f9b419cc2d3989cf58c60eba1b5e7a5d08fba7f9d92f29ea3a46e
sha512=2199910457d8dedeefe3ffa3e4ef7a4f0845bb66459bcf3951d6197ec5f32a0c49c29874341d7fc4ee026c82a95a0c8aaaea084840b10530f6c00a6120960174
doc/src/slice.bstr/slice_bstr.ml.html
Source file slice_bstr.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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
(* * Copyright (c) 2024 Romain Calascibetta <romain.calascibetta@gmail.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESBstr. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) type t = Bstr.t Slice.t external ( < ) : 'a -> 'a -> bool = "%lessthan" external ( <= ) : 'a -> 'a -> bool = "%lessequal" external ( >= ) : 'a -> 'a -> bool = "%greaterequal" external ( > ) : 'a -> 'a -> bool = "%greaterthan" let ( > ) (x : int) y = x > y [@@inline] let ( < ) (x : int) y = x < y [@@inline] let ( <= ) (x : int) y = x <= y [@@inline] let ( >= ) (x : int) y = x >= y [@@inline] let min (a : int) b = if a <= b then a else b [@@inline] let max (a : int) b = if a >= b then a else b [@@inline] open Slice let make ?(off= 0) ?len buf = let len = match len with | Some len -> len | None -> Bstr.length buf - off in if len < 0 || off < 0 || off > Bstr.length buf - len then invalid_arg "Slice.make"; Slice.unsafe_make ~off ~len buf let empty = unsafe_make ~off:0 ~len:0 Bstr.empty let length { len; _ } = len let get { off; buf; _ } idx = Bstr.get buf (off + idx) let get_int8 { off; buf; _ } idx = Bstr.get_int8 buf (off + idx) let get_uint8 { off; buf; _ } idx = Bstr.get_uint8 buf (off + idx) let get_uint16_ne { off; buf; _ } idx = Bstr.get_uint16_ne buf (off + idx) let get_uint16_le { off; buf; _ } idx = Bstr.get_uint16_le buf (off + idx) let get_uint16_be { off; buf; _ } idx = Bstr.get_uint16_be buf (off + idx) let get_int16_ne { off; buf; _ } idx = Bstr.get_int16_ne buf (off + idx) let get_int16_le { off; buf; _ } idx = Bstr.get_int16_ne buf (off + idx) let get_int16_be { off; buf; _ } idx = Bstr.get_int16_be buf (off + idx) let get_int32_ne { off; buf; _ } idx = Bstr.get_int32_ne buf (off + idx) let get_int32_le { off; buf; _ } idx = Bstr.get_int32_le buf (off + idx) let get_int32_be { off; buf; _ } idx = Bstr.get_int32_be buf (off + idx) let get_int64_ne { off; buf; _ } idx = Bstr.get_int64_ne buf (off + idx) let get_int64_le { off; buf; _ } idx = Bstr.get_int64_le buf (off + idx) let get_int64_be { off; buf; _ } idx = Bstr.get_int64_be buf (off + idx) let set { off; buf; _ } idx v = Bstr.set buf (off + idx) v let set_int8 { off; buf; _ } idx v = Bstr.set_int8 buf (off + idx) v let set_uint8 { off; buf; _ } idx v = Bstr.set_uint8 buf (off + idx) v let set_uint16_ne { off; buf; _ } idx v = Bstr.set_uint16_ne buf (off + idx) v let set_uint16_le { off; buf; _ } idx v = Bstr.set_uint16_le buf (off + idx) v let set_uint16_be { off; buf; _ } idx v = Bstr.set_uint16_be buf (off + idx) v let set_int16_ne { off; buf; _ } idx v = Bstr.set_int16_ne buf (off + idx) v let set_int16_le { off; buf; _ } idx v = Bstr.set_int16_ne buf (off + idx) v let set_int16_be { off; buf; _ } idx v = Bstr.set_int16_be buf (off + idx) v let set_int32_ne { off; buf; _ } idx v = Bstr.set_int32_ne buf (off + idx) v let set_int32_le { off; buf; _ } idx v = Bstr.set_int32_le buf (off + idx) v let set_int32_be { off; buf; _ } idx v = Bstr.set_int32_be buf (off + idx) v let set_int64_ne { off; buf; _ } idx v = Bstr.set_int64_ne buf (off + idx) v let set_int64_le { off; buf; _ } idx v = Bstr.set_int64_le buf (off + idx) v let set_int64_be { off; buf; _ } idx v = Bstr.set_int64_be buf (off + idx) v let blit a b = let len = Int.min a.len b.len in Bstr.blit a.buf ~src_off:a.off b.buf ~dst_off:b.off ~len:len let fill { off; len; buf; } ?off:(off'= 0) ?len:len' chr = let len' = match len' with | Some len' -> len' | None -> len - off' in Bstr.fill buf ~off:(off + off') ~len:len' chr let sub t ~off ~len = Slice.sub t ~off ~len let shift t n = Slice.shift t n let is_empty t = Slice.is_empty t let sub_string { Slice.buf; off; _ } ~off:off' ~len = let dst = Bytes.create len in Bstr.blit_to_bytes buf ~src_off:(off + off') dst ~dst_off:0 ~len; Bytes.unsafe_to_string dst let to_string { Slice.buf; off= src_off; len } = let dst = Bytes.create len in Bstr.blit_to_bytes buf ~src_off dst ~dst_off:0 ~len; Bytes.unsafe_to_string dst let of_string str = let off = 0 and len = String.length str in Slice.unsafe_make ~off ~len (Bstr.of_string str) let string ?(off= 0) ?len str = let len = match len with | None -> String.length str - off | Some len -> len in Slice.unsafe_make ~off:0 ~len (Bstr.string ~off ~len str) let overlap ({ buf= buf0; _ } as a) ({ buf= buf1; _ } as b) = match Bstr.overlap buf0 buf1 with | None -> None | Some (_, 0, 0) -> let len = max 0 (min (a.off + a.len) (b.off + b.len)) - max a.off b.off in if a.off >= b.off && a.off < b.off + b.len then let offset = a.off - b.off in Some (len, 0, offset) else if b.off >= a.off && b.off < a.off + a.len then let offset = b.off + a.off in Some (len, offset, 0) else None | Some _ -> let a = Bstr.sub buf0 ~off:a.off ~len:a.len and b = Bstr.sub buf1 ~off:b.off ~len:b.len in Bstr.overlap a b (* TODO(dinosaure): this case appears only for bigstrings, but we could optimize it and avoid [Bstr.sub]. *)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>