Boost logo

Boost :

From: John Maddock (john_maddock_at_[hidden])
Date: 2002-07-29 05:56:31


> But then it contradicts one of its intended uses:
>
> "Partial matches are typically used when either validating data input
> (checking each character as it is entered on the keyboard), .."
>
> How you can use it to validate data input if it doesn't validate the very
> initial state of every input - an empty string?
>
> Just to make the contradiction clear, here's the description of the
example
> in "Partial matches" section from the docs:
>
> "The following example tests to see whether the text could be a valid
credit
> card number, as the user presses a key, the character entered would be
added
> to the string being built up, and passed to is_possible_card_number. If
this
> returns true then the text could be a valid card number, so the user
> interface's OK button would be enabled. If it returns false, then this is
> not yet a valid card number, but could be with more input, so the user
> interface would disable the OK button. Finally, if the procedure throws an
> exception the input could never become a valid number, and the inputted
> character must be discarded, and a suitable error indication displayed to
> the user."
>
> Well, empty string definitely falls into "this is not yet a valid card
> number, but could be with more input" category, but with the current
> semantics the procedure will throw an exception when, for example, user
> deletes the first (incorrectly) entered character.
>
> 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.

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! To put it another way, why on earth would you want
to waste CPU cycles trying a partial match against a NULL string? The fact
that it is NULL tells you that you need some more input before any decision
can be taken anyway.

John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/index.htm


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk