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,
63 recursiveMatch(
size_t repeat,
65 size_t offset,
size_t len);
82 shared_ptr<RegexBackrefManager> backrefManager,
85 , m_indicator(indicator)
93 shared_ptr<RegexMatcher> matcher;
101 matcher = make_shared<RegexComponentSetMatcher>(
m_expr.substr(0, m_indicator),
110 RegexRepeatMatcher::parseRepetition()
112 size_t exprSize =
m_expr.size();
113 const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
115 if (exprSize == m_indicator) {
122 if (exprSize == (m_indicator + 1)) {
123 if (
'?' ==
m_expr[m_indicator]) {
128 if (
'+' ==
m_expr[m_indicator]) {
130 m_repeatMax = MAX_REPETITIONS;
133 if (
'*' ==
m_expr[m_indicator]) {
135 m_repeatMax = MAX_REPETITIONS;
140 std::string repeatStruct =
m_expr.substr(m_indicator, exprSize - m_indicator);
141 size_t rsSize = repeatStruct.size();
145 if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,[0-9]+\\}"))) {
146 size_t separator = repeatStruct.find_first_of(
',', 0);
147 min = atoi(repeatStruct.substr(1, separator - 1).c_str());
148 max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
150 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{,[0-9]+\\}"))) {
151 size_t separator = repeatStruct.find_first_of(
',', 0);
153 max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
155 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,\\}"))) {
156 size_t separator = repeatStruct.find_first_of(
',', 0);
157 min = atoi(repeatStruct.substr(1, separator).c_str());
158 max = MAX_REPETITIONS;
160 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+\\}"))) {
161 min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
165 BOOST_THROW_EXCEPTION(
RegexMatcher::Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
166 +
" Unrecognized format "+
m_expr));
168 if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
169 BOOST_THROW_EXCEPTION(
RegexMatcher::Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
170 +
" Wrong number " +
m_expr));
186 if (0 == m_repeatMin)
190 if (recursiveMatch(0, name, offset, len))
192 for (
size_t i = offset; i < offset + len; i++)
201 RegexRepeatMatcher::recursiveMatch(
size_t repeat,
const Name&
name,
size_t offset,
size_t len)
204 shared_ptr<RegexMatcher> matcher =
m_matchers[0];
206 if (0 < len && repeat >= m_repeatMax)
211 if (0 == len && repeat < m_repeatMin)
216 if (0 == len && repeat >= m_repeatMin)
223 if (matcher->match(name, offset, tried) &&
224 recursiveMatch(repeat + 1, name, offset + tried, len - tried))
235 #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
Name abstraction to represent 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.