14#ifndef OPENVPN_COMMON_NUMBER_H
15#define OPENVPN_COMMON_NUMBER_H
36 const bool nondigit_term =
false)
42 if (std::numeric_limits<T>::min() < 0 && str[0] ==
'-')
50 const char c = str[i++];
51 if (c >=
'0' && c <=
'9')
56 else if (!c || nondigit_term)
70 return parse_number<T>(str.c_str(), retval);
77 if (parse_number<T>(str.c_str(),
ret))
80 throw number_parse_exception(error);
87 if (parse_number<T>(str.c_str(),
ret))
90 throw number_parse_exception(std::string(error));
97 if (parse_number<T>(str,
ret))
100 throw number_parse_exception(std::string(error));
105 const size_t max_len,
108 T *value_return =
nullptr)
110 if (numstr.length() <= max_len)
113 if (parse_number<T>(numstr.c_str(), value))
115 if (value >= minimum && value <= maximum)
118 *value_return = value;
129 bool found_digit =
false;
132 if (c >=
'0' && c <=
'9')
#define OPENVPN_EXCEPTION(C)
Support deferred server-side state creation when client connects.
bool parse_number_validate(const std::string &numstr, const size_t max_len, const T minimum, const T maximum, T *value_return=nullptr)
bool parse_number(const char *str, T &retval, const bool nondigit_term=false)
bool is_number(const char *str)
T parse_number_throw(const std::string &str, const std::string &error)