util: Correcting code style in regular expression implementation

Change-Id: I7c31c2c8c7a68094da6e73223171b8ac0c886370
Refs: #1403
diff --git a/src/util/regex/regex-backref-manager.hpp b/src/util/regex/regex-backref-manager.hpp
index 56919f5..9ca95ea 100644
--- a/src/util/regex/regex-backref-manager.hpp
+++ b/src/util/regex/regex-backref-manager.hpp
@@ -24,12 +24,15 @@
 class RegexBackrefManager
 {
 public:
-  RegexBackrefManager(){}
+  RegexBackrefManager()
+  {
+  }
 
-  virtual ~RegexBackrefManager();
+  virtual
+  ~RegexBackrefManager();
 
-  int
-  pushRef(shared_ptr<RegexMatcher> matcher);
+  size_t
+  pushRef(const shared_ptr<RegexMatcher>& matcher);
 
   void
   popRef();
@@ -37,24 +40,25 @@
   size_t
   size();
 
-  shared_ptr<RegexMatcher>
-  getBackRef(int i);
+  const shared_ptr<RegexMatcher>&
+  getBackref(size_t backrefNo);
 
 private:
-  std::vector<shared_ptr<RegexMatcher> > m_backRefs;
+  std::vector<shared_ptr<RegexMatcher> > m_backrefs;
 };
 
 
-inline RegexBackrefManager::~RegexBackrefManager()
+inline
+RegexBackrefManager::~RegexBackrefManager()
 {
-  m_backRefs.clear();
+  m_backrefs.clear();
 }
 
-inline int
-RegexBackrefManager::pushRef(shared_ptr<RegexMatcher> matcher)
+inline size_t
+RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
 {
-  size_t last = m_backRefs.size();
-  m_backRefs.push_back(matcher);
+  size_t last = m_backrefs.size();
+  m_backrefs.push_back(matcher);
 
   return last;
 }
@@ -62,19 +66,19 @@
 inline void
 RegexBackrefManager::popRef()
 {
-  m_backRefs.pop_back();
+  m_backrefs.pop_back();
 }
 
 inline size_t
 RegexBackrefManager::size()
 {
-  return m_backRefs.size();
+  return m_backrefs.size();
 }
 
-inline shared_ptr<RegexMatcher>
-RegexBackrefManager::getBackRef(int i)
+inline const shared_ptr<RegexMatcher>&
+RegexBackrefManager::getBackref(size_t backrefNo)
 {
-  return m_backRefs[i];
+  return m_backrefs[backrefNo];
 }
 
 
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index 6ca7258..08c101c 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -24,9 +24,12 @@
 class RegexBackrefMatcher : public RegexMatcher
 {
 public:
-  RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
+  RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
 
-  virtual ~RegexBackrefMatcher(){}
+  virtual
+  ~RegexBackrefMatcher()
+  {
+  }
 
   void
   lateCompile()
@@ -45,9 +48,10 @@
 
 namespace ndn {
 
-inline RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
-                                                shared_ptr<RegexBackrefManager> backRefManager)
-  : RegexMatcher (expr, EXPR_BACKREF, backRefManager)
+inline
+RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
+                                         shared_ptr<RegexBackrefManager> backrefManager)
+  : RegexMatcher(expr, EXPR_BACKREF, backrefManager)
 {
   // compile();
 }
@@ -55,17 +59,19 @@
 inline void
 RegexBackrefMatcher::compile()
 {
-  int lastIndex = m_expr.size() - 1;
-  if ('(' == m_expr[0] && ')' == m_expr[lastIndex]){
+  if (m_expr.size() < 2)
+    throw RegexMatcher::Error("Unrecognized format: " + m_expr);
+
+  size_t lastIndex = m_expr.size() - 1;
+  if ('(' == m_expr[0] && ')' == m_expr[lastIndex]) {
     // m_backRefManager->pushRef(this);
 
     shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1),
                                                                  m_backrefManager));
-    m_matcherList.push_back(matcher);
+    m_matchers.push_back(matcher);
   }
   else
-    throw RegexMatcher::Error(std::string("Error: RegexBackrefMatcher.Compile(): ")
-                              + " Unrecognoized format " + m_expr);
+    throw RegexMatcher::Error("Unrecognized format: " + m_expr);
 }
 
 
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 747662c..de0b6c9 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -20,7 +20,6 @@
 #include "regex-matcher.hpp"
 #include "regex-pseudo-matcher.hpp"
 
-
 namespace ndn {
 
 class RegexComponentMatcher : public RegexMatcher
@@ -29,17 +28,20 @@
   /**
    * @brief Create a RegexComponent matcher from expr
    * @param expr The standard regular expression to match a component
-   * @param backRefManager The back reference manager
-   * @param exact The flag to provide exact match
+   * @param backrefManager The back reference manager
+   * @param isExactMatch The flag to provide exact match
    */
   RegexComponentMatcher(const std::string& expr,
-                        ptr_lib::shared_ptr<RegexBackrefManager> backRefManager,
-                        bool exact = true);
+                        shared_ptr<RegexBackrefManager> backrefManager,
+                        bool isExactMatch = true);
 
-  virtual ~RegexComponentMatcher() {};
+  virtual
+  ~RegexComponentMatcher()
+  {
+  };
 
   virtual bool
-  match(const Name & name, const int & offset, const int &len = 1);
+  match(const Name& name, size_t offset, size_t len = 1);
 
 protected:
   /**
@@ -50,60 +52,51 @@
   compile();
 
 private:
-  bool m_exact;
+  bool m_isExactMatch;
   boost::regex m_componentRegex;
-  std::vector<ptr_lib::shared_ptr<RegexPseudoMatcher> > m_pseudoMatcher;
+  std::vector<shared_ptr<RegexPseudoMatcher> > m_pseudoMatchers;
 
 };
 
 
 inline
-RegexComponentMatcher::RegexComponentMatcher (const std::string& expr,
-                                              shared_ptr<RegexBackrefManager> backRefManager,
-                                              bool exact)
-  : RegexMatcher (expr, EXPR_COMPONENT, backRefManager),
-    m_exact(exact)
+RegexComponentMatcher::RegexComponentMatcher(const std::string& expr,
+                                             shared_ptr<RegexBackrefManager> backrefManager,
+                                             bool isExactMatch)
+  : RegexMatcher(expr, EXPR_COMPONENT, backrefManager)
+  , m_isExactMatch(isExactMatch)
 {
-  // _LOG_TRACE ("Enter RegexComponentMatcher Constructor: ");
   compile();
-  // _LOG_TRACE ("Exit RegexComponentMatcher Constructor: ");
 }
 
 inline void
-RegexComponentMatcher::compile ()
+RegexComponentMatcher::compile()
 {
-  // _LOG_TRACE ("Enter RegexComponentMatcher::compile");
+  m_componentRegex = boost::regex(m_expr);
 
-  m_componentRegex = boost::regex (m_expr);
-
-  m_pseudoMatcher.clear();
-  m_pseudoMatcher.push_back(make_shared<RegexPseudoMatcher>());
+  m_pseudoMatchers.clear();
+  m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
 
   for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
     {
       shared_ptr<RegexPseudoMatcher> pMatcher = make_shared<RegexPseudoMatcher>();
-      m_pseudoMatcher.push_back(pMatcher);
+      m_pseudoMatchers.push_back(pMatcher);
       m_backrefManager->pushRef(static_pointer_cast<RegexMatcher>(pMatcher));
     }
-
-
-  // _LOG_TRACE ("Exit RegexComponentMatcher::compile");
 }
 
 inline bool
-RegexComponentMatcher::match (const Name & name, const int & offset, const int & len)
+RegexComponentMatcher::match(const Name& name, size_t offset, size_t len)
 {
-  // _LOG_TRACE ("Enter RegexComponentMatcher::match ");
-
   m_matchResult.clear();
 
-  if ("" == m_expr)
+  if (m_expr.empty())
     {
       m_matchResult.push_back(name.get(offset));
       return true;
     }
 
-  if (true == m_exact)
+  if (m_isExactMatch)
     {
       boost::smatch subResult;
       std::string targetStr = name.get(offset).toEscapedString();
@@ -111,8 +104,8 @@
         {
           for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
             {
-              m_pseudoMatcher[i]->resetMatchResult();
-              m_pseudoMatcher[i]->setMatchResult(subResult[i]);
+              m_pseudoMatchers[i]->resetMatchResult();
+              m_pseudoMatchers[i]->setMatchResult(subResult[i]);
             }
           m_matchResult.push_back(name.get(offset));
           return true;
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index e2ff78c..8e0e908 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -24,20 +24,19 @@
 
 class RegexComponentSetMatcher : public RegexMatcher
 {
-
 public:
   /**
    * @brief Create a RegexComponentSetMatcher matcher from expr
    * @param expr The standard regular expression to match a component
-   * @param exact The flag to provide exact match
-   * @param backRefNum The starting back reference number
+   * @param backrefManager Shared pointer to back-reference manager
    */
-  RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
+  RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
 
-  virtual ~RegexComponentSetMatcher();
+  virtual
+  ~RegexComponentSetMatcher();
 
   virtual bool
-  match(const Name& name, const int& offset, const int& len = 1);
+  match(const Name& name, size_t offset, size_t len = 1);
 
 protected:
   /**
@@ -48,57 +47,53 @@
   compile();
 
 private:
-  int
-  extractComponent(int index);
+  size_t
+  extractComponent(size_t index);
 
   void
   compileSingleComponent();
 
   void
-  compileMultipleComponents(const int start, const int lastIndex);
+  compileMultipleComponents(size_t start, size_t lastIndex);
 
 private:
   typedef std::set<shared_ptr<RegexComponentMatcher> > ComponentsSet;
   ComponentsSet m_components;
-  bool m_include;
+  bool m_isInclusion;
 };
 
 
 inline
 RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr,
-                                                   shared_ptr<RegexBackrefManager> backRefManager)
-  : RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
-    m_include(true)
+                                                   shared_ptr<RegexBackrefManager> backrefManager)
+  : RegexMatcher(expr, EXPR_COMPONENT_SET, backrefManager)
+  , m_isInclusion(true)
 {
-  // _LOG_TRACE ("Enter RegexComponentSetMatcher Constructor");
   compile();
-  // _LOG_TRACE ("Exit RegexComponentSetMatcher Constructor");
 }
 
 inline
 RegexComponentSetMatcher::~RegexComponentSetMatcher()
 {
-  // ComponentsSet::iterator it = m_components.begin();
-
-  // for(; it != m_components.end(); it++)
-  //   delete *it;
 }
 
 inline void
 RegexComponentSetMatcher::compile()
 {
-  switch (m_expr[0]){
+  if (m_expr.size() < 2)
+    throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
+
+  switch (m_expr[0]) {
   case '<':
     return compileSingleComponent();
   case '[':
     {
-      int lastIndex = m_expr.size() - 1;
+      size_t lastIndex = m_expr.size() - 1;
       if (']' != m_expr[lastIndex])
-        throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
-                                  + " No matched ']' " + m_expr);
+        throw RegexMatcher::Error("Regexp compile error (no matching ']' in " + m_expr + ")");
 
-      if ('^' == m_expr[1]){
-        m_include = false;
+      if ('^' == m_expr[1]) {
+        m_isInclusion = false;
         compileMultipleComponents(2, lastIndex);
       }
       else
@@ -106,8 +101,7 @@
       break;
     }
   default:
-    throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
-                              + "Parsing error in expr " + m_expr);
+    throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
   }
 }
 
@@ -118,8 +112,7 @@
 
   if (m_expr.size() != end)
     {
-      throw RegexMatcher::Error(
-        std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ") + m_expr);
+      throw RegexMatcher::Error("Component expr error " + m_expr);
     }
   else
     {
@@ -131,37 +124,33 @@
 }
 
 inline void
-RegexComponentSetMatcher::compileMultipleComponents(const int start, const int lastIndex)
+RegexComponentSetMatcher::compileMultipleComponents(size_t start, size_t lastIndex)
 {
-  int index = start;
-  int tmp_index = start;
+  size_t index = start;
+  size_t tempIndex = start;
 
-  while(index < lastIndex){
+  while (index < lastIndex) {
     if ('<' != m_expr[index])
-      throw RegexMatcher::Error(
-        std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
-        "Component expr error " + m_expr);
+      throw RegexMatcher::Error("Component expr error " + m_expr);
 
-    tmp_index = index + 1;
-    index = extractComponent(tmp_index);
+    tempIndex = index + 1;
+    index = extractComponent(tempIndex);
 
     shared_ptr<RegexComponentMatcher> component =
-      make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1),
+      make_shared<RegexComponentMatcher>(m_expr.substr(tempIndex, index - tempIndex - 1),
                                          m_backrefManager);
 
     m_components.insert(component);
   }
 
   if (index != lastIndex)
-    throw RegexMatcher::Error(
-      std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
-      "Not sufficient expr to parse " + m_expr);
+    throw RegexMatcher::Error("Not sufficient expr to parse " + m_expr);
 }
 
 inline bool
-RegexComponentSetMatcher::match(const Name& name, const int& offset, const int& len)
+RegexComponentSetMatcher::match(const Name& name, size_t offset, size_t len)
 {
-  bool matched = false;
+  bool isMatched = false;
 
   /* componentset only matches one component */
   if (len != 1)
@@ -175,14 +164,14 @@
     {
       if ((*it)->match(name, offset, len))
         {
-          matched = true;
+          isMatched = true;
           break;
         }
     }
 
   m_matchResult.clear();
 
-  if (m_include ? matched : !matched)
+  if (m_isInclusion ? isMatched : !isMatched)
     {
       m_matchResult.push_back(name.get(offset));
       return true;
@@ -191,14 +180,14 @@
     return false;
 }
 
-inline int
-RegexComponentSetMatcher::extractComponent(int index)
+inline size_t
+RegexComponentSetMatcher::extractComponent(size_t index)
 {
-  int lcount = 1;
-  int rcount = 0;
+  size_t lcount = 1;
+  size_t rcount = 0;
 
-  while(lcount > rcount){
-    switch (m_expr[index]){
+  while (lcount > rcount) {
+    switch (m_expr[index]) {
     case '<':
       lcount++;
       break;
diff --git a/src/util/regex/regex-matcher.hpp b/src/util/regex/regex-matcher.hpp
index c126e95..88cefe0 100644
--- a/src/util/regex/regex-matcher.hpp
+++ b/src/util/regex/regex-matcher.hpp
@@ -35,17 +35,13 @@
     }
   };
 
-  enum RegexExprType{
+  enum RegexExprType {
     EXPR_TOP,
-
-    EXPR_PATTERNLIST,
-
+    EXPR_PATTERN_LIST,
     EXPR_REPEAT_PATTERN,
-
     EXPR_BACKREF,
     EXPR_COMPONENT_SET,
     EXPR_COMPONENT,
-
     EXPR_PSEUDO
   };
 
@@ -57,7 +53,7 @@
   ~RegexMatcher();
 
   virtual bool
-  match(const Name& name, const int& offset, const int& len);
+  match(const Name& name, size_t offset, size_t len);
 
   /**
    * @brief get the matched name components
@@ -65,11 +61,15 @@
    */
   const std::vector<name::Component>&
   getMatchResult() const
-  { return m_matchResult; }
+  {
+    return m_matchResult;
+  }
 
   const std::string&
   getExpr() const
-  { return m_expr; }
+  {
+    return m_expr;
+  }
 
 protected:
   /**
@@ -81,14 +81,14 @@
 
 private:
   bool
-  recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len);
+  recursiveMatch(size_t matcherNo, const Name& name, size_t offset, size_t len);
 
 
 protected:
   const std::string m_expr;
   const RegexExprType m_type;
   shared_ptr<RegexBackrefManager> m_backrefManager;
-  std::vector<shared_ptr<RegexMatcher> > m_matcherList;
+  std::vector<shared_ptr<RegexMatcher> > m_matchers;
   std::vector<name::Component> m_matchResult;
 };
 
@@ -102,11 +102,11 @@
 RegexMatcher::RegexMatcher(const std::string& expr,
                            const RegexExprType& type,
                            shared_ptr<RegexBackrefManager> backrefManager)
-  : m_expr(expr),
-    m_type(type),
-    m_backrefManager(backrefManager)
+  : m_expr(expr)
+  , m_type(type)
+  , m_backrefManager(backrefManager)
 {
-  if (NULL == m_backrefManager)
+  if (!static_cast<bool>(m_backrefManager))
     m_backrefManager = make_shared<RegexBackrefManager>();
 }
 
@@ -116,16 +116,15 @@
 }
 
 inline bool
-RegexMatcher::match (const Name& name, const int& offset, const int& len)
+RegexMatcher::match(const Name& name, size_t offset, size_t len)
 {
-  // _LOG_TRACE ("Enter RegexMatcher::match");
   bool result = false;
 
   m_matchResult.clear();
 
   if (recursiveMatch(0, name, offset, len))
     {
-      for(int i = offset; i < offset + len ; i++)
+      for (size_t i = offset; i < offset + len ; i++)
         m_matchResult.push_back(name.get(i));
       result = true;
     }
@@ -134,25 +133,23 @@
       result = false;
     }
 
-  // _LOG_TRACE ("Exit RegexMatcher::match");
   return result;
 }
 
 inline bool
-RegexMatcher::recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len)
+RegexMatcher::recursiveMatch(size_t matcherNo, const Name& name, size_t offset, size_t len)
 {
-  // _LOG_TRACE ("Enter RegexMatcher::recursiveMatch");
+  ssize_t tried = len;
 
-  int tried = len;
+  if (matcherNo >= m_matchers.size())
+    return (len == 0);
 
-  if (mId >= m_matcherList.size())
-    return (len != 0 ? false : true);
+  shared_ptr<RegexMatcher> matcher = m_matchers[matcherNo];
 
-  shared_ptr<RegexMatcher> matcher = m_matcherList[mId];
-
-  while(tried >= 0)
+  while (tried >= 0)
     {
-      if (matcher->match(name, offset, tried) && recursiveMatch(mId + 1, name, offset + tried, len - tried))
+      if (matcher->match(name, offset, tried) &&
+          recursiveMatch(matcherNo + 1, name, offset + tried, len - tried))
         return true;
       tried--;
     }
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index 827c3f2..aa244a4 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -26,9 +26,12 @@
 class RegexPatternListMatcher : public RegexMatcher
 {
 public:
-  RegexPatternListMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
+  RegexPatternListMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
 
-  virtual ~RegexPatternListMatcher(){};
+  virtual
+  ~RegexPatternListMatcher()
+  {
+  };
 
 protected:
   virtual void
@@ -36,7 +39,7 @@
 
 private:
   bool
-  extractPattern(int index, int* next);
+  extractPattern(size_t index, size_t* next);
 
   int
   extractSubPattern(const char left, const char right, size_t index);
@@ -58,7 +61,7 @@
 inline
 RegexPatternListMatcher::RegexPatternListMatcher(const std::string& expr,
                                                  shared_ptr<RegexBackrefManager> backrefManager)
-  : RegexMatcher(expr, EXPR_PATTERNLIST, backrefManager)
+  : RegexMatcher(expr, EXPR_PATTERN_LIST, backrefManager)
 {
   compile();
 }
@@ -66,66 +69,64 @@
 inline void
 RegexPatternListMatcher::compile()
 {
-  const int len = m_expr.size();
-  int index = 0;
-  int subHead = index;
+  size_t len = m_expr.size();
+  size_t index = 0;
+  size_t subHead = index;
 
-  while(index < len){
+  while (index < len) {
     subHead = index;
 
     if (!extractPattern(subHead, &index))
-      throw RegexMatcher::Error("RegexPatternListMatcher compile: cannot compile");
+      throw RegexMatcher::Error("Compile error");
   }
 }
 
 inline bool
-RegexPatternListMatcher::extractPattern(int index, int* next)
+RegexPatternListMatcher::extractPattern(size_t index, size_t* next)
 {
-  // std::string errMsg = "Error: RegexPatternListMatcher.ExtractSubPattern(): ";
+  size_t start = index;
+  size_t end = index;
+  size_t indicator = index;
 
-  const int start = index;
-  int end = index;
-  int indicator = index;
-
-  switch (m_expr[index]){
+  switch (m_expr[index]) {
   case '(':
     index++;
     index = extractSubPattern('(', ')', index);
     indicator = index;
     end = extractRepetition(index);
-    if (indicator == end){
+    if (indicator == end) {
       shared_ptr<RegexMatcher> matcher =
         make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start), m_backrefManager);
       m_backrefManager->pushRef(matcher);
       dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
 
-      m_matcherList.push_back(matcher);
+      m_matchers.push_back(matcher);
     }
     else
-      m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
-                                                              m_backrefManager, indicator - start));
+      m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+                                                           m_backrefManager, indicator - start));
     break;
 
   case '<':
     index++;
-    index = extractSubPattern ('<', '>', index);
+    index = extractSubPattern('<', '>', index);
     indicator = index;
     end = extractRepetition(index);
-    m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
-                                                            m_backrefManager, indicator - start));
+    m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+                                                         m_backrefManager, indicator - start));
     break;
 
   case '[':
     index++;
-    index = extractSubPattern ('[', ']', index);
+    index = extractSubPattern('[', ']', index);
     indicator = index;
     end = extractRepetition(index);
-    m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
-                                                            m_backrefManager, indicator - start));
+    m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+                                                         m_backrefManager, indicator - start));
     break;
 
   default:
-    throw RegexMatcher::Error("Error: unexpected syntax");
+    throw RegexMatcher::Error("Unexpected syntax");
   }
 
   *next = end;
@@ -139,10 +140,10 @@
   size_t lcount = 1;
   size_t rcount = 0;
 
-  while(lcount > rcount){
+  while (lcount > rcount) {
 
     if (index >= m_expr.size())
-      throw RegexMatcher::Error("Error: parenthesis mismatch");
+      throw RegexMatcher::Error("Parenthesis mismatch");
 
     if (left == m_expr[index])
       lcount++;
@@ -163,19 +164,18 @@
   if (index == exprSize)
     return index;
 
-  if (('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])){
+  if (('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])) {
     return ++index;
   }
 
-  if ('{' == m_expr[index]){
-    while('}' != m_expr[index]){
+  if ('{' == m_expr[index]) {
+    while ('}' != m_expr[index]) {
       index++;
       if (index == exprSize)
         break;
     }
     if (index == exprSize)
-      throw RegexMatcher::Error(std::string("Error: RegexPatternListMatcher.ExtractRepetition(): ")
-                                + "Missing right brace bracket");
+      throw RegexMatcher::Error("Missing right brace bracket");
     else
       return ++index;
   }
diff --git a/src/util/regex/regex-pseudo-matcher.hpp b/src/util/regex/regex-pseudo-matcher.hpp
index a8b3a2c..182402c 100644
--- a/src/util/regex/regex-pseudo-matcher.hpp
+++ b/src/util/regex/regex-pseudo-matcher.hpp
@@ -25,7 +25,8 @@
 public:
   RegexPseudoMatcher();
 
-  virtual ~RegexPseudoMatcher()
+  virtual
+  ~RegexPseudoMatcher()
   {
   }
 
@@ -41,15 +42,17 @@
   resetMatchResult();
 };
 
-inline RegexPseudoMatcher::RegexPseudoMatcher()
-  :RegexMatcher ("", EXPR_PSEUDO)
+inline
+RegexPseudoMatcher::RegexPseudoMatcher()
+  : RegexMatcher("", EXPR_PSEUDO)
 {
 }
 
 inline void
 RegexPseudoMatcher::setMatchResult(const std::string& str)
 {
-  m_matchResult.push_back(Name::Component((const uint8_t *)str.c_str(), str.size()));
+  m_matchResult.push_back(name::Component(reinterpret_cast<const uint8_t*>(str.c_str()),
+                                          str.size()));
 }
 
 inline void
diff --git a/src/util/regex/regex-repeat-matcher.hpp b/src/util/regex/regex-repeat-matcher.hpp
index ce0abb1..bf49f13 100644
--- a/src/util/regex/regex-repeat-matcher.hpp
+++ b/src/util/regex/regex-repeat-matcher.hpp
@@ -27,14 +27,16 @@
 {
 public:
   RegexRepeatMatcher(const std::string& expr,
-                     shared_ptr<RegexBackrefManager> backRefManager,
-                     int indicator);
+                     shared_ptr<RegexBackrefManager> backrefManager,
+                     size_t indicator);
 
   virtual
-  ~RegexRepeatMatcher(){}
+  ~RegexRepeatMatcher()
+  {
+  }
 
   virtual bool
-  match(const Name& name, const int& offset, const int& len);
+  match(const Name& name, size_t offset, size_t len);
 
 protected:
   /**
@@ -49,15 +51,14 @@
   parseRepetition();
 
   bool
-  recursiveMatch (int repeat,
-                  const Name& name,
-                  const int& offset,
-                  const int&len);
+  recursiveMatch(size_t repeat,
+                 const Name& name,
+                 size_t offset, size_t len);
 
 private:
-  int m_indicator;
-  int m_repeatMin;
-  int m_repeatMax;
+  size_t m_indicator;
+  size_t m_repeatMin;
+  size_t m_repeatMax;
 };
 
 } // namespace ndn
@@ -70,23 +71,19 @@
 inline
 RegexRepeatMatcher::RegexRepeatMatcher(const std::string& expr,
                                        shared_ptr<RegexBackrefManager> backrefManager,
-                                       int indicator)
-  : RegexMatcher (expr, EXPR_REPEAT_PATTERN, backrefManager)
+                                       size_t indicator)
+  : RegexMatcher(expr, EXPR_REPEAT_PATTERN, backrefManager)
   , m_indicator(indicator)
 {
-  // _LOG_TRACE ("Enter RegexRepeatMatcher Constructor");
   compile();
-  // _LOG_TRACE ("Exit RegexRepeatMatcher Constructor");
 }
 
 inline void
 RegexRepeatMatcher::compile()
 {
-  // _LOG_TRACE ("Enter RegexRepeatMatcher::compile");
-
   shared_ptr<RegexMatcher> matcher;
 
-  if ('(' == m_expr[0]){
+  if ('(' == m_expr[0]) {
     matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
     m_backrefManager->pushRef(matcher);
     dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
@@ -95,66 +92,63 @@
     matcher = make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator),
                                                     m_backrefManager);
   }
-  m_matcherList.push_back(matcher);
+  m_matchers.push_back(matcher);
 
   parseRepetition();
-
-  // _LOG_TRACE ("Exit RegexRepeatMatcher::compile");
-
 }
 
 inline bool
 RegexRepeatMatcher::parseRepetition()
 {
-  int exprSize = m_expr.size();
-  int intMax = std::numeric_limits<int>::max();
+  size_t exprSize = m_expr.size();
+  const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
 
-  if (exprSize == m_indicator){
+  if (exprSize == m_indicator) {
     m_repeatMin = 1;
     m_repeatMax = 1;
 
     return true;
   }
-  else{
-    if (exprSize == (m_indicator + 1)){
-      if ('?' == m_expr[m_indicator]){
+  else {
+    if (exprSize == (m_indicator + 1)) {
+      if ('?' == m_expr[m_indicator]) {
         m_repeatMin = 0;
         m_repeatMax = 1;
         return true;
       }
-      if ('+' == m_expr[m_indicator]){
+      if ('+' == m_expr[m_indicator]) {
         m_repeatMin = 1;
-        m_repeatMax = intMax;
+        m_repeatMax = MAX_REPETITIONS;
         return true;
       }
-      if ('*' == m_expr[m_indicator]){
+      if ('*' == m_expr[m_indicator]) {
         m_repeatMin = 0;
-        m_repeatMax = intMax;
+        m_repeatMax = MAX_REPETITIONS;
         return true;
       }
     }
-    else{
+    else {
       std::string repeatStruct = m_expr.substr(m_indicator, exprSize - m_indicator);
-      int rsSize = repeatStruct.size();
-      int min = 0;
-      int max = 0;
+      size_t rsSize = repeatStruct.size();
+      size_t min = 0;
+      size_t max = 0;
 
-      if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
+      if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))) {
+        size_t separator = repeatStruct.find_first_of(',', 0);
         min = atoi(repeatStruct.substr(1, separator - 1).c_str());
         max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
       }
-      else if (boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))) {
+        size_t separator = repeatStruct.find_first_of(',', 0);
         min = 0;
         max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
       }
-      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))){
-        int separator = repeatStruct.find_first_of(',', 0);
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))) {
+        size_t separator = repeatStruct.find_first_of(',', 0);
         min = atoi(repeatStruct.substr(1, separator).c_str());
-        max = intMax;
+        max = MAX_REPETITIONS;
       }
-      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))){
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))) {
         min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
         max = min;
       }
@@ -162,7 +156,7 @@
         throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
                                   + "Unrecognized format "+ m_expr);
 
-      if (min > intMax || max > intMax || min > max)
+      if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
         throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
                                   + "Wrong number " + m_expr);
 
@@ -176,10 +170,8 @@
 }
 
 inline bool
-RegexRepeatMatcher::match(const Name& name, const int& offset, const int& len)
+RegexRepeatMatcher::match(const Name& name, size_t offset, size_t len)
 {
-  // _LOG_TRACE ("Enter RegexRepeatMatcher::match");
-
   m_matchResult.clear();
 
   if (0 == m_repeatMin)
@@ -188,7 +180,7 @@
 
   if (recursiveMatch(0, name, offset, len))
     {
-      for (int i = offset; i < offset + len; i++)
+      for (size_t i = offset; i < offset + len; i++)
         m_matchResult.push_back(name.get(i));
       return true;
     }
@@ -197,10 +189,10 @@
 }
 
 inline bool
-RegexRepeatMatcher::recursiveMatch(int repeat, const Name& name, const int& offset, const int& len)
+RegexRepeatMatcher::recursiveMatch(size_t repeat, const Name& name, size_t offset, size_t len)
 {
-  int tried = len;
-  shared_ptr<RegexMatcher> matcher = m_matcherList[0];
+  ssize_t tried = len;
+  shared_ptr<RegexMatcher> matcher = m_matchers[0];
 
   if (0 < len && repeat >= m_repeatMax)
     {
@@ -217,12 +209,12 @@
       return true;
     }
 
-  while(tried >= 0)
+  while (tried >= 0)
     {
-      if (matcher->match(name, offset, tried) and recursiveMatch(repeat + 1, name,
-                                                                 offset + tried, len - tried))
+      if (matcher->match(name, offset, tried) &&
+          recursiveMatch(repeat + 1, name, offset + tried, len - tried))
         return true;
-      tried --;
+      tried--;
     }
 
   return false;
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index 6a4cf36..dd2ac03 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -20,18 +20,17 @@
 namespace ndn {
 
 RegexTopMatcher::RegexTopMatcher(const std::string& expr, const std::string& expand)
-  : RegexMatcher(expr, EXPR_TOP),
-    m_expand(expand),
-    m_secondaryUsed(false)
+  : RegexMatcher(expr, EXPR_TOP)
+  , m_expand(expand)
+  , m_isSecondaryUsed(false)
 {
-  m_primaryBackRefManager = make_shared<RegexBackrefManager>();
-  m_secondaryBackRefManager = make_shared<RegexBackrefManager>();
+  m_primaryBackrefManager = make_shared<RegexBackrefManager>();
+  m_secondaryBackrefManager = make_shared<RegexBackrefManager>();
   compile();
 }
 
 RegexTopMatcher::~RegexTopMatcher()
 {
-  // delete m_backRefManager;
 }
 
 void
@@ -44,22 +43,25 @@
   if ('$' != expr[expr.size() - 1])
     expr = expr + "<.*>*";
   else
-    expr = expr.substr(0, expr.size()-1);
+    expr = expr.substr(0, expr.size() - 1);
 
-  if ('^' != expr[0])
-    m_secondaryMatcher = make_shared<RegexPatternListMatcher>("<.*>*" + expr,
-                                                              cref(m_secondaryBackRefManager));
-  else
-    expr = expr.substr(1, expr.size()-1);
+  if ('^' != expr[0]) {
+    m_secondaryMatcher = make_shared<RegexPatternListMatcher>(
+      "<.*>*" + expr,
+      cref(m_secondaryBackrefManager));
+  }
+  else {
+    expr = expr.substr(1, expr.size() - 1);
+  }
 
   m_primaryMatcher = make_shared<RegexPatternListMatcher>(func_lib::cref(expr),
-                                                          func_lib::cref(m_primaryBackRefManager));
+                                                          func_lib::cref(m_primaryBackrefManager));
 }
 
 bool
 RegexTopMatcher::match(const Name& name)
 {
-  m_secondaryUsed = false;
+  m_isSecondaryUsed = false;
 
   m_matchResult.clear();
 
@@ -70,10 +72,10 @@
     }
   else
     {
-      if (NULL != m_secondaryMatcher && m_secondaryMatcher->match(name, 0, name.size()))
+      if (static_cast<bool>(m_secondaryMatcher) && m_secondaryMatcher->match(name, 0, name.size()))
         {
           m_matchResult = m_secondaryMatcher->getMatchResult();
-          m_secondaryUsed = true;
+          m_isSecondaryUsed = true;
           return true;
         }
       return false;
@@ -81,24 +83,24 @@
 }
 
 bool
-RegexTopMatcher::match (const Name& name, const int& offset, const int& len)
+RegexTopMatcher::match(const Name& name, size_t, size_t)
 {
   return match(name);
 }
 
 Name
-RegexTopMatcher::expand (const std::string& expandStr)
+RegexTopMatcher::expand(const std::string& expandStr)
 {
   Name result;
 
-  shared_ptr<RegexBackrefManager> backRefManager =
-    (m_secondaryUsed ? m_secondaryBackRefManager : m_primaryBackRefManager);
+  shared_ptr<RegexBackrefManager> backrefManager =
+    (m_isSecondaryUsed ? m_secondaryBackrefManager : m_primaryBackrefManager);
 
-  int backRefNum = backRefManager->size();
+  size_t backrefNo = backrefManager->size();
 
   std::string expand;
 
-  if (expandStr != "")
+  if (!expandStr.empty())
     expand = expandStr;
   else
     expand = m_expand;
@@ -113,26 +115,25 @@
         }
       if (item[0] == '\\')
         {
+          size_t index = boost::lexical_cast<size_t>(item.substr(1, item.size() - 1));
 
-          int index = atoi(item.substr(1, item.size() - 1).c_str());
-
-          if (0 == index){
+          if (0 == index) {
             std::vector<name::Component>::iterator it = m_matchResult.begin();
             std::vector<name::Component>::iterator end = m_matchResult.end();
-            for(; it != end; it++)
-              result.append (*it);
+            for (; it != end; it++)
+              result.append(*it);
           }
-          else if (index <= backRefNum)
+          else if (index <= backrefNo)
             {
               std::vector<name::Component>::const_iterator it =
-                backRefManager->getBackRef (index - 1)->getMatchResult ().begin();
+                backrefManager->getBackref(index - 1)->getMatchResult().begin();
               std::vector<name::Component>::const_iterator end =
-                backRefManager->getBackRef (index - 1)->getMatchResult ().end();
-              for(; it != end; it++)
-                result.append (*it);
+                backrefManager->getBackref(index - 1)->getMatchResult().end();
+              for (; it != end; it++)
+                result.append(*it);
             }
           else
-            throw RegexMatcher::Error("Exceed the range of back reference!");
+            throw RegexMatcher::Error("Exceed the range of back reference");
         }
     }
   return result;
@@ -149,7 +150,7 @@
       if (offset >= expand.size())
         throw RegexMatcher::Error("wrong format of expand string!");
 
-      while(expand[offset] <= '9' and expand[offset] >= '0'){
+      while (expand[offset] <= '9' and expand[offset] >= '0') {
         offset++;
         if (offset > expand.size())
           throw RegexMatcher::Error("wrong format of expand string!");
@@ -167,7 +168,7 @@
 
       size_t left = 1;
       size_t right = 0;
-      while(right < left)
+      while (right < left)
         {
           if (expand[offset] == '<')
             left++;
@@ -186,10 +187,9 @@
 shared_ptr<RegexTopMatcher>
 RegexTopMatcher::fromName(const Name& name, bool hasAnchor)
 {
-  Name::const_iterator it = name.begin();
   std::string regexStr("^");
 
-  for(; it != name.end(); it++)
+  for (Name::const_iterator it = name.begin(); it != name.end(); it++)
     {
       regexStr.append("<");
       regexStr.append(convertSpecialChar(it->toEscapedString()));
@@ -207,7 +207,7 @@
 RegexTopMatcher::convertSpecialChar(const std::string& str)
 {
   std::string newStr;
-  for(size_t i = 0; i < str.size(); i++)
+  for (size_t i = 0; i < str.size(); i++)
     {
       char c = str[i];
       switch (c)
@@ -226,12 +226,14 @@
         case '^':
         case '$':
           newStr.push_back('\\');
+          // Fallthrough
         default:
           newStr.push_back(c);
+          break;
         }
     }
 
   return newStr;
 }
 
-}//ndn
+} // namespace ndn
diff --git a/src/util/regex/regex-top-matcher.hpp b/src/util/regex/regex-top-matcher.hpp
index a1ae322..e553bf3 100644
--- a/src/util/regex/regex-top-matcher.hpp
+++ b/src/util/regex/regex-top-matcher.hpp
@@ -36,7 +36,7 @@
   match(const Name& name);
 
   virtual bool
-  match(const Name& name, const int& offset, const int& length);
+  match(const Name& name, size_t offset, size_t len);
 
   virtual Name
   expand(const std::string& expand = "");
@@ -59,9 +59,9 @@
   const std::string m_expand;
   shared_ptr<RegexPatternListMatcher> m_primaryMatcher;
   shared_ptr<RegexPatternListMatcher> m_secondaryMatcher;
-  shared_ptr<RegexBackrefManager> m_primaryBackRefManager;
-  shared_ptr<RegexBackrefManager> m_secondaryBackRefManager;
-  bool m_secondaryUsed;
+  shared_ptr<RegexBackrefManager> m_primaryBackrefManager;
+  shared_ptr<RegexBackrefManager> m_secondaryBackrefManager;
+  bool m_isSecondaryUsed;
 };
 
 } // namespace ndn