9
10
11
12
13
14
15
16
17
18
19
21inline bool wildcards_match(std::string_view str, std::string_view pattern)
23 const size_t n = str.size();
24 const size_t m = pattern.size();
27 std::vector<int8_t> memo((n + 1) * (m + 1), -1);
29 auto get_memo = [&](size_t i, size_t j) -> int8_t& {
return memo[i * (m + 1) + j]; };
31 auto match = [&](
auto& match_ref, size_t i, size_t j) ->
bool {
37 int8_t& cached = get_memo(i, j);
46 result = match_ref(match_ref, i, j + 1);
49 result = match_ref(match_ref, i + 1, j);
52 else if(i < n && (pattern[j] ==
'?' || pattern[j] == str[i]))
54 result = match_ref(match_ref, i + 1, j + 1);
61 cached = result ? 1 : 0;
65 return match(match, 0, 0);