Adds support for string_view in Variable

This commit is contained in:
Felipe Zimmerle 2020-08-26 11:20:12 -03:00
parent 7f1633c1c2
commit 856a84106a
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277

View File

@ -105,6 +105,7 @@ class KeyExclusion {
public:
KeyExclusion() { }
virtual bool match(const std::string &a) = 0;
virtual bool match(const bpstd::string_view &a) = 0;
virtual ~KeyExclusion() { }
};
@ -122,6 +123,10 @@ class KeyExclusionRegex : public KeyExclusion {
bool match(const std::string &a) override {
return m_re.searchAll(a).size() > 0;
}
bool match(const bpstd::string_view &a) override {
// FIXME: string_view will be a good thing in searchAll.
return m_re.searchAll(std::string(a)).size() > 0;
}
Utils::Regex m_re;
};
@ -141,6 +146,13 @@ class KeyExclusionString : public KeyExclusion {
return static_cast<char>(toupper(aa)) == static_cast<char>(bb);
});
}
bool match(const bpstd::string_view &a) override {
return a.size() == m_key.size() && std::equal(a.begin(), a.end(),
m_key.begin(),
[](char aa, char bb) {
return static_cast<char>(toupper(aa)) == static_cast<char>(bb);
});
}
std::string m_key;
};
@ -162,7 +174,7 @@ class KeyExclusions : public std::deque<std::unique_ptr<KeyExclusion>> {
//}
};
bool toOmit(std::string a) {
bool toOmit(const std::string &a) {
for (auto &z : *this) {
if (z->match(a)) {
return true;
@ -170,6 +182,16 @@ class KeyExclusions : public std::deque<std::unique_ptr<KeyExclusion>> {
}
return false;
}
bool toOmit(const bpstd::string_view &a) {
for (auto &z : *this) {
if (z->match(a)) {
return true;
}
}
return false;
}
};