Commit d6b0ea92 authored by Pietro Abate's avatar Pietro Abate

[r2006-07-04 09:25:21 by afrisch] Empty log message

Original author: afrisch
Date: 2006-07-04 09:25:21+00:00
parent e507700a
......@@ -13,13 +13,13 @@ let write_markup_string ~to_enc buf s =
failwith ("Cannot represent code point " ^ string_of_int n))
s
in
Buffer.add_string buf s'
buf s'
let write_data_string ~to_enc buf s =
let write_part i len =
if (len > 0) then
if to_enc = `Enc_utf8
then Buffer.add_substring buf s i len
then buf (String.sub s i len)
else
let s' =
convert
......@@ -28,7 +28,7 @@ let write_data_string ~to_enc buf s =
~subst:(fun n -> "&#" ^ string_of_int n ^ ";")
~range_pos:i ~range_len:len s
in
Buffer.add_string buf s'
buf s'
in
let i = ref 0 in
for k = 0 to String.length s - 1 do
......@@ -36,11 +36,11 @@ let write_data_string ~to_enc buf s =
| ('&' | '<' | '>' | '"' | '%') as c ->
write_part !i (k - !i);
begin match c with
'&' -> Buffer.add_string buf "&amp;"
| '<' -> Buffer.add_string buf "&lt;"
| '>' -> Buffer.add_string buf "&gt;"
| '"' -> Buffer.add_string buf "&quot;"
| '%' -> Buffer.add_string buf "&#37;" (* reserved in DTDs *)
'&' -> buf "&amp;"
| '<' -> buf "&lt;"
| '>' -> buf "&gt;"
| '"' -> buf "&quot;"
| '%' -> buf "&#37;" (* reserved in DTDs *)
| _ -> assert false
end;
i := k+1
......@@ -90,10 +90,9 @@ and schema_values ~wds v =
schema_values ~wds tl
| _ -> raise exn_print_xml
let string_of_xml ~utf8 ns_table v =
let to_buf ~utf8 buffer ns_table v =
let to_enc = if utf8 then `Enc_utf8 else `Enc_iso88591 in
let buffer = Buffer.create 127 in
let printer = Ns.Printer.printer ns_table in
let wms = write_markup_string ~to_enc buffer
......@@ -181,10 +180,14 @@ let string_of_xml ~utf8 ns_table v =
| v -> schema_value ~wds v
in
document_start ();
print_elt (Ns.Printer.prefixes printer) v;
Buffer.contents buffer
print_elt (Ns.Printer.prefixes printer) v
let print_xml ~utf8 ns_table s =
let s = string_of_xml ~utf8 ns_table s in
let buf = Buffer.create 32 in
to_buf ~utf8 (Buffer.add_string buf) ns_table s;
let s = Buffer.contents buf in
if utf8 then string_utf8 (U.mk s) else string_latin1 s
let dump_xml ~utf8 ns_table s =
to_buf ~utf8 print_string ns_table s;
Value.nil
val print_xml: utf8:bool -> Ns.table -> Value.t -> Value.t
val dump_xml: utf8:bool -> Ns.table -> Value.t -> Value.t
......@@ -214,6 +214,15 @@ register_fun "print_xml_utf8"
(fun v -> Print_xml.print_xml ~utf8:true !Eval.ns_table v);;
register_fun "dump_xml"
Types.any string_latin1
(fun v -> Print_xml.dump_xml ~utf8:false !Eval.ns_table v);;
register_fun "dump_xml_utf8"
Types.any string
(fun v -> Print_xml.dump_xml ~utf8:true !Eval.ns_table v);;
register_fun "print"
string_latin1 nil
(fun v ->
......
......@@ -634,7 +634,8 @@ this case, the transformation is applied recursively to its content.
<p>
As a convenience, some of the OCaml expression constructors
are allowed as x-expressions (without a need to go back to OCaml
with double curly braces): (unqualified) value identifiers and
with double curly braces): (unqualified) value identifiers <b>without
apostrophes</b> and
function calls.
</p>
......@@ -702,13 +703,19 @@ X-patterns can have:
</p>
<ul>
<li>capture variables (lowercase OCaml identifiers);</li>
<li>capture variables (lowercase OCaml identifiers <b>without apostrophes</b>);</li>
<li>constant bindings <code>(x := c)</code> where x is a capture
variable and c is
a literal x-constant (this pattern always succeeds and returns the
binding x->c).</li>
</ul>
<p>
An identifier in an X-pattern can be either a reference
to a named X-type (if such a type declaration is in scope)
or a capture variable (otherwise).
</p>
<p>
Here is a brief description of the semantics of patterns. Given
an input value, a pattern can either succeed or fail. If it succeeds,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment