diff options
author | Guillaume Melquiond <guillaume.melquiond@inria.fr> | 2015-07-28 12:30:14 +0200 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@inria.fr> | 2015-07-28 12:30:14 +0200 |
commit | 71b101172275a7c5872f6e8e70f9c0185f93f828 (patch) | |
tree | 3d31693af2a5f595b5a8f8cbab3438c3bb6cd18d /lib/util.ml | |
parent | 6d8d39fd0a1c7dac1b6415660fd97fe3ad010ff7 (diff) |
Use open_utf8_file_in for opening files in the IDE. (Fix bug #2874)
File system.ml seemed like a better choice than util.ml for sharing the
code, but it was bringing a bunch of useless dependencies to the IDE.
There are presumably several other tools that would benefit from using
open_utf8_file_in instead of open_in, e.g. coqdoc.
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 a8c25f745..a20dba0fc 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 |