caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Strauss <philippe@strauss-acoustics.ch>
To: caml-list@inria.fr
Subject: [Caml-list] ocaml-pcre and UTF-8
Date: Thu, 16 Feb 2012 10:29:30 +0100	[thread overview]
Message-ID: <32FE3555-556A-43AC-8B1B-9A4AF08DBA02@strauss-acoustics.ch> (raw)

Hello caml'ers,

How do I convince PCRE to be UTF-8 friendly? example:

--
open Pcre

external show : 'a -> string = "%show"

let recomp = regexp ~flags:[`UTF8; `CASELESS]

let res_w = "(*UTF8)^(\w+)$"
let rec_w = recomp res_w

let accents = ["blurb"; "toxicité"; "velléités"; "à"; "où"; "über"; "marie-jeanne"]

let () =
	Printf.printf "config_utf8=%b\n" Pcre.config_utf8 ;
	List.iter (fun word ->
		try
        	let sub = Pcre.extract_opt ~full_match:false ~rex:rec_w word in
        	print_endline (show sub)
        with Not_found -> Printf.eprintf "Not_found was raised on \"%s\" :-(\n%!" word
	) accents
--

at least on my setup it gives:

--
philou@air:~/mysrc/web/myco$ ./pcre_utf 
config_utf8=true
[|Some ("blurb")|]
Not_found was raised on "toxicité" :-(
Not_found was raised on "velléités" :-(
Not_found was raised on "à" :-(
Not_found was raised on "où" :-(
Not_found was raised on "über" :-(
Not_found was raised on "marie-jeanne" :-(
--

A php user which happen to be a nice guy got it working on PHP :-( how lame.

--
Philippe Strauss
http://www.strauss-acoustics.ch/







             reply	other threads:[~2012-02-16  9:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16  9:29 Philippe Strauss [this message]
2012-02-16 10:18 ` Mauricio Fernandez
2012-02-16 10:18 ` Philippe Strauss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32FE3555-556A-43AC-8B1B-9A4AF08DBA02@strauss-acoustics.ch \
    --to=philippe@strauss-acoustics.ch \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).