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.string_match incorrect
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-25 (04:24)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Str.string_match incorrect
On Sat, 2004-12-25 at 14:07, Christopher A. Watford wrote:

> >From the documentation, as you have pointed out (now I see what you
> mean), it does not make this constraint obvious. It appears that
> string_match's documentation should include that an implicit ^ is
> added. string_partial_match makes this clear however.

Except even that isn't quite correct -- ^ matches a newline
as well as start of string.

When matching on a 'string' the special handling of newline
is out of place -- newlines are ordinary characters.

When matching on a whole file, as in awk/sed/perl style
of tools, the line orientation makes some sense.

In any case, the bug is a mismatch, IMHO, between what the
function does and what the documentation says it does.

I had expected string_match to match a whole string or fail,
because that's what the documentation says it does.

However there are two compatibility arguments for
changing the documentation instead -- non Ocaml user
expectations (clearly indicated in replies to my post),
and breaking of existing Ocaml code that relies on
the actual behaviour not the documented behaviour,
misreading it as others seem to have done, and assuming
PCRE/Emacs/awk/sed ... or whatever .. semantics.

If that path is chosen I think it would be nice
to provide a function that actually does what the
documentation *originally* specified (that is,
what it says right now): match a whole string.

This is because the obvious hack:


does not in fact work if the string contains newlines --
according to the documentation anyhow :)

I'm not a heavy user of Str -- I would never use it
in a serious application. However I used it in
the program I wrote to build test harness for
ExtLib (there is now an extlib-test module in CVS
which tests ExtLib) and it didn't work.

I did indeed fix the problem with ^r$, because I'm
checking filenames which seem unlikely to have any
newlines in them. 

Anyhow .. it's up to Xavier: I posted the original
note into the bugtracker too :)

John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net