18 m_secondaryUsed(false)
20 m_primaryBackRefManager = make_shared<RegexBackrefManager>();
21 m_secondaryBackRefManager = make_shared<RegexBackrefManager>();
33 std::string errMsg =
"Error: RegexTopMatcher.Compile(): ";
37 if (
'$' != expr[expr.size() - 1])
38 expr = expr +
"<.*>*";
40 expr = expr.substr(0, expr.size()-1);
43 m_secondaryMatcher = make_shared<RegexPatternListMatcher>(boost::cref(
"<.*>*" + expr),
44 boost::cref(m_secondaryBackRefManager));
46 expr = expr.substr(1, expr.size()-1);
48 m_primaryMatcher = make_shared<RegexPatternListMatcher>(boost::cref(expr),
49 boost::cref(m_primaryBackRefManager));
55 m_secondaryUsed =
false;
59 if (m_primaryMatcher->match(name, 0, name.
size()))
66 if (NULL != m_secondaryMatcher && m_secondaryMatcher->match(name, 0, name.
size()))
69 m_secondaryUsed =
true;
87 shared_ptr<RegexBackrefManager> backRefManager = (m_secondaryUsed ? m_secondaryBackRefManager : m_primaryBackRefManager);
89 int backRefNum = backRefManager->
size();
99 while (offset < expand.size())
101 std::string item = getItemFromExpand(expand, offset);
104 result.
append(item.substr(1, item.size() - 2));
109 int index = atoi(item.substr(1, item.size() - 1).c_str());
112 std::vector<name::Component>::iterator it =
m_matchResult.begin();
113 std::vector<name::Component>::iterator end =
m_matchResult.end();
114 for(; it != end; it++)
117 else if (index <= backRefNum)
119 std::vector<name::Component>::const_iterator it = backRefManager->getBackRef (index - 1)->getMatchResult ().
begin();
120 std::vector<name::Component>::const_iterator end = backRefManager->getBackRef (index - 1)->getMatchResult ().
end();
121 for(; it != end; it++)
132 RegexTopMatcher::getItemFromExpand(
const std::string& expand,
size_t& offset)
134 size_t begin = offset;
136 if (expand[offset] ==
'\\')
139 if (offset >= expand.size())
142 while(expand[offset] <=
'9' and expand[offset] >=
'0'){
144 if (offset > expand.size())
147 if (offset > begin + 1)
148 return expand.substr(begin, offset - begin);
150 throw RegexMatcher::Error(
"wrong format of expand string!");
152 else if (expand[offset] ==
'<')
155 if (offset >= expand.size())
156 throw RegexMatcher::Error(
"wrong format of expand string!");
162 if (expand[offset] ==
'<')
164 if (expand[offset] ==
'>')
167 if (offset >= expand.size())
168 throw RegexMatcher::Error(
"wrong format of expand string!");
170 return expand.substr(begin, offset - begin);
173 throw RegexMatcher::Error(
"wrong format of expand string!");
176 shared_ptr<RegexTopMatcher>
180 std::string regexStr(
"^");
182 for(; it != name.
end(); it++)
184 regexStr.append(
"<");
186 regexStr.append(
">");
190 regexStr.append(
"$");
192 return make_shared<RegexTopMatcher>(boost::cref(regexStr));
196 RegexTopMatcher::convertSpecialChar(
const std::string& str)
199 for(
size_t i = 0; i < str.size(); i++)
217 newStr.push_back(
'\\');
const_iterator begin() const
Begin iterator (const).
void toEscapedString(std::ostream &result) const
Write the value to result, escaping characters according to the NDN URI Scheme.
static shared_ptr< RegexTopMatcher > fromName(const Name &name, bool hasAnchor=false)
Buffer::const_iterator end() const
const_iterator end() const
End iterator (const).
virtual void compile()
Compile the regular expression to generate the more matchers when necessary.
size_t size() const
Get the number of components.
std::vector< name::Component > m_matchResult
A Name holds an array of Name::Component and represents an NDN name.
virtual Name expand(const std::string &expand="")
Component holds a read-only name component value.
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
bool match(const Name &name)
virtual ~RegexTopMatcher()
RegexTopMatcher(const std::string &expr, const std::string &expand="")