]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_string.cc
update sources to v12.1.3
[ceph.git] / ceph / src / rgw / rgw_string.cc
CommitLineData
d2e6a577
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "rgw_string.h"
5
6static bool char_eq(char c1, char c2)
7{
8 return c1 == c2;
9}
10
11static bool ci_char_eq(char c1, char c2)
12{
13 return tolower(c1) == tolower(c2);
14}
15
16bool match_wildcards(boost::string_view pattern, boost::string_view input,
17 uint32_t flags)
18{
19 const auto eq = (flags & MATCH_CASE_INSENSITIVE) ? &ci_char_eq : &char_eq;
20
21 auto it1 = pattern.begin();
22 auto it2 = input.begin();
23 while (true) {
24 if (it1 == pattern.end())
25 return it2 == input.end();
26 if (*it1 == '*') {
27 if (it1 + 1 == pattern.end())
28 return true;
29 if (it2 == input.end() || eq(*(it1 + 1), *it2))
30 ++it1;
31 else
32 ++it2;
33 continue;
34 }
35 if (it2 == input.end())
36 return false;
37 if (*it1 == '?' || eq(*it1, *it2)) {
38 ++it1;
39 ++it2;
40 continue;
41 }
42 return false;
43 }
44 return false;
45}