28 #include <boost/regex.hpp> 34 shared_ptr<RegexBackrefManager> backrefManager,
37 , m_indicator(indicator)
48 matcher->lateCompile();
52 m_matchers.push_back(make_shared<RegexComponentSetMatcher>(
m_expr.substr(0, m_indicator),
60 RegexRepeatMatcher::parseRepetition()
62 size_t exprSize =
m_expr.size();
63 const size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
65 if (exprSize == m_indicator) {
71 if (exprSize == (m_indicator + 1)) {
72 if (
'?' ==
m_expr[m_indicator]) {
77 if (
'+' ==
m_expr[m_indicator]) {
79 m_repeatMax = MAX_REPETITIONS;
82 if (
'*' ==
m_expr[m_indicator]) {
84 m_repeatMax = MAX_REPETITIONS;
89 std::string repeatStruct =
m_expr.substr(m_indicator, exprSize - m_indicator);
90 size_t rsSize = repeatStruct.size();
94 if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,[0-9]+\\}"))) {
95 size_t separator = repeatStruct.find_first_of(
',', 0);
96 min = std::atoi(repeatStruct.substr(1, separator - 1).data());
97 max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
99 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{,[0-9]+\\}"))) {
100 size_t separator = repeatStruct.find_first_of(
',', 0);
102 max = std::atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).data());
104 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+,\\}"))) {
105 size_t separator = repeatStruct.find_first_of(
',', 0);
106 min = std::atoi(repeatStruct.substr(1, separator).data());
107 max = MAX_REPETITIONS;
109 else if (boost::regex_match(repeatStruct, boost::regex(
"\\{[0-9]+\\}"))) {
110 min = std::atoi(repeatStruct.substr(1, rsSize - 1).data());
114 BOOST_THROW_EXCEPTION(Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
115 +
" Unrecognized format " +
m_expr));
117 if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
118 BOOST_THROW_EXCEPTION(Error(std::string(
"Error: RegexRepeatMatcher.ParseRepetition():")
119 +
" Wrong number " +
m_expr));
135 if (m_repeatMin == 0)
139 if (recursiveMatch(0,
name, offset, len)) {
140 for (
size_t i = offset; i < offset + len; i++)
149 RegexRepeatMatcher::recursiveMatch(
size_t repeat,
const Name&
name,
size_t offset,
size_t len)
153 if (0 < len && repeat >= m_repeatMax) {
157 if (0 == len && repeat < m_repeatMin) {
161 if (0 == len && repeat >= m_repeatMin) {
167 if (matcher->match(
name, offset, tried) &&
168 recursiveMatch(repeat + 1,
name, offset + tried, len - tried))
Copyright (c) 2011-2015 Regents of the University of California.
RegexRepeatMatcher(const std::string &expr, shared_ptr< RegexBackrefManager > backrefManager, size_t indicator)
shared_ptr< RegexBackrefManager > m_backrefManager
bool match(const Name &name, size_t offset, size_t len) override
std::vector< shared_ptr< RegexMatcher > > m_matchers
std::vector< name::Component > m_matchResult
Represents an absolute name.
void compile() override
Compile the regular expression to generate the more matchers when necessary.