Skip to content

Commit

Permalink
Merge pull request #5688 from shuffle2/improve-search-comparison
Browse files Browse the repository at this point in the history
Use CompareStringOrdinal in DoFileSearch instead of _wcsicmp
  • Loading branch information
JosJuice committed Jun 26, 2017
2 parents 88b442e + 1634f0c commit a07611c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Source/Core/Common/FileSearch.cpp
Expand Up @@ -9,6 +9,7 @@
#include "Common/FileSearch.h"

#ifdef _MSC_VER
#include <Windows.h>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#define HAS_STD_FILESYSTEM
Expand Down Expand Up @@ -85,9 +86,10 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
return std::any_of(native_exts.cbegin(), native_exts.cend(), [&native_path](const auto& ext) {
// TODO provide cross-platform compat for the comparison function, once more platforms
// support std::filesystem
return native_path.length() >= ext.native().length() &&
_wcsicmp(&native_path.c_str()[native_path.length() - ext.native().length()],
ext.c_str()) == 0;
int compare_len = static_cast<int>(ext.native().length());
return native_path.length() >= compare_len &&
CompareStringOrdinal(&native_path.c_str()[native_path.length() - compare_len],
compare_len, ext.c_str(), compare_len, TRUE) == CSTR_EQUAL;
});
};

Expand All @@ -102,12 +104,12 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
if (recursive)
{
// TODO use fs::directory_options::follow_directory_symlink ?
for (auto& entry : fs::recursive_directory_iterator(fs::path(directory.c_str())))
for (auto& entry : fs::recursive_directory_iterator(fs::path(directory)))
add_filtered(entry);
}
else
{
for (auto& entry : fs::directory_iterator(fs::path(directory.c_str())))
for (auto& entry : fs::directory_iterator(fs::path(directory)))
add_filtered(entry);
}
}
Expand Down

0 comments on commit a07611c

Please sign in to comment.