NumberParser behavior

General discussion regarding the development of POCO for contributors.
Posts: 12
Joined: 21 Oct 2006, 03:18

NumberParser behavior

Postby phireis » 02 Mar 2007, 04:44

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


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).

Posts: 1195
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: NumberParser behavior

Postby guenter » 02 Mar 2007, 10:49

Thanks. That sounds like a good solution.

Return to “Contributors”

Who is online

Users browsing this forum: No registered users and 0 guests