30 if (lhs.size() != rhs.size())
31 return (lhs.size() < rhs.size()) ? -1 : 1;
32 for (
unsigned int i = 0; i < lhs.size(); ++i) {
33 const int c1 = std::toupper(lhs[i]);
34 const int c2 = std::toupper(rhs[i]);
36 return (c1 < c2) ? -1 : 1;
43 for (std::string::const_iterator i = pattern.cbegin(); i != pattern.cend(); ++i) {
44 if (*i ==
'*' || *i ==
'?') {
45 const std::string::const_iterator j = i + 1;
46 if (j != pattern.cend() && (*j ==
'*' || *j ==
'?')) {
54 bool matchglob(
const std::string& pattern,
const std::string& name)
56 const char* p = pattern.c_str();
57 const char* n = name.c_str();
58 std::stack<std::pair<const char*, const char*>, std::vector<std::pair<const char*, const char*>>> backtrack;
62 while (*p !=
'\0' && matching) {
66 while (*n !=
'\0' && *n != p[1]) {
71 backtrack.emplace(p, n);
86 }
else if (*n ==
'\\' && *p ==
'/') {
88 }
else if (*n ==
'/' && *p ==
'\\') {
99 if (matching && *n ==
'\0') {
104 if (backtrack.empty()) {
109 p = backtrack.top().first;
110 n = backtrack.top().second;
118 bool matchglobs(
const std::vector<std::string> &patterns,
const std::string &name) {
119 return std::any_of(begin(patterns), end(patterns), [&name](
const std::string &pattern) {
128 std::transform(str.cbegin(), str.cend(), str.begin(), [](
int c) {
129 return std::tolower(c);
133 std::string
trim(
const std::string& s,
const std::string& t)
135 const std::string::size_type beg = s.find_first_not_of(t);
136 if (beg == std::string::npos)
138 const std::string::size_type end = s.find_last_not_of(t);
139 return s.substr(beg, end - beg + 1);
142 void findAndReplace(std::string &source,
const std::string &searchFor,
const std::string &replaceWith)
144 std::string::size_type index = 0;
145 while ((index = source.find(searchFor, index)) != std::string::npos) {
146 source.replace(index, searchFor.length(), replaceWith);
147 index += replaceWith.length();
bool matchglob(const std::string &pattern, const std::string &name)
void findAndReplace(std::string &source, const std::string &searchFor, const std::string &replaceWith)
Replace all occurrences of searchFor with replaceWith in the given source.
int caseInsensitiveStringCompare(const std::string &lhs, const std::string &rhs)
bool isValidGlobPattern(const std::string &pattern)
bool matchglobs(const std::vector< std::string > &patterns, const std::string &name)
void strTolower(std::string &str)
std::string trim(const std::string &s, const std::string &t)
Remove heading and trailing whitespaces from the input parameter.