BIND 10 trac3015, updated. 0202fc5aeaa4e339d55c93eeaf83cdfaafda559a [3015] Rewrote to use boost::lexical cast to convert string to values

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jul 8 02:48:06 UTC 2013


The branch, trac3015 has been updated
       via  0202fc5aeaa4e339d55c93eeaf83cdfaafda559a (commit)
      from  5d8b4032ea2c69f3487d5af8627350e9e35e619a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0202fc5aeaa4e339d55c93eeaf83cdfaafda559a
Author: Kazunori Fujiwara <fujiwara at wide.ad.jp>
Date:   Mon Jul 8 11:43:54 2013 +0900

    [3015] Rewrote to use boost::lexical cast to convert string to values

-----------------------------------------------------------------------

Summary of changes:
 src/lib/cc/data.cc |   36 ++++++++++--------------------------
 src/lib/cc/data.h  |    6 ++++--
 2 files changed, 14 insertions(+), 28 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc
index a23f923..a48e1ce 100644
--- a/src/lib/cc/data.cc
+++ b/src/lib/cc/data.cc
@@ -28,6 +28,7 @@
 #include <climits>
 
 #include <boost/algorithm/string.hpp> // for iequals
+#include <boost/lexical_cast.hpp>
 
 #include <cmath>
 
@@ -90,7 +91,7 @@ Element::getValue(std::map<std::string, ConstElementPtr>&) 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<double>(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<int64_t>(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 d001a29..ca1c5ef 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<long long int>(i))); };
+    bool setValue(const int i) { return (setValue(static_cast<long long int>(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;
 };



More information about the bind10-changes mailing list