[Pkg-bitcoin-commits] [libunivalue] 62/76: Use internal, locale-independent isspace(), isdigit() implementations.

Jonas Smedegaard dr at jones.dk
Mon Apr 4 09:18:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libunivalue.

commit 2158205266aba7dbee88e307c75bb42176c991a1
Author: Jeff Garzik <jeff at bloq.com>
Date:   Sat Nov 7 09:40:26 2015 -0500

    Use internal, locale-independent isspace(), isdigit() implementations.
    
    Fixes #17
---
 .gitignore             |  1 +
 gen/gen.cpp            |  1 -
 include/univalue.h     | 18 +++++++++++++++++-
 lib/univalue.cpp       |  3 +--
 lib/univalue_read.cpp  | 25 +++++++++++++++----------
 lib/univalue_write.cpp |  1 -
 test/.gitignore        |  3 +++
 7 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/.gitignore b/.gitignore
index a7a2ca9..19e42f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ univalue-config.h*
 test-driver
 libtool
 ltmain.sh
+test-suite.log
 
 *.a
 *.la
diff --git a/gen/gen.cpp b/gen/gen.cpp
index 5e5a4d4..4a26c00 100644
--- a/gen/gen.cpp
+++ b/gen/gen.cpp
@@ -8,7 +8,6 @@
 // $ ./gen > univalue_escapes.h
 //
 
-#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 #include "univalue.h"
diff --git a/include/univalue.h b/include/univalue.h
index ac05116..13b84fd 100644
--- a/include/univalue.h
+++ b/include/univalue.h
@@ -243,8 +243,24 @@ extern enum jtokentype getJsonToken(std::string& tokenVal,
                                     unsigned int& consumed, const char *raw);
 extern const char *uvTypeName(UniValue::VType t);
 
+static inline bool json_isspace(int ch)
+{
+	switch (ch) {
+	case 0x20:
+	case 0x09:
+	case 0x0a:
+	case 0x0d:
+		return true;
+
+	default:
+		return false;
+	}
+
+	// not reached
+}
+
 extern const UniValue NullUniValue;
 
 const UniValue& find_value( const UniValue& obj, const std::string& name);
 
-#endif // __UNIVALUE_H__
\ No newline at end of file
+#endif // __UNIVALUE_H__
diff --git a/lib/univalue.cpp b/lib/univalue.cpp
index 883e865..332461c 100644
--- a/lib/univalue.cpp
+++ b/lib/univalue.cpp
@@ -4,7 +4,6 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <stdint.h>
-#include <ctype.h>
 #include <errno.h>
 #include <iomanip>
 #include <limits>
@@ -21,7 +20,7 @@ static bool ParsePrechecks(const std::string& str)
 {
     if (str.empty()) // No empty string allowed
         return false;
-    if (str.size() >= 1 && (isspace(str[0]) || isspace(str[str.size()-1]))) // No padding allowed
+    if (str.size() >= 1 && (json_isspace(str[0]) || json_isspace(str[str.size()-1]))) // No padding allowed
         return false;
     if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
         return false;
diff --git a/lib/univalue_read.cpp b/lib/univalue_read.cpp
index 6459123..be4657b 100644
--- a/lib/univalue_read.cpp
+++ b/lib/univalue_read.cpp
@@ -9,6 +9,11 @@
 
 using namespace std;
 
+static bool json_isdigit(int ch)
+{
+	return ((ch >= '0') && (ch <= '9'));
+}
+
 // convert hexadecimal string to unsigned integer
 static const char *hatoui(const char *first, const char *last,
                           unsigned int& out)
@@ -17,7 +22,7 @@ static const char *hatoui(const char *first, const char *last,
     for (; first != last; ++first)
     {
         int digit;
-        if (isdigit(*first))
+        if (json_isdigit(*first))
             digit = *first - '0';
 
         else if (*first >= 'a' && *first <= 'f')
@@ -44,7 +49,7 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
 
     const char *rawStart = raw;
 
-    while ((*raw) && (isspace(*raw)))             // skip whitespace
+    while ((*raw) && (json_isspace(*raw)))             // skip whitespace
         raw++;
 
     switch (*raw) {
@@ -113,18 +118,18 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
         const char *first = raw;
 
         const char *firstDigit = first;
-        if (!isdigit(*firstDigit))
+        if (!json_isdigit(*firstDigit))
             firstDigit++;
-        if ((*firstDigit == '0') && isdigit(firstDigit[1]))
+        if ((*firstDigit == '0') && json_isdigit(firstDigit[1]))
             return JTOK_ERR;
 
         numStr += *raw;                       // copy first char
         raw++;
 
-        if ((*first == '-') && (!isdigit(*raw)))
+        if ((*first == '-') && (!json_isdigit(*raw)))
             return JTOK_ERR;
 
-        while ((*raw) && isdigit(*raw)) {     // copy digits
+        while ((*raw) && json_isdigit(*raw)) {     // copy digits
             numStr += *raw;
             raw++;
         }
@@ -134,9 +139,9 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
             numStr += *raw;                   // copy .
             raw++;
 
-            if (!isdigit(*raw))
+            if (!json_isdigit(*raw))
                 return JTOK_ERR;
-            while ((*raw) && isdigit(*raw)) { // copy digits
+            while ((*raw) && json_isdigit(*raw)) { // copy digits
                 numStr += *raw;
                 raw++;
             }
@@ -152,9 +157,9 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
                 raw++;
             }
 
-            if (!isdigit(*raw))
+            if (!json_isdigit(*raw))
                 return JTOK_ERR;
-            while ((*raw) && isdigit(*raw)) { // copy digits
+            while ((*raw) && json_isdigit(*raw)) { // copy digits
                 numStr += *raw;
                 raw++;
             }
diff --git a/lib/univalue_write.cpp b/lib/univalue_write.cpp
index bce3997..fc528b7 100644
--- a/lib/univalue_write.cpp
+++ b/lib/univalue_write.cpp
@@ -2,7 +2,6 @@
 // Distributed under the MIT software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
-#include <ctype.h>
 #include <iomanip>
 #include <sstream>
 #include <stdio.h>
diff --git a/test/.gitignore b/test/.gitignore
index 4afa094..3d9347f 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,4 @@
 unitester
+
+*.trs
+*.log

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git



More information about the Pkg-bitcoin-commits mailing list