Re: Writing uncommon ASCII characters programmatically

"Doyle Jonathan [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
I got it now, it works fine when I use to \xdd. My text editor uses UTF-8 encoding.Thank you.
JD

      De : "Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]>
 À : "[email protected]" <[email protected]> 
 Envoyé le : Mardi 27 janvier 2015 11h24
 Objet : Re: "ocaml_beginners"::[] Writing uncommon ASCII characters programmatically
   
    The numerical value of the character 'c' is *defined* by the encoding.
The wikipedia article for latin-1  http://en.wikipedia.org/wiki/ISO_8859-1gives you the encodings in hexadecimal (you can use \xdd to specify the hexa number as an OCaml character literal).The character 'è' in this table is \xE8.
$ cat > test.ml <<EOFprint_endline "\xE8";;EOF$ ocaml test.ml | iconv -f latin1è
According to  http://en.wikipedia.org/wiki/UTF-8the euro symbol "€" is encoded in UTF-8 as the byte sequence (in hexa) E2 82 AC:
$ cat > test.ml <<EOFprint_endline "\xE2\x82\xAC";;EOF$ ocaml test.ml | iconv -f utf-8€




On Tue, Jan 27, 2015 at 11:12 AM, Doyle Jonathan [email protected] [ocaml_beginners] <[email protected]> wrote:

 

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 :Ö







  

   



  #yiv7041646273 #yiv7041646273 -- #yiv7041646273ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv7041646273 #yiv7041646273ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv7041646273 #yiv7041646273ygrp-mkp #yiv7041646273hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv7041646273 #yiv7041646273ygrp-mkp #yiv7041646273ads {margin-bottom:10px;}#yiv7041646273 #yiv7041646273ygrp-mkp .yiv7041646273ad {padding:0 0;}#yiv7041646273 #yiv7041646273ygrp-mkp .yiv7041646273ad p {margin:0;}#yiv7041646273 #yiv7041646273ygrp-mkp .yiv7041646273ad a {color:#0000ff;text-decoration:none;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ygrp-lc {font-family:Arial;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ygrp-lc #yiv7041646273hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ygrp-lc .yiv7041646273ad {margin-bottom:10px;padding:0 0;}#yiv7041646273 #yiv7041646273actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv7041646273 #yiv7041646273activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv7041646273 #yiv7041646273activity span {font-weight:700;}#yiv7041646273 #yiv7041646273activity span:first-child {text-transform:uppercase;}#yiv7041646273 #yiv7041646273activity span a {color:#5085b6;text-decoration:none;}#yiv7041646273 #yiv7041646273activity span span {color:#ff7900;}#yiv7041646273 #yiv7041646273activity span .yiv7041646273underline {text-decoration:underline;}#yiv7041646273 .yiv7041646273attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv7041646273 .yiv7041646273attach div a {text-decoration:none;}#yiv7041646273 .yiv7041646273attach img {border:none;padding-right:5px;}#yiv7041646273 .yiv7041646273attach label {display:block;margin-bottom:5px;}#yiv7041646273 .yiv7041646273attach label a {text-decoration:none;}#yiv7041646273 blockquote {margin:0 0 0 4px;}#yiv7041646273 .yiv7041646273bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv7041646273 .yiv7041646273bold a {text-decoration:none;}#yiv7041646273 dd.yiv7041646273last p a {font-family:Verdana;font-weight:700;}#yiv7041646273 dd.yiv7041646273last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv7041646273 dd.yiv7041646273last p span.yiv7041646273yshortcuts {margin-right:0;}#yiv7041646273 div.yiv7041646273attach-table div div a {text-decoration:none;}#yiv7041646273 div.yiv7041646273attach-table {width:400px;}#yiv7041646273 div.yiv7041646273file-title a, #yiv7041646273 div.yiv7041646273file-title a:active, #yiv7041646273 div.yiv7041646273file-title a:hover, #yiv7041646273 div.yiv7041646273file-title a:visited {text-decoration:none;}#yiv7041646273 div.yiv7041646273photo-title a, #yiv7041646273 div.yiv7041646273photo-title a:active, #yiv7041646273 div.yiv7041646273photo-title a:hover, #yiv7041646273 div.yiv7041646273photo-title a:visited {text-decoration:none;}#yiv7041646273 div#yiv7041646273ygrp-mlmsg #yiv7041646273ygrp-msg p a span.yiv7041646273yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv7041646273 .yiv7041646273green {color:#628c2a;}#yiv7041646273 .yiv7041646273MsoNormal {margin:0 0 0 0;}#yiv7041646273 o {font-size:0;}#yiv7041646273 #yiv7041646273photos div {float:left;width:72px;}#yiv7041646273 #yiv7041646273photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv7041646273 #yiv7041646273photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv7041646273 #yiv7041646273reco-category {font-size:77%;}#yiv7041646273 #yiv7041646273reco-desc {font-size:77%;}#yiv7041646273 .yiv7041646273replbq {margin:4px;}#yiv7041646273 #yiv7041646273ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv7041646273 #yiv7041646273ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv7041646273 #yiv7041646273ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv7041646273 #yiv7041646273ygrp-mlmsg select, #yiv7041646273 input, #yiv7041646273 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv7041646273 #yiv7041646273ygrp-mlmsg pre, #yiv7041646273 code {font:115% monospace;}#yiv7041646273 #yiv7041646273ygrp-mlmsg * {line-height:1.22em;}#yiv7041646273 #yiv7041646273ygrp-mlmsg #yiv7041646273logo {padding-bottom:10px;}#yiv7041646273 #yiv7041646273ygrp-msg p a {font-family:Verdana;}#yiv7041646273 #yiv7041646273ygrp-msg p#yiv7041646273attach-count span {color:#1E66AE;font-weight:700;}#yiv7041646273 #yiv7041646273ygrp-reco #yiv7041646273reco-head {color:#ff7900;font-weight:700;}#yiv7041646273 #yiv7041646273ygrp-reco {margin-bottom:20px;padding:0px;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ov li a {font-size:130%;text-decoration:none;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv7041646273 #yiv7041646273ygrp-sponsor #yiv7041646273ov ul {margin:0;padding:0 0 0 8px;}#yiv7041646273 #yiv7041646273ygrp-text {font-family:Georgia;}#yiv7041646273 #yiv7041646273ygrp-text p {margin:0 0 1em 0;}#yiv7041646273 #yiv7041646273ygrp-text tt {font-size:120%;}#yiv7041646273 #yiv7041646273ygrp-vital ul li:last-child {border-right:none !important;}#yiv7041646273
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.