24 #ifndef NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP 25 #define NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP 27 #include "../../common.hpp" 29 #include <boost/regex.hpp> 39 shared_ptr<RegexBackrefManager> backrefManager,
62 recursiveMatch(
size_t repeat,
64 size_t offset,
size_t len);
81 shared_ptr<RegexBackrefManager> backrefManager,
84 , m_indicator(indicator)
92 shared_ptr<RegexMatcher> matcher;
100 matcher = make_shared<RegexComponentSetMatcher>(
m_expr.substr(0, m_indicator),
109 RegexRepeatMatcher::parseRepetition()
111 size_t exprSize =
m_expr.size();
112 const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
114 if (exprSize == m_indicator) {
121 if (exprSize == (m_indicator + 1)) {
122 if (
'?' ==
m_expr[m_indicator]) {
127 if (
'+' ==
m_expr[m_indicator]) {
129 m_repeatMax = MAX_REPETITIONS;
132 if (
'*' ==
m_expr[m_indicator]) {
134 m_repeatMax = MAX_REPETITIONS;
139 std::string repeatStruct =
m_expr.substr(m_indicator, exprSize - m_indicator);
140 size_t rsSize = repeatStruct.size();
144 if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,[0-9]+\\}"))) {
145 size_t separator = repeatStruct.find_first_of(
',', 0);
146 min = atoi(repeatStruct.substr(1, separator - 1).c_str());
147 max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
149 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{,[0-9]+\\}"))) {
150 size_t separator = repeatStruct.find_first_of(
',', 0);
152 max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
154 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,\\}"))) {
155 size_t separator = repeatStruct.find_first_of(
',', 0);
156 min = atoi(repeatStruct.substr(1, separator).c_str());
157 max = MAX_REPETITIONS;
159 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+\\}"))) {
160 min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
164 BOOST_THROW_EXCEPTION(
RegexMatcher::Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
165 +
" Unrecognized format "+
m_expr));
167 if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
168 BOOST_THROW_EXCEPTION(
RegexMatcher::Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
169 +
" Wrong number " +
m_expr));
185 if (0 == m_repeatMin)
189 if (recursiveMatch(0, name, offset, len))
191 for (
size_t i = offset; i < offset + len; i++)
200 RegexRepeatMatcher::recursiveMatch(
size_t repeat,
const Name&
name,
size_t offset,
size_t len)
203 shared_ptr<RegexMatcher> matcher =
m_matchers[0];
205 if (0 < len && repeat >= m_repeatMax)
210 if (0 == len && repeat < m_repeatMin)
215 if (0 == len && repeat >= m_repeatMin)
222 if (matcher->match(name, offset, tried) &&
223 recursiveMatch(repeat + 1, name, offset + tried, len - tried))
234 #endif // NDN_UTIL_REGEX_REGEX_REPEAT_MATCHER_HPP Copyright (c) 2011-2015 Regents of the University of California.
RegexRepeatMatcher(const std::string &expr, shared_ptr< RegexBackrefManager > backrefManager, size_t indicator)
virtual void compile()
Compile the regular expression to generate the more matchers when necessary.
shared_ptr< RegexBackrefManager > m_backrefManager
std::vector< shared_ptr< RegexMatcher > > m_matchers
std::vector< name::Component > m_matchResult
Represents an absolute name.
virtual ~RegexRepeatMatcher()
virtual bool match(const Name &name, size_t offset, size_t len)
const Component & get(ssize_t i) const
Get the component at the given index.