src: Enabling -Werror in debug mode and some style updates

Several important warnings are still getting suppressed, because of
CryptoPP library

Change-Id: I8fb3d938544ecc38c65529262504dc753124bafd
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 9cb1a0f..441bc99 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -195,7 +195,7 @@
       if (end - begin < 2)
         return false;
 
-      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin);
       begin += 2;
       number = be16toh(value);
     }
@@ -204,7 +204,7 @@
       if (end - begin < 4)
         return false;
 
-      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin);
       begin += 4;
       number = be32toh(value);
     }
@@ -227,8 +227,8 @@
 readType(InputIterator& begin, const InputIterator& end, uint32_t& type)
 {
   uint64_t number;
-  bool ok = readVarNumber(begin, end, number);
-  if (number > std::numeric_limits<uint32_t>::max())
+  bool isOk = readVarNumber(begin, end, number);
+  if (!isOk || number > std::numeric_limits<uint32_t>::max())
     {
       return false;
     }
@@ -255,7 +255,7 @@
       if (end - begin < 2)
         throw Error("Insufficient data during TLV processing");
 
-      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin);
       begin += 2;
       return be16toh(value);
     }
@@ -264,7 +264,7 @@
       if (end - begin < 4)
         throw Error("Insufficient data during TLV processing");
 
-      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin);
       begin += 4;
       return be32toh(value);
     }
@@ -423,7 +423,7 @@
       if (end - begin < 2)
         throw Error("Insufficient data during TLV processing");
 
-      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin);
       begin += 2;
       return be16toh(value);
     }
@@ -432,7 +432,7 @@
       if (end - begin < 4)
         throw Error("Insufficient data during TLV processing");
 
-      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin); // kind of dangerous... but should be efficient
+      uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin);
       begin += 4;
       return be32toh(value);
     }
diff --git a/src/interest.cpp b/src/interest.cpp
index 229e0fb..a49ee1f 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -27,20 +27,24 @@
 bool
 Interest::matchesName(const Name &name) const
 {
+  if (name.size() < m_name.size())
+    return false;
+
   if (!m_name.isPrefixOf(name))
     return false;
 
   if (getMinSuffixComponents() >= 0 &&
     // Add 1 for the implicit digest.
-      !(name.size() + 1 - m_name.size() >= getMinSuffixComponents()))
+      !(name.size() + 1 - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
     return false;
 
   if (getMaxSuffixComponents() >= 0 &&
     // Add 1 for the implicit digest.
-      !(name.size() + 1 - m_name.size() <= getMaxSuffixComponents()))
+      !(name.size() + 1 - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
     return false;
 
-  if (!getExclude().empty() && name.size() > m_name.size() &&
+  if (!getExclude().empty() &&
+      name.size() > m_name.size() &&
       getExclude().isExcluded(name[m_name.size()]))
     return false;
 
diff --git a/src/name-component.cpp b/src/name-component.cpp
deleted file mode 100644
index 78f32c9..0000000
--- a/src/name-component.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "common.hpp"
-
-#include "name-component.hpp"
-
-#include "util/time.hpp"
-#include "util/string-helper.hpp"
-
-namespace ndn {
-namespace name {
-
-Component 
-Component::fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
-{
-  std::string trimmedString(escapedString + beginOffset, escapedString + endOffset);
-  trim(trimmedString);
-  std::string value = unescape(trimmedString);
-        
-  if (value.find_first_not_of(".") == std::string::npos) {
-    // Special case for component of only periods.  
-    if (value.size() <= 2)
-      // Zero, one or two periods is illegal.  Ignore this component.
-      return Component();
-    else
-      // Remove 3 periods.
-      return Component((const uint8_t *)&value[3], value.size() - 3); 
-  }
-  else
-    return Component((const uint8_t *)&value[0], value.size()); 
-}
-
-void
-Component::toEscapedString(std::ostream& result) const
-{
-  const uint8_t *valuePtr = value();
-  size_t valueSize = value_size();
-  
-  bool gotNonDot = false;
-  for (unsigned i = 0; i < valueSize; ++i) {
-    if (valuePtr[i] != 0x2e) {
-      gotNonDot = true;
-      break;
-    }
-  }
-  if (!gotNonDot) {
-    // Special case for component of zero or more periods.  Add 3 periods.
-    result << "...";
-    for (size_t i = 0; i < valueSize; ++i)
-      result << '.';
-  }
-  else {
-    // In case we need to escape, set to upper case hex and save the previous flags.
-    std::ios::fmtflags saveFlags = result.flags(std::ios::hex | std::ios::uppercase);
-    
-    for (size_t i = 0; i < valueSize; ++i) {
-      uint8_t x = valuePtr[i];
-      // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
-      if ((x >= 0x30 && x <= 0x39) || (x >= 0x41 && x <= 0x5a) ||
-          (x >= 0x61 && x <= 0x7a) || x == 0x2b || x == 0x2d || 
-          x == 0x2e || x == 0x5f)
-        result << x;
-      else {
-        result << '%';
-        if (x < 16)
-          result << '0';
-        result << (unsigned int)x;
-      }
-    }
-    
-    // Restore.
-    result.flags(saveFlags);
-  }  
-}
-
-int
-Component::compare(const Component& other) const
-{
-  // Imitate ndn_Exclude_compareComponents.
-  if (value_size() < other.value_size())
-    return -1;
-  if (value_size() > other.value_size())
-    return 1;
-
-  if (value_size() == 0)
-    return 0;
-  
-  // The components are equal length.  Just do a byte compare.  
-  return std::memcmp(value(), other.value(), value_size());
-}
-
-// const Block &
-// wireEncode() const
-// {
-  
-// }
-
-} // namespace name
-} // namespace ndn
diff --git a/src/name-component.hpp b/src/name-component.hpp
index 238c2be..9ea09c5 100644
--- a/src/name-component.hpp
+++ b/src/name-component.hpp
@@ -13,6 +13,7 @@
 #include "common.hpp"
 #include "encoding/block.hpp"
 #include "encoding/encoding-buffer.hpp"
+#include "util/string-helper.hpp"
 
 namespace ndn {
 namespace name {
@@ -24,101 +25,77 @@
 {
 public:
   /// @brief Error that can be thrown from the block
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
-  
+  struct Error : public std::runtime_error {
+    Error(const std::string& what) : std::runtime_error(what) {}
+  };
+
   /**
    * Create a new Name::Component with a null value.
    */
-  Component()
-    : Block(Tlv::NameComponent)
-  {    
-  }
+  Component();
 
   /**
    * @brief Directly create component from wire block
    *
-   * ATTENTION  wire MUST BE of type Tlv::Component. Any other value would cause an exception
+   * @throws Error if wire.type() is not Tlv::Component
    */
-  Component(const Block& wire)
-    : Block(wire)
-  {
-    if (type() != Tlv::NameComponent)
-      throw Error("Constructing name component from non name component TLV wire block");
-  }
-  
+  Component(const Block& wire);
+
   /**
    * Create a new Name::Component, taking another pointer to the Blob value.
    * @param value A blob with a pointer to an immutable array.  The pointer is copied.
    */
-  Component(const ConstBufferPtr &buffer)
-    : Block (Tlv::NameComponent, buffer)
-  {
-  }
-  
+  Component(const ConstBufferPtr& buffer);
+
   /**
    * Create a new Name::Component, copying the given value.
    * @param value The value byte array.
    */
-  Component(const Buffer& value) 
-    : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(value)))
-  {
-  }
+  Component(const Buffer& value);
 
   /**
    * Create a new Name::Component, copying the given value.
    * @param value Pointer to the value byte array.
    * @param valueLen Length of value.
    */
-  Component(const uint8_t *value, size_t valueLen) 
-    : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(value, valueLen)))
-  {
-  }
+  Component(const uint8_t *value, size_t valueLen);
 
   template<class InputIterator>
-  Component(InputIterator begin, InputIterator end)
-    : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(begin, end)))
-  {
-  }
+  Component(InputIterator begin, InputIterator end);
 
   explicit
-  Component(const char *str)
-    : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(str, ::strlen(str))))
-  {
-  }
+  Component(const char *str);
 
   explicit
-  Component(const std::string& str)
-    : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(str.begin(), str.end())))
-  {
-  }
-  
+  Component(const std::string& str);
+
   /**
    * @brief Fast encoding or block size estimation
    */
   template<bool T>
   size_t
-  wireEncode(EncodingImpl<T> &block) const;
-  
+  wireEncode(EncodingImpl<T>& block) const;
+
   /**
    * Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
-   * If the escaped string is "", "." or ".." then return a Blob with a null pointer, 
+   * If the escaped string is "", "." or ".." then return a Blob with a null pointer,
    * which means the component should be skipped in a URI name.
    * @param escapedString The escaped string.  It does not need to be null-terminated because we only scan to endOffset.
    * @param beginOffset The offset in escapedString of the beginning of the portion to decode.
    * @param endOffset The offset in escapedString of the end of the portion to decode.
    * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
    */
-  static Component 
+  static Component
   fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
 
   /**
    * Make a Blob value by decoding the escapedString according to the NDN URI Scheme.
-   * If the escaped string is "", "." or ".." then return a Blob with a null pointer, 
+   * If the escaped string is "", "." or ".." then return a Blob with a null pointer,
    * which means the component should be skipped in a URI name.
    * @param escapedString The null-terminated escaped string.
    * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
    */
-  static Component 
+  static Component
   fromEscapedString(const char *escapedString)
   {
     return fromEscapedString(escapedString, 0, ::strlen(escapedString));
@@ -126,12 +103,12 @@
 
   /**
    * Make a Blob value by decoding the escapedString according to the NDN URI Scheme.
-   * If the escaped string is "", "." or ".." then return a Blob with a null pointer, 
+   * If the escaped string is "", "." or ".." then return a Blob with a null pointer,
    * which means the component should be skipped in a URI name.
    * @param escapedString The escaped string.
    * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
    */
-  static Component 
+  static Component
   fromEscapedString(const std::string& escapedString)
   {
     return fromEscapedString(escapedString.c_str());
@@ -143,9 +120,9 @@
    * @param value the buffer with the value to escape
    * @param result the string stream to write to.
    */
-  void 
+  void
   toEscapedString(std::ostream& result) const;
-  
+
   /**
    * Convert the value by escaping characters according to the NDN URI Scheme.
    * This also adds "..." to a value with zero or more ".".
@@ -171,7 +148,7 @@
   {
     return toEscapedString();
   }
-    
+
   /**
    * @brief Interpret this name component as nonNegativeInteger
    *
@@ -202,7 +179,7 @@
    * @param number The non-negative number
    * @return The component value.
    */
-  static Component 
+  static Component
   fromNumber(uint64_t number);
 
   /**
@@ -228,14 +205,14 @@
   {
     return !hasValue();
   }
-    
+
   /**
    * Check if this is the same component as other.
    * @param other The other Component to compare with.
    * @return true if the components are equal, otherwise false.
    */
   bool
-  operator == (const Component& other) const { return equals(other); }
+  operator==(const Component& other) const { return equals(other); }
 
   /**
    * Check if this is not the same component as other.
@@ -243,8 +220,8 @@
    * @return true if the components are not equal, otherwise false.
    */
   bool
-  operator != (const Component& other) const { return !equals(other); }
-    
+  operator!=(const Component& other) const { return !equals(other); }
+
   /**
    * Compare this to the other Component using NDN canonical ordering.
    * @param other The other Component to compare with.
@@ -255,24 +232,6 @@
    */
   int
   compare(const Component& other) const;
-  
-  /**
-   * Return true if this is less than or equal to the other Component in the NDN canonical ordering.
-   * @param other The other Component to compare with.
-   *
-   * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
-   */
-  bool
-  operator <= (const Component& other) const { return compare(other) <= 0; }
-  
-  /**
-   * Return true if this is less than the other Component in the NDN canonical ordering.
-   * @param other The other Component to compare with.
-   *
-   * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
-   */
-  bool
-  operator < (const Component& other) const { return compare(other) < 0; }
 
   /**
    * Return true if this is less than or equal to the other Component in the NDN canonical ordering.
@@ -281,7 +240,25 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator >= (const Component& other) const { return compare(other) >= 0; }
+  operator<=(const Component& other) const { return compare(other) <= 0; }
+
+  /**
+   * Return true if this is less than the other Component in the NDN canonical ordering.
+   * @param other The other Component to compare with.
+   *
+   * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
+   */
+  bool
+  operator<(const Component& other) const { return compare(other) < 0; }
+
+  /**
+   * Return true if this is less than or equal to the other Component in the NDN canonical ordering.
+   * @param other The other Component to compare with.
+   *
+   * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
+   */
+  bool
+  operator>=(const Component& other) const { return compare(other) >= 0; }
 
   /**
    * Return true if this is greater than the other Component in the NDN canonical ordering.
@@ -290,21 +267,137 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator > (const Component& other) const { return compare(other) > 0; }
+  operator>(const Component& other) const { return compare(other) > 0; }
 
-  // 
+  //
   // !!! MUST NOT INCLUDE ANY DATA HERE !!!
   //
   // This class is just a helper and is directly reinterpret_cast'ed from Block
 };
 
-inline std::ostream &
-operator << (std::ostream &os, const Component &component)
+inline std::ostream&
+operator << (std::ostream& os, const Component& component)
 {
   component.toEscapedString(os);
   return os;
 }
 
+inline
+Component::Component()
+  : Block(Tlv::NameComponent)
+{
+}
+
+inline
+Component::Component(const Block& wire)
+  : Block(wire)
+{
+  if (type() != Tlv::NameComponent)
+    throw Error("Constructing name component from non name component TLV wire block");
+}
+
+inline
+Component::Component(const ConstBufferPtr& buffer)
+  : Block (Tlv::NameComponent, buffer)
+{
+}
+
+inline
+Component::Component(const Buffer& value)
+  : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(value)))
+{
+}
+
+inline
+Component::Component(const uint8_t *value, size_t valueLen)
+  : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(value, valueLen)))
+{
+}
+
+template<class InputIterator>
+inline
+Component::Component(InputIterator begin, InputIterator end)
+  : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(begin, end)))
+{
+}
+
+inline
+Component::Component(const char *str)
+  : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(str, ::strlen(str))))
+{
+}
+
+inline
+Component::Component(const std::string& str)
+  : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(str.begin(), str.end())))
+{
+}
+
+
+inline Component
+Component::fromEscapedString(const char* escapedString, size_t beginOffset, size_t endOffset)
+{
+  std::string trimmedString(escapedString + beginOffset, escapedString + endOffset);
+  trim(trimmedString);
+  std::string value = unescape(trimmedString);
+
+  if (value.find_first_not_of(".") == std::string::npos) {
+    // Special case for component of only periods.
+    if (value.size() <= 2)
+      // Zero, one or two periods is illegal.  Ignore this component.
+      return Component();
+    else
+      // Remove 3 periods.
+      return Component((const uint8_t *)&value[3], value.size() - 3);
+  }
+  else
+    return Component((const uint8_t *)&value[0], value.size());
+}
+
+
+inline void
+Component::toEscapedString(std::ostream& result) const
+{
+  const uint8_t *valuePtr = value();
+  size_t valueSize = value_size();
+
+  bool gotNonDot = false;
+  for (unsigned i = 0; i < valueSize; ++i) {
+    if (valuePtr[i] != 0x2e) {
+      gotNonDot = true;
+      break;
+    }
+  }
+  if (!gotNonDot) {
+    // Special case for component of zero or more periods.  Add 3 periods.
+    result << "...";
+    for (size_t i = 0; i < valueSize; ++i)
+      result << '.';
+  }
+  else {
+    // In case we need to escape, set to upper case hex and save the previous flags.
+    std::ios::fmtflags saveFlags = result.flags(std::ios::hex | std::ios::uppercase);
+
+    for (size_t i = 0; i < valueSize; ++i) {
+      uint8_t x = valuePtr[i];
+      // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
+      if ((x >= 0x30 && x <= 0x39) || (x >= 0x41 && x <= 0x5a) ||
+          (x >= 0x61 && x <= 0x7a) || x == 0x2b || x == 0x2d ||
+          x == 0x2e || x == 0x5f)
+        result << x;
+      else {
+        result << '%';
+        if (x < 16)
+          result << '0';
+        result << (unsigned int)x;
+      }
+    }
+
+    // Restore.
+    result.flags(saveFlags);
+  }
+}
+
 
 inline Component
 Component::fromNumber(uint64_t number)
@@ -334,6 +427,23 @@
   return toNumber();
 }
 
+inline int
+Component::compare(const Component& other) const
+{
+  // Imitate ndn_Exclude_compareComponents.
+  if (value_size() < other.value_size())
+    return -1;
+  if (value_size() > other.value_size())
+    return 1;
+
+  if (value_size() == 0)
+    return 0;
+
+  // The components are equal length.  Just do a byte compare.
+  return std::memcmp(value(), other.value(), value_size());
+}
+
+
 template<bool T>
 inline size_t
 Component::wireEncode(EncodingImpl<T>& block) const
diff --git a/src/name.cpp b/src/name.cpp
deleted file mode 100644
index cb8759b..0000000
--- a/src/name.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "common.hpp"
-
-#include "name.hpp"
-
-#include <algorithm>
-#include <cstring>
-
-#include "util/time.hpp"
-#include "util/string-helper.hpp"
-
-namespace ndn {
-
-void 
-Name::set(const char *uri_cstr) 
-{
-  clear();
-  
-  std::string uri = uri_cstr;
-  trim(uri);
-  if (uri.size() == 0)
-    return;
-
-  size_t iColon = uri.find(':');
-  if (iColon != std::string::npos) {
-    // Make sure the colon came before a '/'.
-    size_t iFirstSlash = uri.find('/');
-    if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
-      // Omit the leading protocol such as ndn:
-      uri.erase(0, iColon + 1);
-      trim(uri);
-    }
-  }
-    
-  // Trim the leading slash and possibly the authority.
-  if (uri[0] == '/') {
-    if (uri.size() >= 2 && uri[1] == '/') {
-      // Strip the authority following "//".
-      size_t iAfterAuthority = uri.find('/', 2);
-      if (iAfterAuthority == std::string::npos)
-        // Unusual case: there was only an authority.
-        return;
-      else {
-        uri.erase(0, iAfterAuthority + 1);
-        trim(uri);
-      }
-    }
-    else {
-      uri.erase(0, 1);
-      trim(uri);
-    }
-  }
-
-  size_t iComponentStart = 0;
-  
-  // Unescape the components.
-  while (iComponentStart < uri.size()) {
-    size_t iComponentEnd = uri.find("/", iComponentStart);
-    if (iComponentEnd == std::string::npos)
-      iComponentEnd = uri.size();
-    
-    Component component = Component::fromEscapedString(&uri[0], iComponentStart, iComponentEnd);
-    // Ignore illegal components.  This also gets rid of a trailing '/'.
-    if (!component.empty())
-      append(Component(component));
-    
-    iComponentStart = iComponentEnd + 1;
-  }
-}
-
-Name&
-Name::append(const Name& name)
-{
-  if (&name == this)
-    // Copying from this name, so need to make a copy first.
-    return append(Name(name));
-
-  for (size_t i = 0; i < name.size(); ++i)
-    append(name.at(i));
-  
-  return *this;
-}
-
-Name
-Name::getSubName(size_t iStartComponent, size_t nComponents) const
-{
-  Name result;
-  
-  size_t iEnd = iStartComponent + nComponents;
-  for (size_t i = iStartComponent; i < iEnd && i < size(); ++i)
-    result.append(at(i));
-  
-  return result;
-}
-
-Name
-Name::getSubName(size_t iStartComponent) const
-{
-  Name result;
-  
-  for (size_t i = iStartComponent; i < size(); ++i)
-    result.append(at(i));
-  
-  return result;
-}
-
-bool 
-Name::equals(const Name& name) const
-{
-  if (size() != name.size())
-    return false;
-
-  for (size_t i = 0; i < size(); ++i) {
-    if (at(i) != name.at(i))
-      return false;
-  }
-
-  return true;
-}
-
-bool 
-Name::isPrefixOf(const Name& name) const
-{
-  // This name is longer than the name we are checking it against.
-  if (size() > name.size())
-    return false;
-
-  // Check if at least one of given components doesn't match.
-  for (size_t i = 0; i < size(); ++i) {
-    if (at(i) != name.at(i))
-      return false;
-  }
-
-  return true;
-}
-
-
-int
-Name::compare(const Name& other) const
-{
-  for (size_t i = 0; i < size() && i < other.size(); ++i) {
-    int comparison = at(i).compare(other.at(i));
-    if (comparison == 0)
-      // The components at this index are equal, so check the next components.
-      continue;
-    
-    // Otherwise, the result is based on the components at this index.
-    return comparison;
-  }
-  
-  // The components up to min(this.size(), other.size()) are equal, so the shorter name is less.
-  if (size() < other.size())
-    return -1;
-  else if (size() > other.size())
-    return 1;
-  else
-    return 0;
-}
-
-std::ostream&
-operator << (std::ostream& os, const Name& name)
-{
-  if (name.empty())
-    {
-      os << "/";
-    }
-  else
-    {
-      for (Name::const_iterator i = name.begin(); i != name.end(); i++) {
-        os << "/";
-        i->toEscapedString(os);
-      }
-    }
-  
-  return os;
-}
-
-} // namespace ndn
diff --git a/src/name.hpp b/src/name.hpp
index aea084b..5a8dfcf 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -26,7 +26,11 @@
 class Name : public ptr_lib::enable_shared_from_this<Name> {
 public:
   /// @brief Error that can be thrown from the block
-  struct Error : public name::Component::Error { Error(const std::string &what) : name::Component::Error(what) {} };
+  class Error : public name::Component::Error {
+  public:
+    Error(const std::string& what)
+      : name::Component::Error(what) {}
+  };
 
   typedef name::Component Component;
 
@@ -65,7 +69,7 @@
    * @endcode
    */
   explicit
-  Name(const Block &wire)
+  Name(const Block& wire)
   {
     m_nameBlock = wire;
     m_nameBlock.parse();
@@ -94,13 +98,13 @@
    */
   template<bool T>
   size_t
-  wireEncode(EncodingImpl<T> &block) const;
+  wireEncode(EncodingImpl<T>& block) const;
 
-  const Block &
+  const Block&
   wireEncode() const;
 
   void
-  wireDecode(const Block &wire);
+  wireDecode(const Block& wire);
 
   /**
    * @brief Check if already has wire
@@ -130,7 +134,7 @@
    * @return This name so that you can chain calls to append.
    */
   Name&
-  append(const uint8_t *value, size_t valueLength)
+  append(const uint8_t* value, size_t valueLength)
   {
     m_nameBlock.push_back(Component(value, valueLength));
     return *this;
@@ -148,26 +152,15 @@
     return *this;
   }
 
-  // /**
-  //  * Append a new component, copying from value.
-  //  * @return This name so that you can chain calls to append.
-  //  */
-  // Name&
-  // append(const Buffer& value)
-  // {
-  //   m_nameBlock.push_back(value);
-  //   return *this;
-  // }
-
   Name&
-  append(const ConstBufferPtr &value)
+  append(const ConstBufferPtr& value)
   {
     m_nameBlock.push_back(value);
     return *this;
   }
 
   Name&
-  append(const Component &value)
+  append(const Component& value)
   {
     m_nameBlock.push_back(value);
     return *this;
@@ -181,14 +174,14 @@
    * converted from string, each having different outcomes
    */
   Name&
-  append(const char *value)
+  append(const char* value)
   {
     m_nameBlock.push_back(Component(value));
     return *this;
   }
 
   Name&
-  append(const Block &value)
+  append(const Block& value)
   {
     if (value.type() == Tlv::NameComponent)
       m_nameBlock.push_back(value);
@@ -310,12 +303,6 @@
   bool
   isPrefixOf(const Name& name) const;
 
-  bool
-  match(const Name& name) const
-  {
-    return isPrefixOf(name);
-  }
-
   //
   // vector equivalent interface.
   //
@@ -348,7 +335,7 @@
   }
 
   const Component&
-  operator [] (ssize_t i) const
+  operator[](ssize_t i) const
   {
     return get(i);
   }
@@ -364,7 +351,8 @@
   const Component&
   at(ssize_t i) const
   {
-    if ((i >= 0 && i >= size()) || (i < 0 && i < -size()))
+    if ((i >= 0 && static_cast<size_t>(i) >= size()) ||
+        (i < 0  && static_cast<size_t>(-i) > size()))
       throw Error("Requested component does not exist (out of bounds)");
 
     return get(i);
@@ -395,7 +383,7 @@
    * @param component The component of type T.
    */
   template<class T> void
-  push_back(const T &component)
+  push_back(const T& component)
   {
     append(component);
   }
@@ -406,7 +394,7 @@
    * @return true if the names are equal, otherwise false.
    */
   bool
-  operator == (const Name &name) const { return equals(name); }
+  operator==(const Name& name) const { return equals(name); }
 
   /**
    * Check if this name has the same component count and components as the given name.
@@ -414,7 +402,7 @@
    * @return true if the names are not equal, otherwise false.
    */
   bool
-  operator != (const Name &name) const { return !equals(name); }
+  operator!=(const Name& name) const { return !equals(name); }
 
   /**
    * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
@@ -423,7 +411,7 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator <= (const Name& other) const { return compare(other) <= 0; }
+  operator<=(const Name& other) const { return compare(other) <= 0; }
 
   /**
    * Return true if this is less than the other Name in the NDN canonical ordering.
@@ -432,7 +420,7 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator < (const Name& other) const { return compare(other) < 0; }
+  operator<(const Name& other) const { return compare(other) < 0; }
 
   /**
    * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
@@ -441,7 +429,7 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator >= (const Name& other) const { return compare(other) >= 0; }
+  operator>=(const Name& other) const { return compare(other) >= 0; }
 
   /**
    * Return true if this is greater than the other Name in the NDN canonical ordering.
@@ -450,7 +438,7 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator > (const Name& other) const { return compare(other) > 0; }
+  operator>(const Name& other) const { return compare(other) > 0; }
 
   //
   // Iterator interface to name components.
@@ -498,14 +486,21 @@
   mutable Block m_nameBlock;
 };
 
-std::ostream&
-operator<<(std::ostream& os, const Name& name);
-
-inline Name&
-Name::appendVersion()
+inline std::ostream&
+operator<<(std::ostream& os, const Name& name)
 {
-  appendNumber(time::toUnixTimestamp(time::system_clock::now()).count());
-  return *this;
+  if (name.empty())
+    {
+      os << "/";
+    }
+  else
+    {
+      for (Name::const_iterator i = name.begin(); i != name.end(); i++) {
+        os << "/";
+        i->toEscapedString(os);
+      }
+    }
+  return os;
 }
 
 inline std::string
@@ -526,25 +521,181 @@
   return is;
 }
 
+
+inline void
+Name::set(const char* uri_cstr)
+{
+  clear();
+
+  std::string uri = uri_cstr;
+  trim(uri);
+  if (uri.size() == 0)
+    return;
+
+  size_t iColon = uri.find(':');
+  if (iColon != std::string::npos) {
+    // Make sure the colon came before a '/'.
+    size_t iFirstSlash = uri.find('/');
+    if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
+      // Omit the leading protocol such as ndn:
+      uri.erase(0, iColon + 1);
+      trim(uri);
+    }
+  }
+
+  // Trim the leading slash and possibly the authority.
+  if (uri[0] == '/') {
+    if (uri.size() >= 2 && uri[1] == '/') {
+      // Strip the authority following "//".
+      size_t iAfterAuthority = uri.find('/', 2);
+      if (iAfterAuthority == std::string::npos)
+        // Unusual case: there was only an authority.
+        return;
+      else {
+        uri.erase(0, iAfterAuthority + 1);
+        trim(uri);
+      }
+    }
+    else {
+      uri.erase(0, 1);
+      trim(uri);
+    }
+  }
+
+  size_t iComponentStart = 0;
+
+  // Unescape the components.
+  while (iComponentStart < uri.size()) {
+    size_t iComponentEnd = uri.find("/", iComponentStart);
+    if (iComponentEnd == std::string::npos)
+      iComponentEnd = uri.size();
+
+    Component component = Component::fromEscapedString(&uri[0], iComponentStart, iComponentEnd);
+    // Ignore illegal components.  This also gets rid of a trailing '/'.
+    if (!component.empty())
+      append(Component(component));
+
+    iComponentStart = iComponentEnd + 1;
+  }
+}
+
+inline Name&
+Name::append(const Name& name)
+{
+  if (&name == this)
+    // Copying from this name, so need to make a copy first.
+    return append(Name(name));
+
+  for (size_t i = 0; i < name.size(); ++i)
+    append(name.at(i));
+
+  return *this;
+}
+
+inline Name&
+Name::appendVersion()
+{
+  appendNumber(time::toUnixTimestamp(time::system_clock::now()).count());
+  return *this;
+}
+
+inline Name
+Name::getSubName(size_t iStartComponent, size_t nComponents) const
+{
+  Name result;
+
+  size_t iEnd = iStartComponent + nComponents;
+  for (size_t i = iStartComponent; i < iEnd && i < size(); ++i)
+    result.append(at(i));
+
+  return result;
+}
+
+inline Name
+Name::getSubName(size_t iStartComponent) const
+{
+  Name result;
+
+  for (size_t i = iStartComponent; i < size(); ++i)
+    result.append(at(i));
+
+  return result;
+}
+
+inline bool
+Name::equals(const Name& name) const
+{
+  if (size() != name.size())
+    return false;
+
+  for (size_t i = 0; i < size(); ++i) {
+    if (at(i) != name.at(i))
+      return false;
+  }
+
+  return true;
+}
+
+inline bool
+Name::isPrefixOf(const Name& name) const
+{
+  // This name is longer than the name we are checking it against.
+  if (size() > name.size())
+    return false;
+
+  // Check if at least one of given components doesn't match.
+  for (size_t i = 0; i < size(); ++i) {
+    if (at(i) != name.at(i))
+      return false;
+  }
+
+  return true;
+}
+
+
+inline int
+Name::compare(const Name& other) const
+{
+  for (size_t i = 0; i < size() && i < other.size(); ++i) {
+    int comparison = at(i).compare(other.at(i));
+    if (comparison == 0)
+      // The components at this index are equal, so check the next components.
+      continue;
+
+    // Otherwise, the result is based on the components at this index.
+    return comparison;
+  }
+
+  // The components up to min(this.size(), other.size()) are equal, so the shorter name is less.
+  if (size() < other.size())
+    return -1;
+  else if (size() > other.size())
+    return 1;
+  else
+    return 0;
+}
+
+
+
 template<bool T>
 inline size_t
 Name::wireEncode(EncodingImpl<T>& blk) const
 {
   size_t total_len = 0;
 
-  for (const_reverse_iterator i = rbegin ();
-       i != rend ();
+  for (const_reverse_iterator i = rbegin();
+       i != rend();
        ++i)
     {
-      total_len += i->wireEncode (blk);
+      total_len += i->wireEncode(blk);
     }
 
-  total_len += blk.prependVarNumber (total_len);
-  total_len += blk.prependVarNumber (Tlv::Name);
+  total_len += blk.prependVarNumber(total_len);
+  total_len += blk.prependVarNumber(Tlv::Name);
   return total_len;
 }
 
-inline const Block &
+inline const Block&
 Name::wireEncode() const
 {
   if (m_nameBlock.hasWire())
@@ -563,7 +714,7 @@
 }
 
 inline void
-Name::wireDecode(const Block &wire)
+Name::wireDecode(const Block& wire)
 {
   if (wire.type() != Tlv::Name)
     throw Tlv::Error("Unexpected TLV type when decoding Name");
diff --git a/src/security/identity-certificate.cpp b/src/security/identity-certificate.cpp
index 5fddbfc..b4d5cb5 100644
--- a/src/security/identity-certificate.cpp
+++ b/src/security/identity-certificate.cpp
@@ -17,9 +17,8 @@
 bool
 IdentityCertificate::isCorrectName(const Name& name)
 {
-  int i = name.size() - 1;
-  
   string idString("ID-CERT");
+  int i = name.size() - 1;
   for (; i >= 0; i--) {
     if(name.get(i).toEscapedString() == idString)
       break;
@@ -28,7 +27,7 @@
   if (i < 0)
     return false;
   
-  int keyIdx = 0;
+  size_t keyIdx = 0;
   string keyString("KEY");
   for (; keyIdx < name.size(); keyIdx++) {
     if(name.get(keyIdx).toEscapedString() == keyString)
@@ -59,11 +58,11 @@
 Name
 IdentityCertificate::certificateNameToPublicKeyName(const Name& certificateName)
 {
-  int i = certificateName.size() - 1;
   string idString("ID-CERT");
   bool foundIdString = false;
-  for (; i >= 0; i--) {
-    if (certificateName.get(i).toEscapedString() == idString)
+  size_t idCertComponentIndex = certificateName.size() - 1;
+  for (; idCertComponentIndex + 1 > 0; --idCertComponentIndex) {
+    if (certificateName.get(idCertComponentIndex).toEscapedString() == idString)
       {
         foundIdString = true;
         break;
@@ -73,11 +72,12 @@
   if(!foundIdString)
     throw Error("Incorrect identity certificate name " + certificateName.toUri());
     
-  Name tmpName = certificateName.getSubName(0, i);    
+  Name tmpName = certificateName.getSubName(0, idCertComponentIndex);
   string keyString("KEY");
   bool foundKeyString = false;
-  for (i = 0; i < tmpName.size(); i++) {
-    if (tmpName.get(i).toEscapedString() == keyString)
+  size_t keyComponentIndex = 0;
+  for (; keyComponentIndex < tmpName.size(); keyComponentIndex++) {
+    if (tmpName.get(keyComponentIndex).toEscapedString() == keyString)
       {
         foundKeyString = true;
         break;
@@ -86,8 +86,11 @@
 
   if(!foundKeyString)
     throw Error("Incorrect identity certificate name " + certificateName.toUri());
-  
-  return tmpName.getSubName(0, i).append(tmpName.getSubName(i + 1, tmpName.size() - i - 1));
+
+  return tmpName
+           .getSubName(0, keyComponentIndex)
+           .append(tmpName.getSubName(keyComponentIndex + 1,
+                                      tmpName.size() - keyComponentIndex - 1));
 }
 
 } // namespace ndn
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index aeb34dd..393355f 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -337,8 +337,8 @@
 
 //   sqlite3_stmt *statement;
 //   sqlite3_prepare_v2(m_database, 
-//                       "INSERT OR REPLACE INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data)\
-//                        values (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
+//                       "INSERT OR REPLACE INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data) "
+//                        "VALUES (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
 //                       -1, &statement, 0);
 
 //   _LOG_DEBUG("certName: " << certificateName);
diff --git a/src/security/validator.cpp b/src/security/validator.cpp
index 82de103..be166e5 100644
--- a/src/security/validator.cpp
+++ b/src/security/validator.cpp
@@ -249,7 +249,7 @@
           const uint8_t* p1 = buffer->buf();
           const uint8_t* p2 = sigValue.value();
 
-          for(int i = 0; i < crypto::SHA256_DIGEST_SIZE; i++)
+          for(size_t i = 0; i < crypto::SHA256_DIGEST_SIZE; i++)
             if(p1[i] != p2[i]) 
               return false;
           return true;
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index 5ae5f35..e2eabe8 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -30,9 +30,6 @@
 protected:
   virtual void 
   compile();
-    
-private:
-  int m_refNum;
 };
 
 } // namespace ndn
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index b102316..50cb8de 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -72,7 +72,7 @@
   m_pseudoMatcher.clear();
   m_pseudoMatcher.push_back(ptr_lib::make_shared<RegexPseudoMatcher>());
 
-  for (int i = 1; i < m_componentRegex.mark_count(); i++)
+  for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
     {
       ptr_lib::shared_ptr<RegexPseudoMatcher> pMatcher = ptr_lib::make_shared<RegexPseudoMatcher>();
       m_pseudoMatcher.push_back(pMatcher);
@@ -102,7 +102,7 @@
       std::string targetStr = name.get(offset).toEscapedString();
       if(boost::regex_match(targetStr, subResult, m_componentRegex))
         {
-          for (int i = 1; i < m_componentRegex.mark_count(); i++)
+          for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
             {
               m_pseudoMatcher[i]->resetMatchResult();
               m_pseudoMatcher[i]->setMatchResult(subResult[i]);
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index ffb4c6d..857c59e 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -107,9 +107,9 @@
 inline void 
 RegexComponentSetMatcher::compileSingleComponent()
 {
-  int end = extractComponent(1);
+  size_t end = extractComponent(1);
 
-  if(m_expr.size() != end)
+  if (m_expr.size() != end)
     {
       throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ")
                                 + m_expr);
diff --git a/src/util/regex/regex-matcher.hpp b/src/util/regex/regex-matcher.hpp
index baa8bf3..0d34311 100644
--- a/src/util/regex/regex-matcher.hpp
+++ b/src/util/regex/regex-matcher.hpp
@@ -66,7 +66,7 @@
 
 private:
   bool 
-  recursiveMatch(const int& mId, const Name& name, const int& offset, const int& len);
+  recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len);
 
 
 protected:
@@ -124,7 +124,7 @@
 }
   
 inline bool 
-RegexMatcher::recursiveMatch(const int& mId, const Name& name, const int& offset, const int& len)
+RegexMatcher::recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len)
 {
   // _LOG_TRACE ("Enter RegexMatcher::recursiveMatch");
 
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index 84b5c46..3ae74f1 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -32,10 +32,10 @@
   extractPattern(int index, int* next);
     
   int 
-  extractSubPattern(const char left, const char right, int index);
+  extractSubPattern(const char left, const char right, size_t index);
     
   int 
-  extractRepetition(int index);
+  extractRepetition(size_t index);
 
 private:
 
@@ -121,10 +121,10 @@
 }
   
 inline int 
-RegexPatternListMatcher::extractSubPattern(const char left, const char right, int index)
+RegexPatternListMatcher::extractSubPattern(const char left, const char right, size_t index)
 {
-  int lcount = 1;
-  int rcount = 0;
+  size_t lcount = 1;
+  size_t rcount = 0;
 
   while(lcount > rcount){
 
@@ -143,9 +143,9 @@
 }
 
 inline int 
-RegexPatternListMatcher::extractRepetition(int index)
+RegexPatternListMatcher::extractRepetition(size_t index)
 {
-  int exprSize = m_expr.size();
+  size_t exprSize = m_expr.size();
 
   if(index == exprSize)
     return index;
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index 38f1a5a..d3b8271 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -95,8 +95,8 @@
   else
     expand = m_expand;
 
-  int offset = 0;
-  while(offset < expand.size())
+  size_t offset = 0;
+  while (offset < expand.size())
     {
       std::string item = getItemFromExpand(expand, offset);
       if(item[0] == '<')
@@ -129,9 +129,9 @@
 }
 
 std::string
-RegexTopMatcher::getItemFromExpand(const std::string& expand, int & offset)
+RegexTopMatcher::getItemFromExpand(const std::string& expand, size_t& offset)
 {
-  int begin = offset;
+  size_t begin = offset;
 
   if(expand[offset] == '\\')
     {
@@ -155,8 +155,8 @@
       if(offset >= expand.size())
         throw RegexMatcher::Error("wrong format of expand string!");
         
-      int left = 1;
-      int right = 0;
+      size_t left = 1;
+      size_t right = 0;
       while(right < left)
         {
           if(expand[offset] == '<')
@@ -196,7 +196,7 @@
 RegexTopMatcher::convertSpecialChar(const std::string& str)
 {
   std::string newStr;
-  for(int i = 0; i < str.size(); i++)
+  for(size_t i = 0; i < str.size(); i++)
     {
       char c = str[i];
       switch(c)
diff --git a/src/util/regex/regex-top-matcher.hpp b/src/util/regex/regex-top-matcher.hpp
index fc4a0df..4d9c01e 100644
--- a/src/util/regex/regex-top-matcher.hpp
+++ b/src/util/regex/regex-top-matcher.hpp
@@ -43,7 +43,7 @@
 
 private:
   std::string
-  getItemFromExpand(const std::string& expand, int & offset);
+  getItemFromExpand(const std::string& expand, size_t& offset);
 
   static std::string
   convertSpecialChar(const std::string& str);
diff --git a/src/util/scheduler.cpp b/src/util/scheduler.cpp
index 377800f..fc6492f 100644
--- a/src/util/scheduler.cpp
+++ b/src/util/scheduler.cpp
@@ -76,8 +76,7 @@
 
 
 Scheduler::Scheduler(boost::asio::io_service& ioService)
-  : m_ioService(ioService)
-  , m_scheduledEvent(m_events.end())
+  : m_scheduledEvent(m_events.end())
   , m_deadlineTimer(ioService)
   , m_isEventExecuting(false)
 {
diff --git a/src/util/scheduler.hpp b/src/util/scheduler.hpp
index b7364ce..cc8bcce 100644
--- a/src/util/scheduler.hpp
+++ b/src/util/scheduler.hpp
@@ -56,8 +56,6 @@
   onEvent(const boost::system::error_code& code);
   
 private:
-  boost::asio::io_service& m_ioService;
-
   struct EventInfo
   {
     EventInfo(const time::nanoseconds& after,
diff --git a/src/util/string-helper.hpp b/src/util/string-helper.hpp
index 14f499e..9e2329c 100644
--- a/src/util/string-helper.hpp
+++ b/src/util/string-helper.hpp
@@ -23,7 +23,7 @@
 inline std::string 
 toHex(const uint8_t* array, size_t arraySize)
 {
-  if (!&array)
+  if (array == 0 || arraySize == 0)
     return "";
   
   std::ostringstream result;