From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-07-30 00:28:57
John Maddock wrote:
> > BTW, I don't think that explicitly checking for empty
> > string should do the trick ;) - I believe the current semantics is
> > flawed and doesn't reflect user's expectations (which are also
> > supported by the docs).
> Well you won't be surprised to learn that I disagree:-)
> The problem with matching a null string is that any partial match will
> always succeed, since there will always be a null string suffix that
> "matches". I don't see this as very useful.
For one, it covers our use case :) (input validation). Do you have a use
case in mind there the current semantic (empty string _not_ partially
matching to anything) make sense?
> With respect to validating input, you are right that a null
> string could match if there was more input, but a null string
> could match anything at all if there was more input!
Right, and IMO 'boost::regex_match(..., boost::match_default |
boost::match_partial) should return 'true' in this case.
> To put it another way, why on earth would you want
> to waste CPU cycles trying a partial match against a NULL
For one thing, I hope that when 'boost::regex_match' compares iterators into
input string and discovers that they are equal, it doesn't spent another 5
minutes there just hanging around :). Speaking seriously, it's not at all
clear to me that writing
|| boost::regex_match(input, match, re, boost::match_default |
is going to be faster than plain call to properly implemented
'boost::regex_match' (which, after all, can do the same thing inside :)
> The fact that it is NULL tells you that you need some more input
> before any decision can be taken anyway.
You need explicitly to check for empty string to make that decision. I am
arguing that this is not a user's responsibility and that this should be a
default semantics of partial matches. You don't want users that use
'regex_match' for input validation to always write
input.empty() || boost::regex_match(... boost::match_partial)
instead of simple
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk