diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2018-01-19 11:24:29 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2018-01-25 17:17:15 +0100 |
commit | 112ab4b1c396fc2117191297227d8e411f9b9bb3 (patch) | |
tree | f6d06ef60c696b43d48e2cd8e2f7f426a03b3706 /src/unicode.ml | |
parent | 098ac444e731d7674d8910264ae58fb876618a5a (diff) |
Better memory management
Diffstat (limited to 'src/unicode.ml')
-rwxr-xr-x | src/unicode.ml | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/unicode.ml b/src/unicode.ml deleted file mode 100755 index cc8c087..0000000 --- a/src/unicode.ml +++ /dev/null @@ -1,51 +0,0 @@ -type t = Uchar.t array - -type decoder_encoding = Uutf.decoder_encoding - -let array_from_rev_list l = begin - let length = (List.length l) - 1 in - let arr = Array.make (length + 1) (Obj.magic 0) in - List.iteri (fun i elem -> Array.set arr (length - i) elem) l; - arr -end - - -let decode ?encoding str = begin - let decoder = Uutf.decoder ?encoding (`String str) in - let rec loop buf = begin match Uutf.decode decoder with - | `Uchar u -> loop (u::buf) - | `Malformed _ -> loop (Uutf.u_rep::buf) - | `Await -> assert false - | `End -> ( - array_from_rev_list buf - ) - end in - loop [] -end - -let to_utf8 (t:t) = begin - let buf = Buffer.create 512 in - Array.iter (Uutf.Buffer.add_utf_8 buf) t; - Buffer.contents buf -end - -let length = Array.length - -let get t i = Uchar.of_int @@ Array.get t i - -let make i v = Array.make i @@ Uchar.to_int v - -let init s f = Array.init s (fun x -> Uchar.to_int @@ f x) - -let sub = Array.sub - -let blit = Array.blit - -let concat = Array.concat - -let iter f t = Array.iter (fun x -> f @@ Uchar.of_int x) t - - -let to_list t = - Array.map Uchar.of_int t - |> Array.to_list |