English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Str replacement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-05 (19:30)
From: Gerd Stolpmann <info@g...>
Subject: Re: [Caml-list] Str replacement
Am Sonntag, den 05.08.2007, 18:05 +0200 schrieb Xavier Leroy:
> > When is the Str module going to be extended to provide
> > re-entrant operations??
> When someone designs a new interface to Str and gets it approved by a
> few respectable members of this community.  A proof-of-concept
> implementation wouldn't hurt either, although I'm OK with writing the
> final implementation.  It's the API for which I don't have ideas.

What about this:


This is the reentrant API used in Ocamlnet. Once upon a time it was
really based on Str as backend, but we switched to Pcre for its extended
capabilities. The core idea is that code like

if Str.string_match re s 0 then
  let u = Str.matched_group 1 s in

is replaced by

match Str.string_match re s 0 with
  Some m ->
    let u = Str.matched_group m 1 s in
| None ->

which is not very much longer. All intermediate state is kept in m.

Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714