diff options
author | zhipeng li <qiuxinyidian@gmail.com> | 2023-08-25 18:54:38 +0200 |
---|---|---|
committer | Zhipeng Li <qiuxinyidian@gmail.com> | 2023-12-21 16:40:45 +0100 |
commit | 94fa9bd2d90857ca2c6a956a79406318ab2fa485 (patch) | |
tree | fe61cc48e9163ca31f47e9961d299527e0be9cd1 /src/rgw/rgw_string.cc | |
parent | Merge pull request #52723 from lxbsz/wip-62245 (diff) | |
download | ceph-94fa9bd2d90857ca2c6a956a79406318ab2fa485.tar.xz ceph-94fa9bd2d90857ca2c6a956a79406318ab2fa485.zip |
rgw: modify string match_wildcards with fnmatch
Fixes: https://tracker.ceph.com/issues/62292
Signed-off-by: zhipeng li <qiuxinyidian@gmail.com>
Diffstat (limited to 'src/rgw/rgw_string.cc')
-rw-r--r-- | src/rgw/rgw_string.cc | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/src/rgw/rgw_string.cc b/src/rgw/rgw_string.cc index 7be82f854a8..420db96c4f2 100644 --- a/src/rgw/rgw_string.cc +++ b/src/rgw/rgw_string.cc @@ -2,44 +2,21 @@ // vim: ts=8 sw=2 smarttab ft=cpp #include "rgw_string.h" +#include <fnmatch.h> -static bool char_eq(char c1, char c2) -{ - return c1 == c2; -} - -static bool ci_char_eq(char c1, char c2) -{ - return tolower(c1) == tolower(c2); -} - -bool match_wildcards(std::string_view pattern, std::string_view input, +bool match_wildcards(const std::string& pattern, const std::string& input, uint32_t flags) { - const auto eq = (flags & MATCH_CASE_INSENSITIVE) ? &ci_char_eq : &char_eq; + bool case_insensive = flags & MATCH_CASE_INSENSITIVE; + uint32_t flag = 0; + + if (case_insensive) { + flag = FNM_CASEFOLD; + } - auto it1 = pattern.begin(); - auto it2 = input.begin(); - while (true) { - if (it1 == pattern.end()) - return it2 == input.end(); - if (*it1 == '*') { - if (it1 + 1 == pattern.end()) - return true; - if (it2 == input.end() || eq(*(it1 + 1), *it2)) - ++it1; - else - ++it2; - continue; - } - if (it2 == input.end()) - return false; - if (*it1 == '?' || eq(*it1, *it2)) { - ++it1; - ++it2; - continue; - } + if (fnmatch(pattern.data(), input.data(), flag) == 0) { + return true; + } else { return false; } - return false; } |