diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index eaacb312..ecb972c1 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "StaticDialog.h" #include "Common.h" @@ -850,6 +851,64 @@ double stodLocale(const generic_string& str, _locale_t loc, size_t* idx) return ans; } +// Source: https://blogs.msdn.microsoft.com/greggm/2005/09/21/comparing-file-names-in-native-code/ +// Modified to use TCHAR's instead of assuming Unicode and reformatted to conform with Notepad++ code style +static TCHAR ToUpperInvariant(TCHAR input) +{ + TCHAR result; + LONG lres = LCMapString(LOCALE_INVARIANT, LCMAP_UPPERCASE, &input, 1, &result, 1); + if (lres == 0) + { + assert(false and "LCMapString failed to convert a character to upper case"); + result = input; + } + return result; +} + +// Source: https://blogs.msdn.microsoft.com/greggm/2005/09/21/comparing-file-names-in-native-code/ +// Modified to use TCHAR's instead of assuming Unicode and reformatted to conform with Notepad++ code style +int OrdinalIgnoreCaseCompareStrings(LPCTSTR sz1, LPCTSTR sz2) +{ + if (sz1 == sz2) + { + return 0; + } + + if (sz1 == nullptr) sz1 = _T(""); + if (sz2 == nullptr) sz2 = _T(""); + + for (;; sz1++, sz2++) + { + const TCHAR c1 = *sz1; + const TCHAR c2 = *sz2; + + // check for binary equality first + if (c1 == c2) + { + if (c1 == 0) + { + return 0; // We have reached the end of both strings. No difference found. + } + } + else + { + if (c1 == 0 || c2 == 0) + { + return (c1-c2); // We have reached the end of one string + } + + // IMPORTANT: this needs to be upper case to match the behavior of the operating system. + // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/StringsinNET20.asp + const TCHAR u1 = ToUpperInvariant(c1); + const TCHAR u2 = ToUpperInvariant(c2); + if (u1 != u2) + { + return (u1-u2); // strings are different + } + } + } +} + bool str2Clipboard(const generic_string &str2cpy, HWND hwnd) { size_t len2Allocate = (str2cpy.size() + 1) * sizeof(TCHAR); diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 20a76581..3d652293 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -178,6 +178,8 @@ generic_string stringJoin(const std::vector& strings, const gene generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable); double stodLocale(const generic_string& str, _locale_t loc, size_t* idx = NULL); +int OrdinalIgnoreCaseCompareStrings(LPCTSTR sz1, LPCTSTR sz2); + bool str2Clipboard(const generic_string &str2cpy, HWND hwnd); generic_string GetLastErrorAsString(DWORD errorCode = 0); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b69cb41e..a9a13d0f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1409,7 +1409,7 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vectorgetFullPathName())) + if (OrdinalIgnoreCaseCompareStrings(name, _buffers.at(i)->getFullPathName()) == 0) return _buffers.at(i)->getID(); } return BUFFER_INVALID; diff --git a/PowerEditor/src/ScitillaComponent/DocTabView.cpp b/PowerEditor/src/ScitillaComponent/DocTabView.cpp index 47f77ed3..437b4c64 100644 --- a/PowerEditor/src/ScitillaComponent/DocTabView.cpp +++ b/PowerEditor/src/ScitillaComponent/DocTabView.cpp @@ -96,7 +96,7 @@ BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not fo ::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast(&tie)); BufferID id = reinterpret_cast(tie.lParam); Buffer * buf = MainFileManager->getBufferByID(id); - if (!lstrcmp(fullfilename, buf->getFullPathName())) + if (OrdinalIgnoreCaseCompareStrings(fullfilename, buf->getFullPathName()) == 0) { return id; } diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 50e96f44..e91c1dc6 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -815,7 +815,7 @@ void FileBrowser::getDirectoryStructure(const TCHAR *dir, const std::vector