Add const version of UrlParser::matchQueryParam

This commit is contained in:
Ai Lin Chia
2017-10-16 15:16:51 +02:00
parent 641b77d939
commit 8cb75b16e6
2 changed files with 28 additions and 6 deletions

@ -468,7 +468,7 @@ bool UrlParser::removePathParam(const UrlComponent::Matcher &matcher, const UrlC
return removeComponent(matches, validator);
}
std::vector<UrlComponent *> UrlParser::matchQueryParam(const UrlComponent::Matcher &matcher) {
const std::vector<UrlComponent *> UrlParser::matchQueryParam(const UrlComponent::Matcher &matcher) {
std::vector<UrlComponent *> result;
// don't need to loop if it's all deleted
@ -476,13 +476,34 @@ std::vector<UrlComponent *> UrlParser::matchQueryParam(const UrlComponent::Match
return result;
}
for (auto it = m_queries.begin(); it != m_queries.end(); ++it) {
if (it->isDeleted()) {
for (auto &query : m_queries) {
if (query.isDeleted()) {
continue;
}
if (matcher.isMatching(*it)) {
result.push_back(&(*it));
if (matcher.isMatching(query)) {
result.push_back(&query);
}
}
return result;
}
const std::vector<const UrlComponent *> UrlParser::matchQueryParam(const UrlComponent::Matcher &matcher) const {
std::vector<const UrlComponent *> result;
// don't need to loop if it's all deleted
if (m_queriesDeleteCount == m_queries.size()) {
return result;
}
for (const auto &query : m_queries) {
if (query.isDeleted()) {
continue;
}
if (matcher.isMatching(query)) {
result.push_back(&query);
}
}

@ -31,7 +31,8 @@ public:
return m_queries.size();
}
std::vector<UrlComponent*> matchQueryParam( const UrlComponent::Matcher &keyMatch );
const std::vector<UrlComponent*> matchQueryParam(const UrlComponent::Matcher &keyMatch);
const std::vector<const UrlComponent*> matchQueryParam(const UrlComponent::Matcher &keyMatch) const;
bool removeQueryParam( const char *param );
bool removeQueryParam( const std::vector<UrlComponent*> &urlComponents, const UrlComponent::Validator &validator );