29 #include <boost/lexical_cast.hpp> 36 , m_isSecondaryUsed(false)
38 m_primaryBackrefManager = make_shared<RegexBackrefManager>();
39 m_secondaryBackrefManager = make_shared<RegexBackrefManager>();
50 std::string errMsg =
"Error: RegexTopMatcher.Compile(): ";
54 if (
'$' != expr[expr.size() - 1])
55 expr = expr +
"<.*>*";
57 expr = expr.substr(0, expr.size() - 1);
60 m_secondaryMatcher = make_shared<RegexPatternListMatcher>(
62 m_secondaryBackrefManager);
65 expr = expr.substr(1, expr.size() - 1);
70 m_primaryMatcher = ndn::make_shared<RegexPatternListMatcher>(expr,
71 m_primaryBackrefManager);
77 m_isSecondaryUsed =
false;
81 if (m_primaryMatcher->match(name, 0, name.
size()))
88 if (static_cast<bool>(m_secondaryMatcher) && m_secondaryMatcher->match(name, 0, name.
size()))
91 m_isSecondaryUsed =
true;
109 shared_ptr<RegexBackrefManager> backrefManager =
110 (m_isSecondaryUsed ? m_secondaryBackrefManager : m_primaryBackrefManager);
112 size_t backrefNo = backrefManager->
size();
116 if (!expandStr.empty())
122 while (offset < expand.size())
124 std::string item = getItemFromExpand(expand, offset);
127 result.
append(item.substr(1, item.size() - 2));
131 size_t index = boost::lexical_cast<
size_t>(item.substr(1, item.size() - 1));
136 for (; it != end; it++)
139 else if (index <= backrefNo)
141 std::vector<name::Component>::const_iterator it =
142 backrefManager->getBackref(index - 1)->getMatchResult().
begin();
143 std::vector<name::Component>::const_iterator end =
144 backrefManager->getBackref(index - 1)->getMatchResult().
end();
145 for (; it != end; it++)
156 RegexTopMatcher::getItemFromExpand(
const std::string&
expand,
size_t& offset)
158 size_t begin = offset;
160 if (expand[offset] ==
'\\')
163 if (offset >= expand.size())
166 while (expand[offset] <=
'9' and expand[offset] >=
'0') {
168 if (offset > expand.size())
171 if (offset > begin + 1)
172 return expand.substr(begin, offset - begin);
176 else if (expand[offset] ==
'<')
179 if (offset >= expand.size())
186 if (expand[offset] ==
'<')
188 if (expand[offset] ==
'>')
191 if (offset >= expand.size())
194 return expand.substr(begin, offset - begin);
200 shared_ptr<RegexTopMatcher>
203 std::string regexStr(
"^");
207 regexStr.append(
"<");
208 regexStr.append(convertSpecialChar(it->toUri()));
209 regexStr.append(
">");
213 regexStr.append(
"$");
217 return ndn::make_shared<RegexTopMatcher>(regexStr);
221 RegexTopMatcher::convertSpecialChar(
const std::string& str)
224 for (
size_t i = 0; i < str.size(); i++)
242 newStr.push_back(
'\\');
Copyright (c) 2011-2015 Regents of the University of California.
const_iterator begin() const
Begin iterator (const).
static shared_ptr< RegexTopMatcher > fromName(const Name &name, bool hasAnchor=false)
Buffer::const_iterator end() const
Table::const_iterator iterator
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
Name abstraction to represent an absolute 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="")