caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocaml-pcre and UTF-8
@ 2012-02-16  9:29 Philippe Strauss
  2012-02-16 10:18 ` Mauricio Fernandez
  2012-02-16 10:18 ` Philippe Strauss
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Strauss @ 2012-02-16  9:29 UTC (permalink / raw)
  To: caml-list

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/







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-16 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-16  9:29 [Caml-list] ocaml-pcre and UTF-8 Philippe Strauss
2012-02-16 10:18 ` Mauricio Fernandez
2012-02-16 10:18 ` Philippe Strauss

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).