Skip to content

Commit 86f61b9

Browse files
committed
基本支持通配符
1 parent 88ea6be commit 86f61b9

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Util/src/StringUtil.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Util/StringUtil.h"
22
#include <cstdlib>
33
#include <cstring>
4-
4+
#include <algorithm>
55
#include "wildcards/match.hpp"
66

77
std::vector<std::string_view> StringUtil::Split(std::string_view source, std::string_view separator)
@@ -162,16 +162,30 @@ struct equal_to
162162
{
163163
constexpr auto operator()(const char& lhs, const char& rhs) const -> decltype(lhs == rhs)
164164
{
165-
if (lhs == rhs)
166-
{
167-
return true;
168-
}
169-
return (lhs == '\\' || lhs == '/') && (rhs == '\\' || rhs == '/');
165+
return lhs == rhs
166+
|| ((lhs == '\\' || lhs == '/') && (rhs == '\\' || rhs == '/'))
167+
|| (::tolower(lhs) == ::tolower(rhs));
170168
}
171169
};
172170

173171
bool StringUtil::FileWildcardMatch(std::string_view sourceFile, std::string_view pattern)
174172
{
175-
return wildcards::match(sourceFile, pattern, equal_to()).res;
176-
}
173+
equal_to eq;
177174

175+
auto minSize = std::min(sourceFile.size(), pattern.size());
176+
bool match = true;
177+
for (std::size_t i = 0; i != minSize; i++)
178+
{
179+
if(!eq(sourceFile[i], pattern[i]))
180+
{
181+
match = false;
182+
break;
183+
}
184+
}
185+
186+
if(!match)
187+
{
188+
match = wildcards::match(sourceFile, pattern, equal_to()).res;
189+
}
190+
return match;
191+
}

0 commit comments

Comments
 (0)