summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileSearch.cpp
diff options
context:
space:
mode:
authorwaddlesplash <waddlesplash@gmail.com>2015-09-21 20:01:08 -0400
committerwaddlesplash <waddlesplash@gmail.com>2015-09-27 13:25:51 -0400
commit5643fe5d1f55f6311d842d73c4614c3577bd10e2 (patch)
tree68a0d325970ea1a7ed36eeb3fc619d2a73f0ce56 /Source/Core/Common/FileSearch.cpp
parent79bf93996fbfc713c1d6aa641b3af061d1d33c36 (diff)
FileSearch: Don't use RegExs, just do string comparisons.
Nothing used the RegEx feature of FileSearch, and GCC < 4.9 doesn't support C++11 RegEx properly, so get rid of it.
Diffstat (limited to 'Source/Core/Common/FileSearch.cpp')
-rw-r--r--Source/Core/Common/FileSearch.cpp26
1 files changed, 9 insertions, 17 deletions
diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp
index b5395cf21c..451c451030 100644
--- a/Source/Core/Common/FileSearch.cpp
+++ b/Source/Core/Common/FileSearch.cpp
@@ -2,13 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
-#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ < 9
-#error <regex> is broken in GCC < 4.9; please upgrade
-#endif
-
#include <algorithm>
#include <functional>
-#include <regex>
#include "Common/CommonPaths.h"
#include "Common/FileSearch.h"
@@ -37,20 +32,17 @@ static std::vector<std::string> FileSearchWithTest(const std::vector<std::string
return result;
}
-std::vector<std::string> DoFileSearch(const std::vector<std::string>& globs, const std::vector<std::string>& directories, bool recursive)
+std::vector<std::string> DoFileSearch(const std::vector<std::string>& exts, const std::vector<std::string>& directories, bool recursive)
{
- std::string regex_str = "^(";
- for (const auto& str : globs)
- {
- if (regex_str.size() != 2)
- regex_str += "|";
- // convert glob to regex
- regex_str += std::regex_replace(std::regex_replace(str, std::regex("\\."), "\\."), std::regex("\\*"), ".*");
- }
- regex_str += ")$";
- std::regex regex(regex_str, std::regex_constants::icase);
+ bool accept_all = std::find(exts.begin(), exts.end(), "") != exts.end();
return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) {
- return std::regex_match(entry.virtualName, regex);
+ if (accept_all)
+ return true;
+ std::string name = entry.virtualName;
+ std::transform(name.begin(), name.end(), name.begin(), ::tolower);
+ return std::any_of(exts.begin(), exts.end(), [&](const std::string& ext) {
+ return name.length() >= ext.length() && name.compare(name.length() - ext.length(), ext.length(), ext) == 0;
+ });
});
}