Overview
Features
Download
Documentation
Community
Add-Ons & Services

NumberParser behavior

General discussion regarding the development of POCO for contributors.

NumberParser behavior

Postby phireis » 02 Mar 2007, 04:44

The behavior of the NumberParser functions are a bit inconsistent in these cases:

NumberParser::parse("12a3");

This results in 12, when it should throw an exception.
I looked at the implementation and found this at tryParse:

return sscanf(s.c_str(), "%d", &value) == 1;

The sscanf behavior is parse until find something unknown, so I sugest this implementation to this and the other parser function:

^char temp;

return sscanf(s.c_str(), "%d%c", &value, &temp) == 1;^

That way it would produce an exception on the input mentioned above, that is a better behavior (at least the behavior I would excpect).

phireis
 
Posts: 12
Joined: 21 Oct 2006, 03:18

Re: NumberParser behavior

Postby guenter » 02 Mar 2007, 10:49

Thanks. That sounds like a good solution.
guenter
 
Posts: 1107
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest

cron