Use standard function (wcscmp/wcsicmp) instead home made one
Close #15030
This commit is contained in:
parent
4ffa8fcdf9
commit
89aaf43722
|
@ -846,63 +846,6 @@ double stodLocale(const generic_string& str, [[maybe_unused]] _locale_t loc, siz
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -163,8 +163,6 @@ void stringJoin(const std::vector<generic_string>& strings, const generic_string
|
|||
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);
|
||||
class Buffer;
|
||||
bool buf2Clipboard(const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd);
|
||||
|
|
|
@ -128,11 +128,11 @@ public:
|
|||
{
|
||||
if (isDescending())
|
||||
{
|
||||
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) > 0;
|
||||
return wcsicmp(getSortKey(a).c_str(), getSortKey(b).c_str()) > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) < 0;
|
||||
return wcsicmp(getSortKey(a).c_str(), getSortKey(b).c_str()) < 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -142,11 +142,11 @@ public:
|
|||
{
|
||||
if (isDescending())
|
||||
{
|
||||
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) > 0;
|
||||
return wcsicmp(a.c_str(), b.c_str()) > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) < 0;
|
||||
return wcsicmp(a.c_str(), b.c_str()) < 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1832,8 +1832,8 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, size_t level, const vec
|
|||
}
|
||||
else if (isRecursive)
|
||||
{
|
||||
if ((OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT(".")) != 0) &&
|
||||
(OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT("..")) != 0) &&
|
||||
if ((wcscmp(foundData.cFileName, TEXT(".")) != 0) &&
|
||||
(wcscmp(foundData.cFileName, TEXT("..")) != 0) &&
|
||||
!matchInExcludeDirList(foundData.cFileName, patterns, level))
|
||||
{
|
||||
generic_string pathDir(dir);
|
||||
|
|
|
@ -84,7 +84,7 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params)
|
|||
if (pos == 2)
|
||||
fn.replace(pos, 2, TEXT("\\"));
|
||||
|
||||
if (OrdinalIgnoreCaseCompareStrings(fullFileName, fn.c_str()) == 0)
|
||||
if (wcscmp(fullFileName, fn.c_str()) == 0)
|
||||
{
|
||||
if (dwAction == FILE_ACTION_MODIFIED)
|
||||
{
|
||||
|
|
|
@ -215,17 +215,17 @@ void Buffer::setFileName(const TCHAR *fn)
|
|||
}
|
||||
}
|
||||
|
||||
if (determinatedLang == L_TEXT) //language can probably be refined
|
||||
if (determinatedLang == L_TEXT) // language can probably be refined
|
||||
{
|
||||
if ((OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("makefile")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("GNUmakefile")) == 0))
|
||||
if ((wcsicmp(_fileName, TEXT("makefile")) == 0) || (wcsicmp(_fileName, TEXT("GNUmakefile")) == 0))
|
||||
determinatedLang = L_MAKEFILE;
|
||||
else if (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("CmakeLists.txt")) == 0)
|
||||
else if (wcsicmp(_fileName, TEXT("CmakeLists.txt")) == 0)
|
||||
determinatedLang = L_CMAKE;
|
||||
else if ((OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("SConstruct")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("SConscript")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("wscript")) == 0))
|
||||
else if ((wcsicmp(_fileName, TEXT("SConstruct")) == 0) || (wcsicmp(_fileName, TEXT("SConscript")) == 0) || (wcsicmp(_fileName, TEXT("wscript")) == 0))
|
||||
determinatedLang = L_PYTHON;
|
||||
else if ((OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("Rakefile")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("Vagrantfile")) == 0))
|
||||
else if ((wcsicmp(_fileName, TEXT("Rakefile")) == 0) || (wcsicmp(_fileName, TEXT("Vagrantfile")) == 0))
|
||||
determinatedLang = L_RUBY;
|
||||
else if ((OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("crontab")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("PKGBUILD")) == 0) || (OrdinalIgnoreCaseCompareStrings(_fileName, TEXT("APKBUILD")) == 0))
|
||||
else if ((wcsicmp(_fileName, TEXT("crontab")) == 0) || (wcsicmp(_fileName, TEXT("PKGBUILD")) == 0) || (wcsicmp(_fileName, TEXT("APKBUILD")) == 0))
|
||||
determinatedLang = L_BASH;
|
||||
}
|
||||
|
||||
|
|
|
@ -897,8 +897,8 @@ void FileBrowser::getDirectoryStructure(const TCHAR *dir, const std::vector<gene
|
|||
}
|
||||
else if (isRecursive)
|
||||
{
|
||||
if ((OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT(".")) != 0) &&
|
||||
(OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT("..")) != 0))
|
||||
if ((wcscmp(foundData.cFileName, TEXT(".")) != 0) &&
|
||||
(wcscmp(foundData.cFileName, TEXT("..")) != 0))
|
||||
{
|
||||
generic_string pathDir(dir);
|
||||
if (pathDir[pathDir.length() - 1] != '\\')
|
||||
|
|
|
@ -1272,7 +1272,7 @@ void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTre
|
|||
}
|
||||
else // Always recursive
|
||||
{
|
||||
if ((OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT(".")) != 0) && (OrdinalIgnoreCaseCompareStrings(foundData.cFileName, TEXT("..")) != 0))
|
||||
if ((wcscmp(foundData.cFileName, TEXT(".")) != 0) && (wcscmp(foundData.cFileName, TEXT("..")) != 0))
|
||||
{
|
||||
generic_string pathDir(folderPath);
|
||||
if (folderPath[lstrlen(folderPath)-1] != '\\')
|
||||
|
|
|
@ -278,7 +278,7 @@ int LastRecentFileList::find(const TCHAR *fn)
|
|||
{
|
||||
for (int i = 0; i < _size; ++i)
|
||||
{
|
||||
if (OrdinalIgnoreCaseCompareStrings(_lrfl.at(i)._name.c_str(), fn) == 0)
|
||||
if (wcscmp(_lrfl.at(i)._name.c_str(), fn) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue