diff options
Diffstat (limited to 'lib/util.ml')
-rw-r--r-- | lib/util.ml | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml index a8c25f74..a20dba0f 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -132,3 +132,14 @@ let map_union f g = function type iexn = Exninfo.iexn let iraise = Exninfo.iraise + +let open_utf8_file_in fname = + let is_bom s = + Int.equal (Char.code s.[0]) 0xEF && + Int.equal (Char.code s.[1]) 0xBB && + Int.equal (Char.code s.[2]) 0xBF + in + let in_chan = open_in fname in + let s = " " in + if input in_chan s 0 3 < 3 || not (is_bom s) then seek_in in_chan 0; + in_chan |