aboutsummaryrefslogtreecommitdiffhomepage
path: root/ide/utf8_convert.mll
diff options
context:
space:
mode:
authorGravatar monate <monate@85f007b7-540e-0410-9357-904b9bb8a0f7>2003-05-14 12:09:29 +0000
committerGravatar monate <monate@85f007b7-540e-0410-9357-904b9bb8a0f7>2003-05-14 12:09:29 +0000
commit05c1e8d802c326b28db14483390af2d83bd6d19a (patch)
tree7883a437ec6cd50c9c50721fd8a116a2fd67a7b9 /ide/utf8_convert.mll
parentadfffe936ed1d22f39bd12b7013447473697db74 (diff)
coqide: load/save file encoding support/
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@4021 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'ide/utf8_convert.mll')
-rw-r--r--ide/utf8_convert.mll51
1 files changed, 51 insertions, 0 deletions
diff --git a/ide/utf8_convert.mll b/ide/utf8_convert.mll
new file mode 100644
index 000000000..52772ad68
--- /dev/null
+++ b/ide/utf8_convert.mll
@@ -0,0 +1,51 @@
+(***********************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA-Rocquencourt & LRI-CNRS-Orsay *)
+(* \VV/ *************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(***********************************************************************)
+
+(* $Id$ *)
+
+{
+ open Lexing
+ let b = Buffer.create 127
+
+}
+
+(* Replace all occurences of \x{iiii} and \x{iiiiiiii} by UTF-8 valid chars *)
+
+let digit = ['0'-'9''A'-'Z''a'-'z']
+let short = digit digit digit digit
+let long = short short
+
+rule entry = parse
+ | "\\x{" (short | long ) '}'
+ { let s = lexeme lexbuf in
+ let n = String.length s in
+ let code =
+ try Glib.Utf8.from_unichar
+ (int_of_string ("0x"^(String.sub s 3 (n - 4))))
+ with _ -> s
+ in
+ let c = if Glib.Utf8.validate code then code else s in
+ Buffer.add_string b c;
+ entry lexbuf
+ }
+ | _
+ { let s = lexeme lexbuf in
+ Buffer.add_string b s;
+ entry lexbuf}
+ | eof
+ {
+ let s = Buffer.contents b in Buffer.reset b ; s
+ }
+
+
+{
+ let f s =
+ let lb = from_string s in
+ Buffer.reset b;
+ entry lb
+}