Commits

Anonymous committed 620412c

Bytes, Strings.Onebyte: + hexdump

  • Participants
  • Parent commits 5c92cae

Comments (0)

Files changed (2)

         external set : t -> int -> Cd_Byte.Byte.t -> unit = "%string_safe_set";
       end
     ;
+
+    value hexdump : ~style:[= `Line ] -> string -> string =
+      let hexchars = "0123456789ABCDEF" in
+      fun ~style bs ->
+        match style with
+        [ `Line ->
+            let len = length bs in
+            if len = 0
+            then ""
+            else
+              let r = make (3 * len - 1) '\x20' in
+              let () =
+                for i = 0 to len - 1 do
+                  ( let b = Char.code bs.[i] in
+                    let hi = b lsr 4 in
+                    let lo = b land 0xF in
+                    let ri = i * 3 in
+                    ( r.[ri] := hexchars.[hi]
+                    ; r.[ri + 1] := hexchars.[lo]
+                    )
+                  )
+                done
+              in
+                r
+        ]
+    ;
+
   end
 ;
+
+
+
+
+
+
+
+
+
+

src/cd_Strings.ml

         value cmp_nocase_latin1 : string -> string -> cmp_res;
         value hash_nocase_latin1 : string -> int;
 
+        value hexdump : ~style:[= `Line] -> string -> string;
+
         include TFUNCS;
 
       end
 
         value append = perv_append;
 
+        value hexdump = Cd_Bytes.Bytes.hexdump;
+
         include TCommon;
 
       end