0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00

Added nondigit_term bool to parse_number() to allow parsing

of numbers that are terminated by non-number chars.  Previously
only '\0' could terminate a number.
This commit is contained in:
James Yonan 2015-02-10 15:55:32 -07:00
parent 2226a34850
commit 01a381ef44

View File

@ -37,8 +37,13 @@ namespace openvpn {
// Parse the number of type T in str, returning
// value in retval. Returns true on success.
// Note -- currently doesn't detect overflow.
// If nondigit_term is true, any non-digit char
// can terminate the numerical value. Otherwise,
// only '\0' can terminate the value.
template <typename T>
inline bool parse_number(const char *str, T& retval)
inline bool parse_number(const char *str,
T& retval,
const bool nondigit_term = false)
{
if (!str[0])
return false; // empty string
@ -58,7 +63,7 @@ namespace openvpn {
ret *= T(10);
ret += T(c - '0');
}
else if (!c)
else if (!c || nondigit_term)
{
retval = neg ? -ret : ret;
return true;