package hxd
Hexdump in OCaml
Install
Dune Dependency
Authors
Maintainers
Sources
hxd-0.3.3.tbz
sha256=4ede235296a5e2a2599776c8bceb4853c164ef7e573570a1edc68a4c0c90433e
sha512=39d42632ea7acc2e9418faefdef91085e420a03c3aa03e04e75f99c9d24a4deb96ff71ad948d208ce562077dd3f6f92f975dc7c006a97cd7eabc1e8a7f5381d0
doc/src/hxd.string/hxd_string.ml.html
Source file hxd_string.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
open Hxd module Caml_scheduler = Make (struct type +'a t = 'a end) type error = Seek type flow = {mutable off: int; len: int} let caml = {bind= (fun x f -> f (Caml_scheduler.prj x)); return= Caml_scheduler.inj} let lseek = let lseek flow pos mode = let () = match mode with | `CUR -> flow.off <- flow.off + pos | `SET -> flow.off <- pos | `END -> flow.off <- flow.len - pos in if flow.off < 0 || flow.off >= flow.len then Caml_scheduler.inj (Error Seek) else Caml_scheduler.inj (Ok flow.off) in {lseek} let pp configuration ppf str = let ic = {off= 0; len= String.length str} in let recv flow buffer ~off ~len = let len = min len (flow.len - flow.off) in Bytes.blit_string str flow.off buffer off len ; flow.off <- flow.off + len ; Caml_scheduler.inj (Ok len) in let send _ _ ~off:_ ~len = Caml_scheduler.inj (Ok len) in let seek = `Absolute 0 in let res = generate configuration caml recv send ic () lseek seek ppf in match Caml_scheduler.prj res with Ok () -> () | Error Seek -> () let generate configuration str seek ppf = let ic = {off= 0; len= String.length str} in let oc = Buffer.create 16 in let recv flow buffer ~off ~len = let len = min len (flow.len - flow.off) in Bytes.blit_string str flow.off buffer off len ; flow.off <- flow.off + len ; Caml_scheduler.inj (Ok len) in let send buf buffer ~off ~len = Buffer.add_substring buf buffer off len ; Caml_scheduler.inj (Ok len) in let res = generate configuration caml recv send ic oc lseek seek ppf in match Caml_scheduler.prj res with | Ok () -> Ok (Buffer.contents oc) | Error Seek -> Error (`Msg "Index out of bounds") let null = Format.formatter_of_out_functions { Format.out_string= (fun _ _ _ -> ()) ; out_flush= (fun () -> ()) ; out_newline= (fun () -> ()) ; out_spaces= (fun _ -> ()) ; out_indent= (fun _ -> ()) } let to_hxd configuration str seek = generate configuration str seek null
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>