8 #ifndef NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
9 #define NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
11 #include "../../common.hpp"
33 match(
const Name& name,
const int& offset,
const int& len = 1);
45 extractComponent(
int index);
48 compileSingleComponent();
51 compileMultipleComponents(
const int start,
const int lastIndex);
54 typedef std::set<shared_ptr<RegexComponentMatcher> > ComponentsSet;
55 ComponentsSet m_components;
62 shared_ptr<RegexBackrefManager> backRefManager)
63 :
RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
85 return compileSingleComponent();
88 int lastIndex =
m_expr.size() - 1;
89 if (
']' !=
m_expr[lastIndex])
91 +
" No matched ']' " +
m_expr);
95 compileMultipleComponents(2, lastIndex);
98 compileMultipleComponents(1, lastIndex);
103 +
"Parsing error in expr " +
m_expr);
108 RegexComponentSetMatcher::compileSingleComponent()
110 size_t end = extractComponent(1);
115 std::string(
"Error: RegexComponentSetMatcher.compileSingleComponent: ") +
m_expr);
119 shared_ptr<RegexComponentMatcher> component =
122 m_components.insert(component);
127 RegexComponentSetMatcher::compileMultipleComponents(
const int start,
const int lastIndex)
130 int tmp_index = start;
132 while(index < lastIndex){
134 throw RegexMatcher::Error(
135 std::string(
"Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
136 "Component expr error " +
m_expr);
138 tmp_index = index + 1;
139 index = extractComponent(tmp_index);
141 shared_ptr<RegexComponentMatcher> component =
142 make_shared<RegexComponentMatcher>(
m_expr.substr(tmp_index, index - tmp_index - 1),
145 m_components.insert(component);
148 if (index != lastIndex)
149 throw RegexMatcher::Error(
150 std::string(
"Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
151 "Not sufficient expr to parse " +
m_expr);
157 bool matched =
false;
165 for (ComponentsSet::iterator it = m_components.begin();
166 it != m_components.end();
169 if ((*it)->match(name, offset, len))
178 if (m_include ? matched : !matched)
188 RegexComponentSetMatcher::extractComponent(
int index)
193 while(lcount > rcount){
216 #endif // NDN_UTIL_REGEX_COMPONENT_SET_MATCHER_HPP
RegexComponentSetMatcher(const std::string &expr, shared_ptr< RegexBackrefManager > backRefManager)
Create a RegexComponentSetMatcher matcher from expr.
virtual ~RegexComponentSetMatcher()
virtual bool match(const Name &name, const int &offset, const int &len=1)
shared_ptr< RegexBackrefManager > m_backrefManager
std::vector< name::Component > m_matchResult
A Name holds an array of Name::Component and represents an NDN name.
virtual void compile()
Compile the regular expression to generate the more matchers when necessary.
const Component & get(ssize_t i) const
Get the component at the given index.