From 268d2ffe8b533890b408740db1a6a3730dfd8597 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sun, 17 May 2015 14:03:01 +0200 Subject: - some code cleanup and modernization trying to fix "dr memory" reports (though they were almost certainly false positives) - there is now a 50ms timeout on logging messages - bugfix: leaked handles after directory searches --- src/shared/util.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/shared/util.cpp') diff --git a/src/shared/util.cpp b/src/shared/util.cpp index e5bcd436..3692aae1 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -109,7 +109,7 @@ std::string &ToLower(std::string &text) std::string ToLower(const std::string &text) { - std::string result = text; + std::string result(text); std::transform(result.begin(), result.end(), result.begin(), locToLower); return result; } @@ -122,11 +122,26 @@ std::wstring &ToLower(std::wstring &text) std::wstring ToLower(const std::wstring &text) { - std::wstring result = text; + std::wstring result(text); std::transform(result.begin(), result.end(), result.begin(), locToLowerW); return result; } +bool CaseInsenstiveComparePred(wchar_t lhs, wchar_t rhs) +{ + return std::tolower(lhs, loc) == std::tolower(rhs, loc); +} + +bool CaseInsensitiveEqual(const std::wstring &lhs, const std::wstring &rhs) +{ + return (lhs.length() == rhs.length()) + && std::equal(lhs.begin(), lhs.end(), + rhs.begin(), + [] (wchar_t lhs, wchar_t rhs) -> bool { + return std::tolower(lhs, loc) == std::tolower(rhs, loc); + }); +} + VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName) { DWORD handle = 0UL; -- cgit v1.3.1