Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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:

https://godirepo.camlcity.org/wwwsvn/trunk/code/src/netstring/netstring_str.mli?rev=1003&root=lib-ocamlnet2&view=auto

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
  do_this
else
  do_something_else

is replaced by

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

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

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