Commit df24da7f authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-06-28 13:57:31 by afrisch] Bug in utf8 decoding

Original author: afrisch
Date: 2004-06-28 13:57:31+00:00
parent 6c8718d4
...@@ -80,17 +80,17 @@ struct ...@@ -80,17 +80,17 @@ struct
| '\000'..'\127' as c -> | '\000'..'\127' as c ->
Char.code c Char.code c
| '\192'..'\223' as c -> | '\192'..'\223' as c ->
((Char.code c - 192) lsl 6) lor ((Char.code c land 0b11111) lsl 6) lor
((Char.code s.[i+1] - 128)) ((Char.code s.[i+1] land 0b111111))
| '\224'..'\239' as c -> | '\224'..'\239' as c ->
((Char.code c - 192) lsl 12) lor ((Char.code c land 0b11111) lsl 12) lor
((Char.code s.[i+1] - 128) lsl 6) lor ((Char.code s.[i+1] land 0b111111) lsl 6) lor
((Char.code s.[i+2] - 128)) ((Char.code s.[i+2] land 0b111111))
| '\240'..'\248' as c -> | '\240'..'\248' as c ->
((Char.code c - 192) lsl 18) lor ((Char.code c land 0b11111) lsl 18) lor
((Char.code s.[i+1] - 128) lsl 12) lor ((Char.code s.[i+1] land 0b111111) lsl 12) lor
((Char.code s.[i+2] - 128) lsl 6) lor ((Char.code s.[i+2] land 0b111111) lsl 6) lor
((Char.code s.[i+3] - 128)) ((Char.code s.[i+3] land 0b111111))
| _ -> failwith "Malformed UTF-8 bufffer" | _ -> failwith "Malformed UTF-8 bufffer"
let next s i = let next s i =
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!DOCTYPE page [
<!ENTITY rarr "&#8594;"> <!-- rightwards arrow, U+2192 ISOnum -->
<page name="manual_interfacewithocaml"> <page name="manual_interfacewithocaml">
<title>Interfacing CDuce with OCaml</title> <title>Interfacing CDuce with OCaml</title>
...@@ -6,20 +9,44 @@ ...@@ -6,20 +9,44 @@
<box title="Introduction" link="intro"> <box title="Introduction" link="intro">
<p> <p>
When you have to write a large program you often need to manage some This page describe the CDuce/OCaml interface. This interface allows
persistent data. An elegant and widespread technique to fulfill the programmer to:
this goal, is to use XML based documents. And a safe and robust
way to treat XML files is to write a small program in CDuce.
</p> </p>
<li>call OCaml functions from a CDuce module;</li>
<li>export a CDuce as an OCaml module, by giving it an explicit OCaml signature.</li>
The intended usages for the interface are:
<li>Piggyback existing OCaml libraries, such as database,
network, GUI, datastructures;</li>
<li>Use CDuce as an XML layer (input/output/transformation) for OCaml
<li>Develop fully mixed OCaml/CDuce projects.</li>
<p> <p>
This page explains how to call CDuce functions from OCaml to couple. It is very To see how to build CDuce with support for the OCaml interface,
simple all you need to do is to write an OCaml interface file for the CDuce see the INSTALL file from the CDuce distribution.
functions you want to export to OCaml. This requires that CDuce was compiled
with support for OCaml interface (<code>ML_INTERFACE=true</code>).
</p> </p>
<box title="Translating types" link="transl">
The heart of the interface is a mapping from OCaml types to CDuce
types. An OCaml type <code>t</code> is translated to a CDuce type
<code>T(t)</code>, which is meant to be &rarr; isomorphic to <code>t</code>:
there exist a canonical function <code>t &rarr; T(t)</code>
from OCaml values of type <code>t</code> to CDuce values of type
<code>T(t)</code>, and another canonical function <code>T(t) &rarr; t</code>.
</box> </box>
<box title="The interface file" link="interface"> <box title="The interface file" link="interface">
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