Browse Source

minor cleanups

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1426 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya 15 years ago
parent
commit
f8248921b2
1 changed files with 13 additions and 16 deletions
  1. 13 16
      src/lib/dns/hex.cc

+ 13 - 16
src/lib/dns/hex.cc

@@ -35,14 +35,15 @@ using namespace std;
 namespace isc {
 namespace isc {
 namespace dns {
 namespace dns {
 
 
-static const char hexdigits[] = "0123456789ABCDEF";
+namespace {
+const char hexdigits[] = "0123456789ABCDEF";
+}
 
 
 std::string
 std::string
-encodeHex(const std::vector<uint8_t>& binary)
-{
+encodeHex(const std::vector<uint8_t>& binary) {
     // calculate the resulting length.  it should be twice the
     // calculate the resulting length.  it should be twice the
     // original data length
     // original data length
-    size_t len = (binary.size() * 2);
+    const size_t len = (binary.size() * 2);
     std::ostringstream hex;
     std::ostringstream hex;
 
 
     BOOST_FOREACH(uint8_t octet, binary) {
     BOOST_FOREACH(uint8_t octet, binary) {
@@ -53,13 +54,12 @@ encodeHex(const std::vector<uint8_t>& binary)
 }
 }
 
 
 void
 void
-decodeHex(const std::string& hex, std::vector<uint8_t>& result)
-{
+decodeHex(const std::string& hex, std::vector<uint8_t>& result) {
     ostringstream comp;
     ostringstream comp;
 
 
     // compress input by removing whitespace
     // compress input by removing whitespace
-    size_t len = hex.length();
-    for (int i = 0; i < len; i++) {
+    const size_t len = hex.length();
+    for (int i = 0; i < len; ++i) {
         char c = hex.at(i);
         char c = hex.at(i);
         if (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
         if (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
             continue;
             continue;
@@ -70,7 +70,6 @@ decodeHex(const std::string& hex, std::vector<uint8_t>& result)
     istringstream iss(comp.str());
     istringstream iss(comp.str());
     result.clear();
     result.clear();
     char c1, c2;
     char c1, c2;
-    uint8_t n;
 
 
     iss.width(1);
     iss.width(1);
     if ((comp.str().length() % 2) == 1) {
     if ((comp.str().length() % 2) == 1) {
@@ -78,13 +77,12 @@ decodeHex(const std::string& hex, std::vector<uint8_t>& result)
         iss >> c2;
         iss >> c2;
 
 
         const char* pos = strchr(hexdigits, toupper(c2));
         const char* pos = strchr(hexdigits, toupper(c2));
-        if (!pos) {
-            isc_throw (BadHexString, "Invalid hex digit");
+        if (pos == NULL) {
+            isc_throw(BadHexString, "Invalid hex digit");
         }
         }
 
 
         if (!iss.eof() && !iss.bad() && !iss.fail()) {
         if (!iss.eof() && !iss.bad() && !iss.fail()) {
-            n = pos - hexdigits;
-            result.push_back(n);
+            result.push_back(pos - hexdigits);
         }
         }
     }
     }
     while (!iss.eof()) {
     while (!iss.eof()) {
@@ -98,11 +96,10 @@ decodeHex(const std::string& hex, std::vector<uint8_t>& result)
         const char* pos1 = strchr(hexdigits, toupper(c1));
         const char* pos1 = strchr(hexdigits, toupper(c1));
         const char* pos2 = strchr(hexdigits, toupper(c2));
         const char* pos2 = strchr(hexdigits, toupper(c2));
         if (!pos1 || !pos2) {
         if (!pos1 || !pos2) {
-            isc_throw (BadHexString, "Invalid hex digit");
+            isc_throw(BadHexString, "Invalid hex digit");
         }
         }
 
 
-        n = (pos1 - hexdigits) << 4;
-        n |= (pos2 - hexdigits);
+        const uint8_t n = ((pos1 - hexdigits) << 4) | (pos2 - hexdigits);
         result.push_back(n);
         result.push_back(n);
     }
     }
 }
 }