util: Ensure ndn::RegexComponentMatcher works with Boost >= 1.56

Change-Id: I39c2c400317cf00a9a560e0b9d26f786ea5e3486
Refs: #1866
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 64ffc6a..6b5474a 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -78,6 +78,18 @@
   compile();
 }
 
+// Re: http://www.boost.org/users/history/version_1_56_0.html
+//
+//   Breaking change: corrected behavior of basic_regex<>::mark_count() to match existing
+//   documentation, basic_regex<>::subexpression(n) changed to match, see
+//   https://svn.boost.org/trac/boost/ticket/9227
+static const size_t BOOST_REGEXP_MARK_COUNT_CORRECTION =
+#if BOOST_VERSION < 105600
+                    1;
+#else
+                    0;
+#endif
+
 inline void
 RegexComponentMatcher::compile()
 {
@@ -86,7 +98,8 @@
   m_pseudoMatchers.clear();
   m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
 
-  for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
+  for (size_t i = 1;
+       i <= m_componentRegex.mark_count() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++)
     {
       shared_ptr<RegexPseudoMatcher> pMatcher = make_shared<RegexPseudoMatcher>();
       m_pseudoMatchers.push_back(pMatcher);
@@ -111,7 +124,8 @@
       std::string targetStr = name.get(offset).toUri();
       if (boost::regex_match(targetStr, subResult, m_componentRegex))
         {
-          for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
+          for (size_t i = 1;
+               i <= m_componentRegex.mark_count() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++)
             {
               m_pseudoMatchers[i]->resetMatchResult();
               m_pseudoMatchers[i]->setMatchResult(subResult[i]);
diff --git a/tests/unit-tests/util/test-regex.cpp b/tests/unit-tests/util/test-regex.cpp
index c5ef435..81630d1 100644
--- a/tests/unit-tests/util/test-regex.cpp
+++ b/tests/unit-tests/util/test-regex.cpp
@@ -59,6 +59,8 @@
   BOOST_CHECK_EQUAL(res, true);
   BOOST_CHECK_EQUAL(cm->getMatchResult().size(), 1);
   BOOST_CHECK_EQUAL(cm->getMatchResult()[0].toUri(), string("ccc.cd"));
+
+  BOOST_REQUIRE_EQUAL(backRef->size(), 2);
   BOOST_CHECK_EQUAL(backRef->getBackref(0)->getMatchResult()[0].toUri(), string("ccc"));
   BOOST_CHECK_EQUAL(backRef->getBackref(1)->getMatchResult()[0].toUri(), string("cd"));
 }