regex: move method definitions to .cpp files
Change-Id: Ifa66c886bd3f920821b0a498f714da24d51b042e
diff --git a/src/util/regex/regex-backref-manager.cpp b/src/util/regex/regex-backref-manager.cpp
new file mode 100644
index 0000000..23c4a0a
--- /dev/null
+++ b/src/util/regex/regex-backref-manager.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-backref-manager.hpp"
+
+namespace ndn {
+
+size_t
+RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
+{
+ auto last = m_backrefs.size();
+ m_backrefs.emplace_back(matcher);
+ return last;
+}
+
+shared_ptr<RegexMatcher>
+RegexBackrefManager::getBackref(size_t i) const
+{
+ auto backref = m_backrefs[i].lock();
+ BOOST_ASSERT(backref != nullptr);
+ return backref;
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-backref-manager.hpp b/src/util/regex/regex-backref-manager.hpp
index 4e112d7..1a6d14e 100644
--- a/src/util/regex/regex-backref-manager.hpp
+++ b/src/util/regex/regex-backref-manager.hpp
@@ -57,22 +57,6 @@
std::vector<weak_ptr<RegexMatcher>> m_backrefs;
};
-inline size_t
-RegexBackrefManager::pushRef(const shared_ptr<RegexMatcher>& matcher)
-{
- auto last = m_backrefs.size();
- m_backrefs.emplace_back(matcher);
- return last;
-}
-
-inline shared_ptr<RegexMatcher>
-RegexBackrefManager::getBackref(size_t i) const
-{
- auto backref = m_backrefs[i].lock();
- BOOST_ASSERT(backref != nullptr);
- return backref;
-}
-
} // namespace ndn
#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MANAGER_HPP
diff --git a/src/util/regex/regex-backref-matcher.cpp b/src/util/regex/regex-backref-matcher.cpp
new file mode 100644
index 0000000..5895b8b
--- /dev/null
+++ b/src/util/regex/regex-backref-matcher.cpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-backref-matcher.hpp"
+#include "regex-pattern-list-matcher.hpp"
+
+namespace ndn {
+
+RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
+ shared_ptr<RegexBackrefManager> backrefManager)
+ : RegexMatcher(expr, EXPR_BACKREF, std::move(backrefManager))
+{
+}
+
+void
+RegexBackrefMatcher::compile()
+{
+ if (m_expr.size() < 2)
+ BOOST_THROW_EXCEPTION(Error("Unrecognized format: " + m_expr));
+
+ size_t lastIndex = m_expr.size() - 1;
+ if ('(' == m_expr[0] && ')' == m_expr[lastIndex]) {
+ m_matchers.push_back(make_shared<RegexPatternListMatcher>(m_expr.substr(1, lastIndex - 1),
+ m_backrefManager));
+ }
+ else
+ BOOST_THROW_EXCEPTION(Error("Unrecognized format: " + m_expr));
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index 947abc7..565331b 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -46,32 +46,4 @@
} // namespace ndn
-#include "regex-pattern-list-matcher.hpp"
-
-namespace ndn {
-
-inline
-RegexBackrefMatcher::RegexBackrefMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backrefManager)
- : RegexMatcher(expr, EXPR_BACKREF, std::move(backrefManager))
-{
-}
-
-inline void
-RegexBackrefMatcher::compile()
-{
- if (m_expr.size() < 2)
- BOOST_THROW_EXCEPTION(Error("Unrecognized format: " + m_expr));
-
- size_t lastIndex = m_expr.size() - 1;
- if ('(' == m_expr[0] && ')' == m_expr[lastIndex]) {
- m_matchers.push_back(make_shared<RegexPatternListMatcher>(m_expr.substr(1, lastIndex - 1),
- m_backrefManager));
- }
- else
- BOOST_THROW_EXCEPTION(Error("Unrecognized format: " + m_expr));
-}
-
-} // namespace ndn
-
#endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
diff --git a/src/util/regex/regex-component-matcher.cpp b/src/util/regex/regex-component-matcher.cpp
new file mode 100644
index 0000000..8d1e824
--- /dev/null
+++ b/src/util/regex/regex-component-matcher.cpp
@@ -0,0 +1,92 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-component-matcher.hpp"
+#include "regex-pseudo-matcher.hpp"
+
+namespace ndn {
+
+// 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 constexpr size_t BOOST_REGEXP_MARK_COUNT_CORRECTION =
+#if BOOST_VERSION < 105600
+ 1;
+#else
+ 0;
+#endif
+
+RegexComponentMatcher::RegexComponentMatcher(const std::string& expr,
+ shared_ptr<RegexBackrefManager> backrefManager,
+ bool isExactMatch)
+ : RegexMatcher(expr, EXPR_COMPONENT, std::move(backrefManager))
+ , m_isExactMatch(isExactMatch)
+{
+ compile();
+}
+
+void
+RegexComponentMatcher::compile()
+{
+ m_componentRegex = boost::regex(m_expr);
+
+ m_pseudoMatchers.clear();
+ m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
+
+ for (size_t i = 1; i <= m_componentRegex.mark_count() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++) {
+ m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
+ m_backrefManager->pushRef(m_pseudoMatchers.back());
+ }
+}
+
+bool
+RegexComponentMatcher::match(const Name& name, size_t offset, size_t len)
+{
+ m_matchResult.clear();
+
+ if (m_expr.empty()) {
+ m_matchResult.push_back(name.get(offset));
+ return true;
+ }
+
+ if (!m_isExactMatch)
+ BOOST_THROW_EXCEPTION(Error("Non-exact component search is not supported yet"));
+
+ boost::smatch subResult;
+ 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() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++) {
+ m_pseudoMatchers[i]->resetMatchResult();
+ m_pseudoMatchers[i]->setMatchResult(subResult[i]);
+ }
+ m_matchResult.push_back(name.get(offset));
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 3140375..4c5ecf0 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -25,12 +25,13 @@
#define NDN_UTIL_REGEX_REGEX_COMPONENT_MATCHER_HPP
#include "regex-matcher.hpp"
-#include "regex-pseudo-matcher.hpp"
#include <boost/regex.hpp>
namespace ndn {
+class RegexPseudoMatcher;
+
class RegexComponentMatcher : public RegexMatcher
{
public:
@@ -57,70 +58,6 @@
std::vector<shared_ptr<RegexPseudoMatcher>> m_pseudoMatchers;
};
-inline
-RegexComponentMatcher::RegexComponentMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backrefManager,
- bool isExactMatch)
- : RegexMatcher(expr, EXPR_COMPONENT, std::move(backrefManager))
- , m_isExactMatch(isExactMatch)
-{
- 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 constexpr size_t BOOST_REGEXP_MARK_COUNT_CORRECTION =
-#if BOOST_VERSION < 105600
- 1;
-#else
- 0;
-#endif
-
-inline void
-RegexComponentMatcher::compile()
-{
- m_componentRegex = boost::regex(m_expr);
-
- m_pseudoMatchers.clear();
- m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
-
- for (size_t i = 1; i <= m_componentRegex.mark_count() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++) {
- m_pseudoMatchers.push_back(make_shared<RegexPseudoMatcher>());
- m_backrefManager->pushRef(m_pseudoMatchers.back());
- }
-}
-
-inline bool
-RegexComponentMatcher::match(const Name& name, size_t offset, size_t len)
-{
- m_matchResult.clear();
-
- if (m_expr.empty()) {
- m_matchResult.push_back(name.get(offset));
- return true;
- }
-
- if (!m_isExactMatch)
- BOOST_THROW_EXCEPTION(Error("Non-exact component search is not supported yet"));
-
- boost::smatch subResult;
- 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() - BOOST_REGEXP_MARK_COUNT_CORRECTION; i++) {
- m_pseudoMatchers[i]->resetMatchResult();
- m_pseudoMatchers[i]->setMatchResult(subResult[i]);
- }
- m_matchResult.push_back(name.get(offset));
- return true;
- }
-
- return false;
-}
-
} // namespace ndn
#endif // NDN_UTIL_REGEX_REGEX_COMPONENT_MATCHER_HPP
diff --git a/src/util/regex/regex-component-set-matcher.cpp b/src/util/regex/regex-component-set-matcher.cpp
new file mode 100644
index 0000000..8e39794
--- /dev/null
+++ b/src/util/regex/regex-component-set-matcher.cpp
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-component-set-matcher.hpp"
+#include "regex-component-matcher.hpp"
+
+namespace ndn {
+
+RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr,
+ shared_ptr<RegexBackrefManager> backrefManager)
+ : RegexMatcher(expr, EXPR_COMPONENT_SET, std::move(backrefManager))
+ , m_isInclusion(true)
+{
+ compile();
+}
+
+void
+RegexComponentSetMatcher::compile()
+{
+ if (m_expr.size() < 2)
+ BOOST_THROW_EXCEPTION(Error("Regexp compile error (cannot parse " + m_expr + ")"));
+
+ switch (m_expr[0]) {
+ case '<':
+ return compileSingleComponent();
+ case '[': {
+ size_t lastIndex = m_expr.size() - 1;
+ if (']' != m_expr[lastIndex])
+ BOOST_THROW_EXCEPTION(Error("Regexp compile error (no matching ']' in " + m_expr + ")"));
+
+ if ('^' == m_expr[1]) {
+ m_isInclusion = false;
+ compileMultipleComponents(2, lastIndex);
+ }
+ else
+ compileMultipleComponents(1, lastIndex);
+ break;
+ }
+ default:
+ BOOST_THROW_EXCEPTION(Error("Regexp compile error (cannot parse " + m_expr + ")"));
+ }
+}
+
+void
+RegexComponentSetMatcher::compileSingleComponent()
+{
+ size_t end = extractComponent(1);
+ if (m_expr.size() != end)
+ BOOST_THROW_EXCEPTION(Error("Component expr error " + m_expr));
+
+ m_components.insert(make_shared<RegexComponentMatcher>(m_expr.substr(1, end - 2),
+ m_backrefManager));
+}
+
+void
+RegexComponentSetMatcher::compileMultipleComponents(size_t start, size_t lastIndex)
+{
+ size_t index = start;
+ size_t tempIndex = start;
+
+ while (index < lastIndex) {
+ if ('<' != m_expr[index])
+ BOOST_THROW_EXCEPTION(Error("Component expr error " + m_expr));
+
+ tempIndex = index + 1;
+ index = extractComponent(tempIndex);
+ m_components.insert(make_shared<RegexComponentMatcher>(m_expr.substr(tempIndex, index - tempIndex - 1),
+ m_backrefManager));
+ }
+
+ if (index != lastIndex)
+ BOOST_THROW_EXCEPTION(Error("Not sufficient expr to parse " + m_expr));
+}
+
+bool
+RegexComponentSetMatcher::match(const Name& name, size_t offset, size_t len)
+{
+ // componentset only matches one component
+ if (len != 1)
+ return false;
+
+ bool isMatched = false;
+ for (const auto& comp : m_components) {
+ if (comp->match(name, offset, len)) {
+ isMatched = true;
+ break;
+ }
+ }
+
+ m_matchResult.clear();
+
+ if (m_isInclusion ? isMatched : !isMatched) {
+ m_matchResult.push_back(name.get(offset));
+ return true;
+ }
+ else
+ return false;
+}
+
+size_t
+RegexComponentSetMatcher::extractComponent(size_t index) const
+{
+ size_t lcount = 1;
+ size_t rcount = 0;
+
+ while (lcount > rcount) {
+ switch (m_expr[index]) {
+ case '<':
+ lcount++;
+ break;
+ case '>':
+ rcount++;
+ break;
+ case 0:
+ BOOST_THROW_EXCEPTION(Error("Square brackets mismatch"));
+ break;
+ }
+ index++;
+ }
+
+ return index;
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index 46d8527..3c9fae9 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -24,13 +24,14 @@
#ifndef NDN_UTIL_REGEX_REGEX_COMPONENT_SET_MATCHER_HPP
#define NDN_UTIL_REGEX_REGEX_COMPONENT_SET_MATCHER_HPP
-#include "regex-component-matcher.hpp"
#include "regex-matcher.hpp"
#include <set>
namespace ndn {
+class RegexComponentMatcher;
+
class RegexComponentSetMatcher : public RegexMatcher
{
public:
@@ -66,122 +67,6 @@
bool m_isInclusion;
};
-inline
-RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backrefManager)
- : RegexMatcher(expr, EXPR_COMPONENT_SET, std::move(backrefManager))
- , m_isInclusion(true)
-{
- compile();
-}
-
-inline void
-RegexComponentSetMatcher::compile()
-{
- if (m_expr.size() < 2)
- BOOST_THROW_EXCEPTION(Error("Regexp compile error (cannot parse " + m_expr + ")"));
-
- switch (m_expr[0]) {
- case '<':
- return compileSingleComponent();
- case '[': {
- size_t lastIndex = m_expr.size() - 1;
- if (']' != m_expr[lastIndex])
- BOOST_THROW_EXCEPTION(Error("Regexp compile error (no matching ']' in " + m_expr + ")"));
-
- if ('^' == m_expr[1]) {
- m_isInclusion = false;
- compileMultipleComponents(2, lastIndex);
- }
- else
- compileMultipleComponents(1, lastIndex);
- break;
- }
- default:
- BOOST_THROW_EXCEPTION(Error("Regexp compile error (cannot parse " + m_expr + ")"));
- }
-}
-
-inline void
-RegexComponentSetMatcher::compileSingleComponent()
-{
- size_t end = extractComponent(1);
- if (m_expr.size() != end)
- BOOST_THROW_EXCEPTION(Error("Component expr error " + m_expr));
-
- m_components.insert(make_shared<RegexComponentMatcher>(m_expr.substr(1, end - 2),
- m_backrefManager));
-}
-
-inline void
-RegexComponentSetMatcher::compileMultipleComponents(size_t start, size_t lastIndex)
-{
- size_t index = start;
- size_t tempIndex = start;
-
- while (index < lastIndex) {
- if ('<' != m_expr[index])
- BOOST_THROW_EXCEPTION(Error("Component expr error " + m_expr));
-
- tempIndex = index + 1;
- index = extractComponent(tempIndex);
- m_components.insert(make_shared<RegexComponentMatcher>(m_expr.substr(tempIndex, index - tempIndex - 1),
- m_backrefManager));
- }
-
- if (index != lastIndex)
- BOOST_THROW_EXCEPTION(Error("Not sufficient expr to parse " + m_expr));
-}
-
-inline bool
-RegexComponentSetMatcher::match(const Name& name, size_t offset, size_t len)
-{
- // componentset only matches one component
- if (len != 1)
- return false;
-
- bool isMatched = false;
- for (const auto& comp : m_components) {
- if (comp->match(name, offset, len)) {
- isMatched = true;
- break;
- }
- }
-
- m_matchResult.clear();
-
- if (m_isInclusion ? isMatched : !isMatched) {
- m_matchResult.push_back(name.get(offset));
- return true;
- }
- else
- return false;
-}
-
-inline size_t
-RegexComponentSetMatcher::extractComponent(size_t index) const
-{
- size_t lcount = 1;
- size_t rcount = 0;
-
- while (lcount > rcount) {
- switch (m_expr[index]) {
- case '<':
- lcount++;
- break;
- case '>':
- rcount++;
- break;
- case 0:
- BOOST_THROW_EXCEPTION(Error("Square brackets mismatch"));
- break;
- }
- index++;
- }
-
- return index;
-}
-
} // namespace ndn
#endif // NDN_UTIL_REGEX_REGEX_COMPONENT_SET_MATCHER_HPP
diff --git a/src/util/regex/regex-matcher.cpp b/src/util/regex/regex-matcher.cpp
new file mode 100644
index 0000000..f460f92
--- /dev/null
+++ b/src/util/regex/regex-matcher.cpp
@@ -0,0 +1,80 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-matcher.hpp"
+
+namespace ndn {
+
+RegexMatcher::RegexMatcher(const std::string& expr, const RegexExprType& type,
+ shared_ptr<RegexBackrefManager> backrefManager)
+ : m_expr(expr)
+ , m_type(type)
+{
+ if (backrefManager)
+ m_backrefManager = std::move(backrefManager);
+ else
+ m_backrefManager = make_shared<RegexBackrefManager>();
+}
+
+RegexMatcher::~RegexMatcher() = default;
+
+bool
+RegexMatcher::match(const Name& name, size_t offset, size_t len)
+{
+ m_matchResult.clear();
+
+ if (recursiveMatch(0, name, offset, len)) {
+ for (size_t i = offset; i < offset + len; i++)
+ m_matchResult.push_back(name.get(i));
+ return true;
+ }
+
+ return false;
+}
+
+bool
+RegexMatcher::recursiveMatch(size_t matcherNo, const Name& name, size_t offset, size_t len)
+{
+ if (matcherNo >= m_matchers.size())
+ return len == 0;
+
+ ssize_t tried = len;
+ auto matcher = m_matchers[matcherNo];
+
+ while (tried >= 0) {
+ if (matcher->match(name, offset, tried) &&
+ recursiveMatch(matcherNo + 1, name, offset + tried, len - tried))
+ return true;
+ tried--;
+ }
+
+ return false;
+}
+
+std::ostream&
+operator<<(std::ostream& os, const RegexMatcher& rm)
+{
+ return os << rm.getExpr();
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-matcher.hpp b/src/util/regex/regex-matcher.hpp
index 5916565..bb18a8f 100644
--- a/src/util/regex/regex-matcher.hpp
+++ b/src/util/regex/regex-matcher.hpp
@@ -56,7 +56,7 @@
shared_ptr<RegexBackrefManager> backrefManager = nullptr);
virtual
- ~RegexMatcher() = default;
+ ~RegexMatcher();
virtual bool
match(const Name& name, size_t offset, size_t len);
@@ -96,56 +96,8 @@
std::vector<name::Component> m_matchResult;
};
-inline std::ostream&
-operator<<(std::ostream& os, const RegexMatcher& rm)
-{
- return os << rm.getExpr();
-}
-
-inline
-RegexMatcher::RegexMatcher(const std::string& expr, const RegexExprType& type,
- shared_ptr<RegexBackrefManager> backrefManager)
- : m_expr(expr)
- , m_type(type)
-{
- if (backrefManager)
- m_backrefManager = std::move(backrefManager);
- else
- m_backrefManager = make_shared<RegexBackrefManager>();
-}
-
-inline bool
-RegexMatcher::match(const Name& name, size_t offset, size_t len)
-{
- m_matchResult.clear();
-
- if (recursiveMatch(0, name, offset, len)) {
- for (size_t i = offset; i < offset + len; i++)
- m_matchResult.push_back(name.get(i));
- return true;
- }
-
- return false;
-}
-
-inline bool
-RegexMatcher::recursiveMatch(size_t matcherNo, const Name& name, size_t offset, size_t len)
-{
- if (matcherNo >= m_matchers.size())
- return len == 0;
-
- ssize_t tried = len;
- auto matcher = m_matchers[matcherNo];
-
- while (tried >= 0) {
- if (matcher->match(name, offset, tried) &&
- recursiveMatch(matcherNo + 1, name, offset + tried, len - tried))
- return true;
- tried--;
- }
-
- return false;
-}
+std::ostream&
+operator<<(std::ostream& os, const RegexMatcher& rm);
} // namespace ndn
diff --git a/src/util/regex/regex-pattern-list-matcher.cpp b/src/util/regex/regex-pattern-list-matcher.cpp
new file mode 100644
index 0000000..9f18441
--- /dev/null
+++ b/src/util/regex/regex-pattern-list-matcher.cpp
@@ -0,0 +1,153 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-pattern-list-matcher.hpp"
+#include "regex-backref-matcher.hpp"
+#include "regex-repeat-matcher.hpp"
+
+namespace ndn {
+
+RegexPatternListMatcher::RegexPatternListMatcher(const std::string& expr,
+ shared_ptr<RegexBackrefManager> backrefManager)
+ : RegexMatcher(expr, EXPR_PATTERN_LIST, std::move(backrefManager))
+{
+ compile();
+}
+
+void
+RegexPatternListMatcher::compile()
+{
+ size_t len = m_expr.size();
+ size_t index = 0;
+ size_t subHead = index;
+
+ while (index < len) {
+ subHead = index;
+
+ if (!extractPattern(subHead, &index))
+ BOOST_THROW_EXCEPTION(Error("Compile error"));
+ }
+}
+
+bool
+RegexPatternListMatcher::extractPattern(size_t index, size_t* next)
+{
+ size_t start = index;
+ size_t end = index;
+ size_t indicator = index;
+
+ switch (m_expr[index]) {
+ case '(':
+ index++;
+ index = extractSubPattern('(', ')', index);
+ indicator = index;
+ end = extractRepetition(index);
+ if (indicator == end) {
+ auto matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start),
+ m_backrefManager);
+ m_backrefManager->pushRef(matcher);
+ matcher->lateCompile();
+ m_matchers.push_back(std::move(matcher));
+ }
+ else
+ m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+ m_backrefManager, indicator - start));
+ break;
+
+ case '<':
+ index++;
+ index = extractSubPattern('<', '>', index);
+ indicator = index;
+ end = extractRepetition(index);
+ m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+ m_backrefManager, indicator - start));
+ break;
+
+ case '[':
+ index++;
+ index = extractSubPattern('[', ']', index);
+ indicator = index;
+ end = extractRepetition(index);
+ m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
+ m_backrefManager, indicator - start));
+ break;
+
+ default:
+ BOOST_THROW_EXCEPTION(Error("Unexpected syntax"));
+ }
+
+ *next = end;
+ return true;
+}
+
+size_t
+RegexPatternListMatcher::extractSubPattern(const char left, const char right, size_t index)
+{
+ size_t lcount = 1;
+ size_t rcount = 0;
+
+ while (lcount > rcount) {
+ if (index >= m_expr.size())
+ BOOST_THROW_EXCEPTION(Error("Parenthesis mismatch"));
+
+ if (left == m_expr[index])
+ lcount++;
+
+ if (right == m_expr[index])
+ rcount++;
+
+ index++;
+ }
+
+ return index;
+}
+
+size_t
+RegexPatternListMatcher::extractRepetition(size_t index)
+{
+ size_t exprSize = m_expr.size();
+
+ if (index == exprSize)
+ return index;
+
+ if (('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])) {
+ return ++index;
+ }
+
+ if ('{' == m_expr[index]) {
+ while ('}' != m_expr[index]) {
+ index++;
+ if (index == exprSize)
+ break;
+ }
+ if (index == exprSize)
+ BOOST_THROW_EXCEPTION(Error("Missing right brace bracket"));
+ else
+ return ++index;
+ }
+ else {
+ return index;
+ }
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index 7bf0366..79c1d3e 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -50,135 +50,4 @@
} // namespace ndn
-#include "regex-backref-matcher.hpp"
-#include "regex-repeat-matcher.hpp"
-
-namespace ndn {
-
-inline
-RegexPatternListMatcher::RegexPatternListMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backrefManager)
- : RegexMatcher(expr, EXPR_PATTERN_LIST, std::move(backrefManager))
-{
- compile();
-}
-
-inline void
-RegexPatternListMatcher::compile()
-{
- size_t len = m_expr.size();
- size_t index = 0;
- size_t subHead = index;
-
- while (index < len) {
- subHead = index;
-
- if (!extractPattern(subHead, &index))
- BOOST_THROW_EXCEPTION(Error("Compile error"));
- }
-}
-
-inline bool
-RegexPatternListMatcher::extractPattern(size_t index, size_t* next)
-{
- size_t start = index;
- size_t end = index;
- size_t indicator = index;
-
- switch (m_expr[index]) {
- case '(':
- index++;
- index = extractSubPattern('(', ')', index);
- indicator = index;
- end = extractRepetition(index);
- if (indicator == end) {
- auto matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start),
- m_backrefManager);
- m_backrefManager->pushRef(matcher);
- matcher->lateCompile();
- m_matchers.push_back(std::move(matcher));
- }
- else
- m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
- m_backrefManager, indicator - start));
- break;
-
- case '<':
- index++;
- index = extractSubPattern('<', '>', index);
- indicator = index;
- end = extractRepetition(index);
- m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
- m_backrefManager, indicator - start));
- break;
-
- case '[':
- index++;
- index = extractSubPattern('[', ']', index);
- indicator = index;
- end = extractRepetition(index);
- m_matchers.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start),
- m_backrefManager, indicator - start));
- break;
-
- default:
- BOOST_THROW_EXCEPTION(Error("Unexpected syntax"));
- }
-
- *next = end;
- return true;
-}
-
-inline size_t
-RegexPatternListMatcher::extractSubPattern(const char left, const char right, size_t index)
-{
- size_t lcount = 1;
- size_t rcount = 0;
-
- while (lcount > rcount) {
- if (index >= m_expr.size())
- BOOST_THROW_EXCEPTION(Error("Parenthesis mismatch"));
-
- if (left == m_expr[index])
- lcount++;
-
- if (right == m_expr[index])
- rcount++;
-
- index++;
- }
-
- return index;
-}
-
-inline size_t
-RegexPatternListMatcher::extractRepetition(size_t index)
-{
- size_t exprSize = m_expr.size();
-
- if (index == exprSize)
- return index;
-
- if (('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])) {
- return ++index;
- }
-
- if ('{' == m_expr[index]) {
- while ('}' != m_expr[index]) {
- index++;
- if (index == exprSize)
- break;
- }
- if (index == exprSize)
- BOOST_THROW_EXCEPTION(Error("Missing right brace bracket"));
- else
- return ++index;
- }
- else {
- return index;
- }
-}
-
-} // namespace ndn
-
#endif // NDN_UTIL_REGEX_REGEX_PATTERN_LIST_MATCHER_HPP
diff --git a/src/util/regex/regex-pseudo-matcher.cpp b/src/util/regex/regex-pseudo-matcher.cpp
new file mode 100644
index 0000000..5c792d5
--- /dev/null
+++ b/src/util/regex/regex-pseudo-matcher.cpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-pseudo-matcher.hpp"
+
+namespace ndn {
+
+RegexPseudoMatcher::RegexPseudoMatcher()
+ : RegexMatcher("", EXPR_PSEUDO)
+{
+}
+
+void
+RegexPseudoMatcher::setMatchResult(const std::string& str)
+{
+ m_matchResult.push_back(name::Component(reinterpret_cast<const uint8_t*>(str.data()), str.size()));
+}
+
+void
+RegexPseudoMatcher::resetMatchResult()
+{
+ m_matchResult.clear();
+}
+
+void
+RegexPseudoMatcher::compile()
+{
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-pseudo-matcher.hpp b/src/util/regex/regex-pseudo-matcher.hpp
index a2c19a0..628b883 100644
--- a/src/util/regex/regex-pseudo-matcher.hpp
+++ b/src/util/regex/regex-pseudo-matcher.hpp
@@ -44,29 +44,6 @@
compile() override;
};
-inline
-RegexPseudoMatcher::RegexPseudoMatcher()
- : RegexMatcher("", EXPR_PSEUDO)
-{
-}
-
-inline void
-RegexPseudoMatcher::setMatchResult(const std::string& str)
-{
- m_matchResult.push_back(name::Component(reinterpret_cast<const uint8_t*>(str.data()), str.size()));
-}
-
-inline void
-RegexPseudoMatcher::resetMatchResult()
-{
- m_matchResult.clear();
-}
-
-inline void
-RegexPseudoMatcher::compile()
-{
-}
-
} // namespace ndn
#endif // NDN_UTIL_REGEX_REGEX_PSEUDO_MATCHER_HPP
diff --git a/src/util/regex/regex-repeat-matcher.cpp b/src/util/regex/regex-repeat-matcher.cpp
new file mode 100644
index 0000000..17986bf
--- /dev/null
+++ b/src/util/regex/regex-repeat-matcher.cpp
@@ -0,0 +1,176 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
+ */
+
+#include "regex-repeat-matcher.hpp"
+#include "regex-backref-matcher.hpp"
+#include "regex-component-set-matcher.hpp"
+
+#include <boost/regex.hpp>
+#include <cstdlib>
+
+namespace ndn {
+
+RegexRepeatMatcher::RegexRepeatMatcher(const std::string& expr,
+ shared_ptr<RegexBackrefManager> backrefManager,
+ size_t indicator)
+ : RegexMatcher(expr, EXPR_REPEAT_PATTERN, std::move(backrefManager))
+ , m_indicator(indicator)
+{
+ compile();
+}
+
+void
+RegexRepeatMatcher::compile()
+{
+ if ('(' == m_expr[0]) {
+ auto matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
+ m_backrefManager->pushRef(matcher);
+ matcher->lateCompile();
+ m_matchers.push_back(std::move(matcher));
+ }
+ else {
+ m_matchers.push_back(make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator),
+ m_backrefManager));
+ }
+
+ parseRepetition();
+}
+
+bool
+RegexRepeatMatcher::parseRepetition()
+{
+ size_t exprSize = m_expr.size();
+ const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
+
+ if (exprSize == m_indicator) {
+ m_repeatMin = 1;
+ m_repeatMax = 1;
+ return true;
+ }
+
+ if (exprSize == (m_indicator + 1)) {
+ if ('?' == m_expr[m_indicator]) {
+ m_repeatMin = 0;
+ m_repeatMax = 1;
+ return true;
+ }
+ if ('+' == m_expr[m_indicator]) {
+ m_repeatMin = 1;
+ m_repeatMax = MAX_REPETITIONS;
+ return true;
+ }
+ if ('*' == m_expr[m_indicator]) {
+ m_repeatMin = 0;
+ m_repeatMax = MAX_REPETITIONS;
+ return true;
+ }
+ }
+ else {
+ std::string repeatStruct = m_expr.substr(m_indicator, exprSize - m_indicator);
+ size_t rsSize = repeatStruct.size();
+ size_t min = 0;
+ size_t max = 0;
+
+ if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))) {
+ size_t separator = repeatStruct.find_first_of(',', 0);
+ min = std::atoi(repeatStruct.substr(1, separator - 1).data());
+ max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
+ }
+ else if (boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))) {
+ size_t separator = repeatStruct.find_first_of(',', 0);
+ min = 0;
+ max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
+ }
+ else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))) {
+ size_t separator = repeatStruct.find_first_of(',', 0);
+ min = std::atoi(repeatStruct.substr(1, separator).data());
+ max = MAX_REPETITIONS;
+ }
+ else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))) {
+ min = std::atoi(repeatStruct.substr(1, rsSize - 1).data());
+ max = min;
+ }
+ else
+ BOOST_THROW_EXCEPTION(Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
+ + " Unrecognized format " + m_expr));
+
+ if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
+ BOOST_THROW_EXCEPTION(Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
+ + " Wrong number " + m_expr));
+
+ m_repeatMin = min;
+ m_repeatMax = max;
+
+ return true;
+ }
+
+ return false;
+}
+
+bool
+RegexRepeatMatcher::match(const Name& name, size_t offset, size_t len)
+{
+ m_matchResult.clear();
+
+ if (m_repeatMin == 0)
+ if (len == 0)
+ return true;
+
+ if (recursiveMatch(0, name, offset, len)) {
+ for (size_t i = offset; i < offset + len; i++)
+ m_matchResult.push_back(name.get(i));
+ return true;
+ }
+
+ return false;
+}
+
+bool
+RegexRepeatMatcher::recursiveMatch(size_t repeat, const Name& name, size_t offset, size_t len)
+{
+ ssize_t tried = len;
+
+ if (0 < len && repeat >= m_repeatMax) {
+ return false;
+ }
+
+ if (0 == len && repeat < m_repeatMin) {
+ return false;
+ }
+
+ if (0 == len && repeat >= m_repeatMin) {
+ return true;
+ }
+
+ auto matcher = m_matchers[0];
+ while (tried >= 0) {
+ if (matcher->match(name, offset, tried) &&
+ recursiveMatch(repeat + 1, name, offset + tried, len - tried))
+ return true;
+ tried--;
+ }
+
+ return false;
+}
+
+} // namespace ndn
diff --git a/src/util/regex/regex-repeat-matcher.hpp b/src/util/regex/regex-repeat-matcher.hpp
index 86af906..de29e02 100644
--- a/src/util/regex/regex-repeat-matcher.hpp
+++ b/src/util/regex/regex-repeat-matcher.hpp
@@ -57,155 +57,4 @@
} // namespace ndn
-#include "regex-backref-matcher.hpp"
-#include "regex-component-set-matcher.hpp"
-
-namespace ndn {
-
-inline
-RegexRepeatMatcher::RegexRepeatMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backrefManager,
- size_t indicator)
- : RegexMatcher(expr, EXPR_REPEAT_PATTERN, std::move(backrefManager))
- , m_indicator(indicator)
-{
- compile();
-}
-
-inline void
-RegexRepeatMatcher::compile()
-{
- if ('(' == m_expr[0]) {
- auto matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
- m_backrefManager->pushRef(matcher);
- matcher->lateCompile();
- m_matchers.push_back(std::move(matcher));
- }
- else {
- m_matchers.push_back(make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator),
- m_backrefManager));
- }
-
- parseRepetition();
-}
-
-inline bool
-RegexRepeatMatcher::parseRepetition()
-{
- size_t exprSize = m_expr.size();
- const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
-
- if (exprSize == m_indicator) {
- m_repeatMin = 1;
- m_repeatMax = 1;
- return true;
- }
-
- if (exprSize == (m_indicator + 1)) {
- if ('?' == m_expr[m_indicator]) {
- m_repeatMin = 0;
- m_repeatMax = 1;
- return true;
- }
- if ('+' == m_expr[m_indicator]) {
- m_repeatMin = 1;
- m_repeatMax = MAX_REPETITIONS;
- return true;
- }
- if ('*' == m_expr[m_indicator]) {
- m_repeatMin = 0;
- m_repeatMax = MAX_REPETITIONS;
- return true;
- }
- }
- else {
- std::string repeatStruct = m_expr.substr(m_indicator, exprSize - m_indicator);
- size_t rsSize = repeatStruct.size();
- size_t min = 0;
- size_t max = 0;
-
- if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))) {
- size_t separator = repeatStruct.find_first_of(',', 0);
- min = std::atoi(repeatStruct.substr(1, separator - 1).data());
- max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
- }
- else if (boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))) {
- size_t separator = repeatStruct.find_first_of(',', 0);
- min = 0;
- max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
- }
- else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))) {
- size_t separator = repeatStruct.find_first_of(',', 0);
- min = std::atoi(repeatStruct.substr(1, separator).data());
- max = MAX_REPETITIONS;
- }
- else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))) {
- min = std::atoi(repeatStruct.substr(1, rsSize - 1).data());
- max = min;
- }
- else
- BOOST_THROW_EXCEPTION(Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
- + " Unrecognized format " + m_expr));
-
- if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
- BOOST_THROW_EXCEPTION(Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
- + " Wrong number " + m_expr));
-
- m_repeatMin = min;
- m_repeatMax = max;
-
- return true;
- }
-
- return false;
-}
-
-inline bool
-RegexRepeatMatcher::match(const Name& name, size_t offset, size_t len)
-{
- m_matchResult.clear();
-
- if (m_repeatMin == 0)
- if (len == 0)
- return true;
-
- if (recursiveMatch(0, name, offset, len)) {
- for (size_t i = offset; i < offset + len; i++)
- m_matchResult.push_back(name.get(i));
- return true;
- }
-
- return false;
-}
-
-inline bool
-RegexRepeatMatcher::recursiveMatch(size_t repeat, const Name& name, size_t offset, size_t len)
-{
- ssize_t tried = len;
-
- if (0 < len && repeat >= m_repeatMax) {
- return false;
- }
-
- if (0 == len && repeat < m_repeatMin) {
- return false;
- }
-
- if (0 == len && repeat >= m_repeatMin) {
- return true;
- }
-
- auto matcher = m_matchers[0];
- while (tried >= 0) {
- if (matcher->match(name, offset, tried) &&
- recursiveMatch(repeat + 1, name, offset + tried, len - tried))
- return true;
- tried--;
- }
-
- return false;
-}
-
-} // namespace ndn
-
#endif // NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP