34 shared_ptr<RegexBackrefManager> backrefManager,
36 :
RegexMatcher(expr, EXPR_REPEAT_PATTERN, std::move(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 (std::regex_match(repeatStruct, std::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 (std::regex_match(repeatStruct, std::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 (std::regex_match(repeatStruct, std::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 (std::regex_match(repeatStruct, std::regex(
"\\{[0-9]+\\}"))) {
110 min = std::atoi(repeatStruct.substr(1, rsSize - 1).data());
114 BOOST_THROW_EXCEPTION(Error(
"RegexRepeatMatcher::parseRepetition(): Unrecognized format " +
m_expr));
116 if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
117 BOOST_THROW_EXCEPTION(Error(
"RegexRepeatMatcher::parseRepetition(): Wrong number " +
m_expr));
133 if (m_repeatMin == 0)
137 if (recursiveMatch(0,
name, offset, len)) {
138 for (
size_t i = offset; i < offset + len; i++)
147 RegexRepeatMatcher::recursiveMatch(
size_t repeat,
const Name&
name,
size_t offset,
size_t len)
151 if (0 < len && repeat >= m_repeatMax) {
155 if (0 == len && repeat < m_repeatMin) {
159 if (0 == len && repeat >= m_repeatMin) {
165 if (matcher->match(
name, offset, tried) &&
166 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.