summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileSearch.cpp
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2015-10-02 04:00:23 +1300
committerScott Mansell <phiren@gmail.com>2015-10-02 04:00:23 +1300
commit58d893e56f05d6e8a1f4b61fd40e5d98793dc874 (patch)
tree0bc58d68011d218124594fecbdf421a4b8f853e8 /Source/Core/Common/FileSearch.cpp
parent696d6eae099feba23c280017c5184785fc1e3076 (diff)
parent06c6f60f5bd67d00b6a7d176b4cc3babacc04ab9 (diff)
Merge pull request #3075 from waddlesplash/no-regexp
FileSearch: Don't use RegExes, just do string comparisons.
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;
+ });
});
}