@@ -52,18 +52,40 @@ std::unique_ptr<DirectoryTree> DirectoryTree::Create(Filesystem& fs) {
5252}
5353
5454bool DirectoryTree::WildcardMatch (const StringView& pattern, const StringView& text) {
55- if (pattern.length () != text.length ()) {
56- return false ;
55+ // Limitations: * and ? cannot be mixed, * only at beginning and end of string
56+ // Input is already lower-cased
57+ if (pattern.empty () && text.empty ()) {
58+ return true ;
5759 }
5860
59- std::string pattern_norm = make_key ( pattern);
60- std::string text_norm = make_key (text );
61+ bool begin_wildcard = pattern. starts_with ( ' * ' );
62+ bool end_wildcard = pattern. ends_with ( ' * ' );
6163
62- return std::equal (pattern_norm.begin (), pattern_norm.end (),
63- text_norm.begin (),
64- [](char p, char t) {
65- return p == ' ?' || p == t;
66- });
64+ if ((begin_wildcard || end_wildcard) && text.size () > 0 ) {
65+ // * handling
66+ bool found = false ;
67+ if (begin_wildcard) {
68+ found |= text.ends_with (pattern.substr (1 ));
69+ }
70+ if (end_wildcard) {
71+ found |= text.starts_with (pattern.substr (0 , pattern.size () - 1 ));
72+ }
73+ return found;
74+ } else {
75+ // ? handling
76+ if (pattern.length () != text.length ()) {
77+ return false ;
78+ }
79+
80+ std::string pattern_norm = make_key (pattern);
81+ std::string text_norm = make_key (text);
82+
83+ return std::equal (pattern_norm.begin (), pattern_norm.end (),
84+ text_norm.begin (),
85+ [](char p, char t) {
86+ return p == ' ?' || p == t;
87+ });
88+ }
6789}
6890
6991DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory (StringView path) const {
0 commit comments