| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
OK, so let me rephrase my question.I have a certain character (let us call it c).According to what you said, the corresponding \ddd will be displayed as c by an ASCII reader.What do I type in OCaml to get it displayed as c by an ISO-latin1 reader?What do I type in OCaml to get it displayed as c by an UTF-8 reader ?
My point is that I do not want to change the encoding in the non-OCaml parts of my projects, which might cause trouble. I want to deal with the encoding issue in OCaml directly.
De : "Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]>
À : "[email protected]" <[email protected]>
Envoyé le : Mardi 27 janvier 2015 10h52
Objet : Re: "ocaml_beginners"::[] Writing uncommon ASCII characters programmatically
\ddd will output precisely the byte you ask for. How it will be interpreted by the reader depends on the encoding it has been configured for. "It is misread in the .sql file" doesn't mean much, it all depends on which software reads that file and how it is configured -- whether it expects UTF-8 input, or ISO-latin1, or just plain ASCII.
On Tue, Jan 27, 2015 at 10:24 AM, Doyle Jonathan [email protected] [ocaml_beginners] <[email protected]> wrote:
In my project where I use Ocaml to manipulate MySQL files, I need to wtite some text into files programmatically, and I am experiencing some trouble when the text has some accentuated Latin characters :
1) When I type accentuated character directly in the Ocaml source interpreter, it is misread in the receiving .sql file (this is example s1 in the code below)
2) According to the Ocaml manual, I could use \ddd where ddd is the ASCII decimal code for the character. When I try that, it is misread n the receiving .sql file again, but in a different way ( this is example s2 in the code below).
Below I copied some functions from my personal library, then explained miscelleneaous attempts to write correctly an accentuated Latin character.
Code from my personal library :
type complete_filename=CFN of string;;
type vague_filename=string;;
let make_filename_complete (s:vague_filename)=
let home=Sys.getenv("HOME") in
if s="" then CFN(home) else
let c=String.get s 0 in
if c='/' then CFN(s) else
if c='~' then CFN(home^(String.sub s 1 (String.length(s)-1))) else
CFN((Sys.getcwd ())^"/"^s);;
let open_out_locally x=try open_out(x) with
_->failwith("File "^x^" cannot be opened out");;
let erase_file_and_fill_it_with_contents_of_buffer (vx:vague_filename) b=
let x=(fun (CFN(u))->u)(make_filename_complete(vx)) in
let john=open_out_locally(x) in
(Buffer.output_buffer(john)(b);close_out john);;
let erase_file_and_fill_it_with_string s (x:vague_filename)=
let n=String.length(s) in
let b=Buffer.create(n) in
let _=Buffer.add_string b s in
erase_file_and_fill_it_with_contents_of_buffer x b;;
And here are my failed attempts :
let s1="This is the French e grave character : è" ;;
erase_file_and_fill_it_with_string s1 "example.sql";;
It produces the following output in example.sql :
This is the French e grave character : è
let s2="This is the French e grave character :\133" ;;
erase_file_and_fill_it_with_string s2 "example.sql";;
It produces the following output in example.sql :
This is the French e grave character :Ö
#yiv7978404911 #yiv7978404911 -- #yiv7978404911ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv7978404911 #yiv7978404911ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv7978404911 #yiv7978404911ygrp-mkp #yiv7978404911hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv7978404911 #yiv7978404911ygrp-mkp #yiv7978404911ads {margin-bottom:10px;}#yiv7978404911 #yiv7978404911ygrp-mkp .yiv7978404911ad {padding:0 0;}#yiv7978404911 #yiv7978404911ygrp-mkp .yiv7978404911ad p {margin:0;}#yiv7978404911 #yiv7978404911ygrp-mkp .yiv7978404911ad a {color:#0000ff;text-decoration:none;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ygrp-lc {font-family:Arial;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ygrp-lc #yiv7978404911hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ygrp-lc .yiv7978404911ad {margin-bottom:10px;padding:0 0;}#yiv7978404911 #yiv7978404911actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv7978404911 #yiv7978404911activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv7978404911 #yiv7978404911activity span {font-weight:700;}#yiv7978404911 #yiv7978404911activity span:first-child {text-transform:uppercase;}#yiv7978404911 #yiv7978404911activity span a {color:#5085b6;text-decoration:none;}#yiv7978404911 #yiv7978404911activity span span {color:#ff7900;}#yiv7978404911 #yiv7978404911activity span .yiv7978404911underline {text-decoration:underline;}#yiv7978404911 .yiv7978404911attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv7978404911 .yiv7978404911attach div a {text-decoration:none;}#yiv7978404911 .yiv7978404911attach img {border:none;padding-right:5px;}#yiv7978404911 .yiv7978404911attach label {display:block;margin-bottom:5px;}#yiv7978404911 .yiv7978404911attach label a {text-decoration:none;}#yiv7978404911 blockquote {margin:0 0 0 4px;}#yiv7978404911 .yiv7978404911bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv7978404911 .yiv7978404911bold a {text-decoration:none;}#yiv7978404911 dd.yiv7978404911last p a {font-family:Verdana;font-weight:700;}#yiv7978404911 dd.yiv7978404911last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv7978404911 dd.yiv7978404911last p span.yiv7978404911yshortcuts {margin-right:0;}#yiv7978404911 div.yiv7978404911attach-table div div a {text-decoration:none;}#yiv7978404911 div.yiv7978404911attach-table {width:400px;}#yiv7978404911 div.yiv7978404911file-title a, #yiv7978404911 div.yiv7978404911file-title a:active, #yiv7978404911 div.yiv7978404911file-title a:hover, #yiv7978404911 div.yiv7978404911file-title a:visited {text-decoration:none;}#yiv7978404911 div.yiv7978404911photo-title a, #yiv7978404911 div.yiv7978404911photo-title a:active, #yiv7978404911 div.yiv7978404911photo-title a:hover, #yiv7978404911 div.yiv7978404911photo-title a:visited {text-decoration:none;}#yiv7978404911 div#yiv7978404911ygrp-mlmsg #yiv7978404911ygrp-msg p a span.yiv7978404911yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv7978404911 .yiv7978404911green {color:#628c2a;}#yiv7978404911 .yiv7978404911MsoNormal {margin:0 0 0 0;}#yiv7978404911 o {font-size:0;}#yiv7978404911 #yiv7978404911photos div {float:left;width:72px;}#yiv7978404911 #yiv7978404911photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv7978404911 #yiv7978404911photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv7978404911 #yiv7978404911reco-category {font-size:77%;}#yiv7978404911 #yiv7978404911reco-desc {font-size:77%;}#yiv7978404911 .yiv7978404911replbq {margin:4px;}#yiv7978404911 #yiv7978404911ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv7978404911 #yiv7978404911ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv7978404911 #yiv7978404911ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv7978404911 #yiv7978404911ygrp-mlmsg select, #yiv7978404911 input, #yiv7978404911 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv7978404911 #yiv7978404911ygrp-mlmsg pre, #yiv7978404911 code {font:115% monospace;}#yiv7978404911 #yiv7978404911ygrp-mlmsg * {line-height:1.22em;}#yiv7978404911 #yiv7978404911ygrp-mlmsg #yiv7978404911logo {padding-bottom:10px;}#yiv7978404911 #yiv7978404911ygrp-msg p a {font-family:Verdana;}#yiv7978404911 #yiv7978404911ygrp-msg p#yiv7978404911attach-count span {color:#1E66AE;font-weight:700;}#yiv7978404911 #yiv7978404911ygrp-reco #yiv7978404911reco-head {color:#ff7900;font-weight:700;}#yiv7978404911 #yiv7978404911ygrp-reco {margin-bottom:20px;padding:0px;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ov li a {font-size:130%;text-decoration:none;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv7978404911 #yiv7978404911ygrp-sponsor #yiv7978404911ov ul {margin:0;padding:0 0 0 8px;}#yiv7978404911 #yiv7978404911ygrp-text {font-family:Georgia;}#yiv7978404911 #yiv7978404911ygrp-text p {margin:0 0 1em 0;}#yiv7978404911 #yiv7978404911ygrp-text tt {font-size:120%;}#yiv7978404911 #yiv7978404911ygrp-vital ul li:last-child {border-right:none !important;}#yiv7978404911