Skip to content

Instantly share code, notes, and snippets.

@Maelan
Maelan / fix-mixed-utf8
Created April 10, 2016 16:34
Decodes UTF-8, interpreting ill-formed UTF-8 sequences as CP1252.
#!/usr/bin/ocaml
(*
* Reads an UTF-8 text and writes it on standard output. Invalid codes are
* regarded as CP1252-encoded characters and are converted to UTF-8.
*)
let substitute = ""
let buf = object (self)
(******************************************************************************)
(**
** Just some notations
**)
let[@inline] ( ~~ ) to_apply ~(f : _ -> _) = to_apply f
let[@inline] ( ~~~ ) to_apply x ~(f : _ -> _) = to_apply x f
let[@inline] ( ~~~~ ) to_apply x y ~(f : _ -> _) = to_apply x y f
let[@inline] ( ~> ) to_apply ~(f : _ -> _) ~init s = to_apply f init s (* fold_left *)