aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2015-07-29 12:12:35 +0200
committerPierre-Marie Pédrot2015-07-29 12:12:35 +0200
commite76ab0ec81040cbe99f616e8457bdc26cc6dceb6 (patch)
tree5bcdbed2dac27feeb27caf840e8cad24e7483a9a /lib
parentaff5a1aaeb9b50c60ff32b7d5336a44fd18428ee (diff)
parent0dac9618c695a345f82ee302b205217fff29be29 (diff)
Merge branch 'v8.5'
Diffstat (limited to 'lib')
-rw-r--r--lib/util.ml11
-rw-r--r--lib/util.mli3
-rw-r--r--lib/xml_lexer.mll10
-rw-r--r--lib/xml_printer.ml2
4 files changed, 26 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml
index a8c25f7456..a20dba0fc4 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
diff --git a/lib/util.mli b/lib/util.mli
index 4fce809c2c..1dc405fcbe 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -110,3 +110,6 @@ val map_union : ('a -> 'c) -> ('b -> 'd) -> ('a, 'b) union -> ('c, 'd) union
type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a
(** Used for browsable-until structures. *)
+
+val open_utf8_file_in : string -> in_channel
+(** Open an utf-8 encoded file and skip the byte-order mark if any. *)
diff --git a/lib/xml_lexer.mll b/lib/xml_lexer.mll
index a33be9da73..f6943dd132 100644
--- a/lib/xml_lexer.mll
+++ b/lib/xml_lexer.mll
@@ -281,6 +281,11 @@ and dq_string = parse
Buffer.add_char tmp (lexeme_char lexbuf 1);
dq_string lexbuf
}
+ | '&'
+ {
+ Buffer.add_string tmp (entity lexbuf);
+ dq_string lexbuf
+ }
| eof
{ raise (Error EUnterminatedString) }
| _
@@ -297,6 +302,11 @@ and q_string = parse
Buffer.add_char tmp (lexeme_char lexbuf 1);
q_string lexbuf
}
+ | '&'
+ {
+ Buffer.add_string tmp (entity lexbuf);
+ q_string lexbuf
+ }
| eof
{ raise (Error EUnterminatedString) }
| _
diff --git a/lib/xml_printer.ml b/lib/xml_printer.ml
index eeddd53cb8..bbb7b51ba3 100644
--- a/lib/xml_printer.ml
+++ b/lib/xml_printer.ml
@@ -46,6 +46,8 @@ let buffer_attr tmp (n,v) =
match v.[p] with
| '\\' -> output "\\\\"
| '"' -> output "\\\""
+ | '<' -> output "&lt;"
+ | '&' -> output "&amp;"
| c -> output' c
done;
output' '"'