33 shared_ptr<RegexBackrefManager> backrefManager,
36 , m_indicator(indicator)
42 RegexRepeatMatcher::compile()
45 auto matcher = make_shared<RegexBackrefMatcher>(
m_expr.substr(0, m_indicator),
52 m_matchers.push_back(make_shared<RegexComponentSetMatcher>(
m_expr.substr(0, m_indicator),
60 RegexRepeatMatcher::parseRepetition()
62 constexpr
size_t MAX_REPETITIONS = std::numeric_limits<size_t>::max();
63 size_t exprSize =
m_expr.size();
65 if (exprSize == m_indicator) {
69 else if (exprSize == m_indicator + 1) {
70 switch (
m_expr[m_indicator]) {
77 m_repeatMax = MAX_REPETITIONS;
81 m_repeatMax = MAX_REPETITIONS;
88 std::string repeatStruct =
m_expr.substr(m_indicator, exprSize - m_indicator);
89 size_t rsSize = repeatStruct.size();
92 if (std::regex_match(repeatStruct, std::regex(
"\\{[0-9]+,[0-9]+\\}"))) {
93 size_t separator = repeatStruct.find_first_of(
',', 0);
94 m_repeatMin = std::stoul(repeatStruct.substr(1, separator - 1));
95 m_repeatMax = std::stoul(repeatStruct.substr(separator + 1, rsSize - separator - 2));
96 if (m_repeatMin > m_repeatMax) {
100 else if (std::regex_match(repeatStruct, std::regex(
"\\{,[0-9]+\\}"))) {
101 size_t separator = repeatStruct.find_first_of(
',', 0);
103 m_repeatMax = std::stoul(repeatStruct.substr(separator + 1, rsSize - separator - 2));
105 else if (std::regex_match(repeatStruct, std::regex(
"\\{[0-9]+,\\}"))) {
106 size_t separator = repeatStruct.find_first_of(
',', 0);
107 m_repeatMin = std::stoul(repeatStruct.substr(1, separator));
108 m_repeatMax = MAX_REPETITIONS;
110 else if (std::regex_match(repeatStruct, std::regex(
"\\{[0-9]+\\}"))) {
111 m_repeatMin = std::stoul(repeatStruct.substr(1, rsSize - 1));
112 m_repeatMax = m_repeatMin;
119 catch (
const std::logic_error&) {
130 if (m_repeatMin == 0 && len == 0) {
134 if (recursiveMatch(0, name, offset, len)) {
135 for (
size_t i = offset; i < offset + len; i++) {
145 RegexRepeatMatcher::recursiveMatch(
size_t repeat,
const Name&
name,
size_t offset,
size_t len)
147 if (0 < len && repeat >= m_repeatMax) {
151 if (0 == len && repeat < m_repeatMin) {
155 if (0 == len && repeat >= m_repeatMin) {
160 ssize_t tried =
static_cast<ssize_t
>(len);
162 if (matcher->match(name, offset, tried) &&
163 recursiveMatch(repeat + 1, name, offset + tried, len - tried)) {
#define NDN_THROW_NESTED(e)
Copyright (c) 2011-2015 Regents of the University of California.
RegexRepeatMatcher(const std::string &expr, shared_ptr< RegexBackrefManager > backrefManager, size_t indicator)
const Component & get(ssize_t i) const
Returns an immutable reference to the component at the specified index.
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.