Revert commit 65c601e3aa895b0dd357513ef02314b86fc66173 for now.
authorCryptoManiac <balthazar@yandex.ru>
Sun, 10 Apr 2016 22:27:05 +0000 (01:27 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Sun, 10 Apr 2016 22:27:05 +0000 (01:27 +0300)
src/util.cpp
src/util.h

index 3cb5300..9fd406c 100644 (file)
@@ -437,28 +437,28 @@ bool ParseMoney(const char* pszIn, int64_t& nRet)
     return true;
 }
 
+static const int8_t phexdigit[256] =
+{
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+     0,  1,  2,  3,  4,  5,  6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
+    -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+};
+
 bool IsHex(const string& str)
 {
-    static const signed char phexdigit[256] =
-    {
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-         0,  1,  2,  3,  4,  5,  6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
-        -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-        -1, -1, -1, -1, -1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-    };
-
     for(unsigned char c :  str)
     {
         if (phexdigit[c] < 0)
@@ -467,19 +467,25 @@ bool IsHex(const string& str)
     return (str.size() > 0) && (str.size()%2 == 0);
 }
 
-vector<uint8_t> ParseHex(const string& str)
+vector<unsigned char> ParseHex(const char* psz)
 {
-    auto nLen = str.length();
-    vector<uint8_t> vchOut;
-    for(size_t nPos = 0; nPos < nLen; nPos += 2)
+    // convert hex dump to vector
+    vector<unsigned char> vch;
+    for ( ; ; )
     {
-        istringstream strm(str.substr(nPos, 2));
-        uint8_t x;
-        strm >> hex >> x;
-        vchOut.push_back(x);
+        while (isspace(*psz))
+            psz++;
+        auto c = phexdigit[(unsigned char)*psz++];
+        if (c == (signed char)-1)
+            break;
+        auto n = (c << 4);
+        c = phexdigit[(uint8_t)*psz++];
+        if (c == (int8_t)-1)
+            break;
+        n |= c;
+        vch.push_back(n);
     }
-
-    return vchOut;
+    return vch;
 }
 
 static void InterpretNegativeSetting(string name, map<string, string>& mapSettingsRet)
index b24771a..57b9f38 100644 (file)
@@ -197,7 +197,8 @@ void ParseString(const std::string& str, char c, std::vector<std::string>& v);
 std::string FormatMoney(int64_t n, bool fPlus=false);
 bool ParseMoney(const std::string& str, int64_t& nRet);
 bool ParseMoney(const char* pszIn, int64_t& nRet);
-std::vector<uint8_t> ParseHex(const std::string& str);
+std::vector<uint8_t> ParseHex(const char *str);
+inline std::vector<uint8_t> ParseHex(const std::string& str) { return ParseHex(str.c_str()); }
 bool IsHex(const std::string& str);
 std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL);
 std::string DecodeBase64(const std::string& str);