From: Kazunori Fujiwara Date: Mon, 8 Jul 2013 02:43:54 +0000 (+0900) Subject: [3015] Rewrote to use boost::lexical cast to convert string to values X-Git-Tag: bind10-1.2.0beta1-release~270^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0202fc5aeaa4e339d55c93eeaf83cdfaafda559a;p=thirdparty%2Fkea.git [3015] Rewrote to use boost::lexical cast to convert string to values --- diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index a23f923551..a48e1ce915 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -28,6 +28,7 @@ #include #include // for iequals +#include #include @@ -90,7 +91,7 @@ Element::getValue(std::map&) const { } bool -Element::setValue(const int64_t) { +Element::setValue(const long long int) { return (false); } @@ -399,38 +400,21 @@ numberFromStringstream(std::istream& in, int& pos) { // ElementPtr fromStringstreamNumber(std::istream& in, int& pos) { - long long int i; - double d = 0.0; - bool is_double = false; - char* endptr; - std::string number = numberFromStringstream(in, pos); - errno = 0; - i = strtoll(number.c_str(), &endptr, 10); - if (*endptr != '\0') { - const char* ptr; - errno = 0; - d = strtod(ptr = number.c_str(), &endptr); - is_double = true; - if (*endptr != '\0' || ptr == endptr) { - isc_throw(JSONError, std::string("Bad number: ") + number); - } else { - if (errno != 0) { - isc_throw(JSONError, std::string("Number overflow: ") + number); - } + if (number.find_first_of(".eE") < number.size()) { + try { + return (Element::create(boost::lexical_cast(number))); + } catch (const boost::bad_lexical_cast&) { + isc_throw(JSONError, std::string("Number overflow: ") + number); } } else { - if ((i == LLONG_MAX || i == LLONG_MIN) && errno != 0) { + try { + return (Element::create(boost::lexical_cast(number))); + } catch (const boost::bad_lexical_cast&) { isc_throw(JSONError, std::string("Number overflow: ") + number); } } - - if (is_double) { - return (Element::create(d)); - } else { - return (Element::create(i)); - } } ElementPtr diff --git a/src/lib/cc/data.h b/src/lib/cc/data.h index d001a29a9b..ca1c5eff65 100644 --- a/src/lib/cc/data.h +++ b/src/lib/cc/data.h @@ -167,7 +167,9 @@ public: /// is of the correct type /// //@{ - virtual bool setValue(const int64_t v); + virtual bool setValue(const long long int v); + bool setValue(const long int i) { return (setValue(static_cast(i))); }; + bool setValue(const int i) { return (setValue(static_cast(i))); }; virtual bool setValue(const double v); virtual bool setValue(const bool t); virtual bool setValue(const std::string& v); @@ -381,7 +383,7 @@ public: using Element::getValue; bool getValue(int64_t& t) const { t = i; return (true); } using Element::setValue; - bool setValue(int64_t v) { i = v; return (true); } + bool setValue(long long int v) { i = v; return (true); } void toJSON(std::ostream& ss) const; bool equals(const Element& other) const; };