mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-28 00:04:25 +02:00
Use wide char version's function directely (part1)
ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/12613#discussion_r1045153278
This commit is contained in:
parent
d476a894c2
commit
432dcb7f15
@ -720,7 +720,7 @@ COLORREF getCtrlBgColor(HWND hWnd)
|
||||
generic_string stringToUpper(generic_string strToConvert)
|
||||
{
|
||||
std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(),
|
||||
[](TCHAR ch){ return static_cast<TCHAR>(_totupper(ch)); }
|
||||
[](wchar_t ch){ return static_cast<wchar_t>(towupper(ch)); }
|
||||
);
|
||||
return strToConvert;
|
||||
}
|
||||
@ -932,7 +932,7 @@ bool str2Clipboard(const generic_string &str2cpy, HWND hwnd)
|
||||
::CloseClipboard();
|
||||
return false;
|
||||
}
|
||||
_tcscpy_s(pStr, len2Allocate / sizeof(TCHAR), str2cpy.c_str());
|
||||
wcscpy_s(pStr, len2Allocate / sizeof(TCHAR), str2cpy.c_str());
|
||||
::GlobalUnlock(hglbCopy);
|
||||
// Place the handle on the clipboard.
|
||||
unsigned int clipBoardFormat = CF_UNICODETEXT;
|
||||
@ -1510,7 +1510,7 @@ HFONT createFont(const TCHAR* fontName, int fontSize, bool isBold, HWND hDestPar
|
||||
if (isBold)
|
||||
logFont.lfWeight = FW_BOLD;
|
||||
|
||||
_tcscpy_s(logFont.lfFaceName, fontName);
|
||||
wcscpy_s(logFont.lfFaceName, fontName);
|
||||
|
||||
HFONT newFont = CreateFontIndirect(&logFont);
|
||||
|
||||
|
@ -37,7 +37,6 @@ const bool dirDown = false;
|
||||
#define BCKGRD_COLOR (RGB(255,102,102))
|
||||
#define TXT_COLOR (RGB(255,255,255))
|
||||
|
||||
#define generic_strtol wcstol
|
||||
#define generic_strncpy wcsncpy
|
||||
#define generic_stricmp wcsicmp
|
||||
#define generic_strncmp wcsncmp
|
||||
|
@ -29,13 +29,11 @@ private:
|
||||
size_t _toColumn = 0;
|
||||
|
||||
protected:
|
||||
bool isDescending() const
|
||||
{
|
||||
bool isDescending() const {
|
||||
return _isDescending;
|
||||
}
|
||||
};
|
||||
|
||||
generic_string getSortKey(const generic_string& input)
|
||||
{
|
||||
generic_string getSortKey(const generic_string& input) {
|
||||
if (isSortingSpecificColumns())
|
||||
{
|
||||
if (input.length() < _fromColumn)
|
||||
@ -58,16 +56,14 @@ protected:
|
||||
{
|
||||
return input;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool isSortingSpecificColumns()
|
||||
{
|
||||
bool isSortingSpecificColumns() {
|
||||
return _toColumn != 0;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
ISorter(bool isDescending, size_t fromColumn, size_t toColumn) : _isDescending(isDescending), _fromColumn(fromColumn), _toColumn(toColumn)
|
||||
{
|
||||
ISorter(bool isDescending, size_t fromColumn, size_t toColumn) : _isDescending(isDescending), _fromColumn(fromColumn), _toColumn(toColumn) {
|
||||
assert(_fromColumn <= _toColumn);
|
||||
};
|
||||
virtual ~ISorter() { };
|
||||
@ -80,8 +76,7 @@ class LexicographicSorter : public ISorter
|
||||
public:
|
||||
LexicographicSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
||||
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
||||
// getSortKey() so many times.
|
||||
@ -115,7 +110,7 @@ public:
|
||||
});
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Implementation of lexicographic sorting of lines, ignoring character casing
|
||||
@ -124,8 +119,7 @@ class LexicographicCaseInsensitiveSorter : public ISorter
|
||||
public:
|
||||
LexicographicCaseInsensitiveSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
||||
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
||||
// getSortKey() so many times.
|
||||
@ -158,7 +152,7 @@ public:
|
||||
});
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class IntegerSorter : public ISorter
|
||||
@ -166,8 +160,7 @@ class IntegerSorter : public ISorter
|
||||
public:
|
||||
IntegerSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
if (isSortingSpecificColumns())
|
||||
{
|
||||
std::stable_sort(lines.begin(), lines.end(), [this](generic_string aIn, generic_string bIn)
|
||||
@ -504,9 +497,8 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Convert each line to a number and then sort.
|
||||
@ -531,8 +523,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
// Note that empty lines are filtered out and added back manually to the output at the end.
|
||||
std::vector<std::pair<size_t, T_Num>> nonEmptyInputAsNumbers;
|
||||
std::vector<generic_string> empties;
|
||||
@ -557,40 +548,44 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(nonEmptyInputAsNumbers.size() + empties.size() == lines.size());
|
||||
const bool descending = isDescending();
|
||||
std::stable_sort(nonEmptyInputAsNumbers.begin(), nonEmptyInputAsNumbers.end(), [descending](std::pair<size_t, T_Num> a, std::pair<size_t, T_Num> b)
|
||||
{
|
||||
if (descending)
|
||||
{
|
||||
return a.second > b.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return a.second < b.second;
|
||||
}
|
||||
});
|
||||
if (descending)
|
||||
{
|
||||
return a.second > b.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return a.second < b.second;
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<generic_string> output;
|
||||
output.reserve(lines.size());
|
||||
if (!isDescending())
|
||||
{
|
||||
output.insert(output.end(), empties.begin(), empties.end());
|
||||
}
|
||||
|
||||
for (auto it = nonEmptyInputAsNumbers.begin(); it != nonEmptyInputAsNumbers.end(); ++it)
|
||||
{
|
||||
output.push_back(lines[it->first]);
|
||||
}
|
||||
|
||||
if (isDescending())
|
||||
{
|
||||
output.insert(output.end(), empties.begin(), empties.end());
|
||||
}
|
||||
|
||||
assert(output.size() == lines.size());
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
bool considerStringEmpty(const generic_string& input)
|
||||
{
|
||||
bool considerStringEmpty(const generic_string& input) {
|
||||
// String has something else than just whitespace.
|
||||
return input.find_first_not_of(TEXT(" \t\r\n")) == std::string::npos;
|
||||
}
|
||||
@ -614,16 +609,14 @@ public:
|
||||
DecimalCommaSorter(bool isDescending, size_t fromColumn, size_t toColumn) : NumericSorter<double>(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
protected:
|
||||
generic_string prepareStringForConversion(const generic_string& input) override
|
||||
{
|
||||
generic_string prepareStringForConversion(const generic_string& input) override {
|
||||
generic_string admissablePart = stringTakeWhileAdmissable(getSortKey(input), TEXT(" \t\r\n0123456789,-"));
|
||||
return stringReplace(admissablePart, TEXT(","), TEXT("."));
|
||||
}
|
||||
};
|
||||
|
||||
double convertStringToNumber(const generic_string& input) override
|
||||
{
|
||||
double convertStringToNumber(const generic_string& input) override {
|
||||
return stodLocale(input, _usLocale);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Converts lines to double before sorting (assumes decimal dot).
|
||||
@ -633,15 +626,13 @@ public:
|
||||
DecimalDotSorter(bool isDescending, size_t fromColumn, size_t toColumn) : NumericSorter<double>(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
protected:
|
||||
generic_string prepareStringForConversion(const generic_string& input) override
|
||||
{
|
||||
generic_string prepareStringForConversion(const generic_string& input) override {
|
||||
return stringTakeWhileAdmissable(getSortKey(input), TEXT(" \t\r\n0123456789.-"));
|
||||
}
|
||||
};
|
||||
|
||||
double convertStringToNumber(const generic_string& input) override
|
||||
{
|
||||
double convertStringToNumber(const generic_string& input) override {
|
||||
return stodLocale(input, _usLocale);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class ReverseSorter : public ISorter
|
||||
@ -649,25 +640,24 @@ class ReverseSorter : public ISorter
|
||||
public:
|
||||
ReverseSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
std::reverse(lines.begin(), lines.end());
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class RandomSorter : public ISorter
|
||||
{
|
||||
public:
|
||||
unsigned seed;
|
||||
RandomSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn)
|
||||
{
|
||||
|
||||
RandomSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) {
|
||||
seed = static_cast<unsigned>(time(NULL));
|
||||
}
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||
{
|
||||
};
|
||||
|
||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override {
|
||||
std::shuffle(lines.begin(), lines.end(), std::default_random_engine(seed));
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -561,7 +561,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
||||
TCHAR longNameFullpath[MAX_PATH];
|
||||
const TCHAR* pFilePath = reinterpret_cast<const TCHAR*>(lParam);
|
||||
wcscpy_s(longNameFullpath, MAX_PATH, pFilePath);
|
||||
if (_tcschr(longNameFullpath, '~'))
|
||||
if (wcschr(longNameFullpath, '~'))
|
||||
{
|
||||
::GetLongPathName(longNameFullpath, longNameFullpath, MAX_PATH);
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ int strVal(const TCHAR *str, int base)
|
||||
if (!str[0]) return 0;
|
||||
|
||||
TCHAR *finStr;
|
||||
int result = generic_strtol(str, &finStr, base);
|
||||
int result = wcstol(str, &finStr, base);
|
||||
if (*finStr != '\0')
|
||||
return -1;
|
||||
return result;
|
||||
@ -1680,7 +1680,7 @@ const TCHAR* NppParameters::getUserDefinedLangNameFromExt(TCHAR *ext, TCHAR *ful
|
||||
// Force to use dark mode UDL in dark mode or to use light mode UDL in light mode
|
||||
for (size_t j = 0, len = extVect.size(); j < len; ++j)
|
||||
{
|
||||
if (!generic_stricmp(extVect[j].c_str(), ext) || (_tcschr(fullName, '.') && !generic_stricmp(extVect[j].c_str(), fullName)))
|
||||
if (!generic_stricmp(extVect[j].c_str(), ext) || (wcschr(fullName, '.') && !generic_stricmp(extVect[j].c_str(), fullName)))
|
||||
{
|
||||
// preserve ext matched UDL
|
||||
iMatched = i;
|
||||
@ -3723,7 +3723,6 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
|
||||
else if (!lstrcmp(keywordsName, TEXT("Comment")))
|
||||
{
|
||||
kwl = (valueNode)?valueNode->Value():TEXT("");
|
||||
//int len = _tcslen(kwl);
|
||||
basic_string<TCHAR> temp{TEXT(" ")};
|
||||
|
||||
temp += kwl;
|
||||
@ -3760,7 +3759,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
|
||||
if (globalMappper().keywordIdMapper.find(keywordsName) != globalMappper().keywordIdMapper.end())
|
||||
{
|
||||
id = globalMappper().keywordIdMapper[keywordsName];
|
||||
if (_tcslen(kwl) < max_char)
|
||||
if (wcslen(kwl) < max_char)
|
||||
{
|
||||
wcscpy_s(_userLangArray[_nbUserLang - 1]->_keywordLists[id], kwl);
|
||||
}
|
||||
|
@ -1015,7 +1015,7 @@ bool FileManager::backupCurrentBuffer()
|
||||
|
||||
TCHAR fullpath[MAX_PATH];
|
||||
::GetFullPathName(backupFilePath.c_str(), MAX_PATH, fullpath, NULL);
|
||||
if (_tcschr(fullpath, '~'))
|
||||
if (wcschr(fullpath, '~'))
|
||||
{
|
||||
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
||||
}
|
||||
|
@ -5397,9 +5397,9 @@ HWND Progress::open(HWND hCallerWnd, const TCHAR* header)
|
||||
::UpdateWindow(hwnd);
|
||||
|
||||
if (header)
|
||||
_tcscpy_s(_header, _countof(_header), header);
|
||||
wcscpy_s(_header, _countof(_header), header);
|
||||
else
|
||||
_tcscpy_s(_header, _countof(_header), cDefaultHeader);
|
||||
wcscpy_s(_header, _countof(_header), cDefaultHeader);
|
||||
|
||||
_hThread = ::CreateThread(NULL, 0, threadFunc, this, 0, NULL);
|
||||
if (!_hThread)
|
||||
|
@ -2294,7 +2294,7 @@ void ScintillaEditView::getGenericText(TCHAR *dest, size_t destlen, size_t start
|
||||
getText(destA, start, end);
|
||||
size_t cp = execute(SCI_GETCODEPAGE);
|
||||
const TCHAR *destW = wmc.char2wchar(destA, cp);
|
||||
_tcsncpy_s(dest, destlen, destW, _TRUNCATE);
|
||||
wcsncpy_s(dest, destlen, destW, _TRUNCATE);
|
||||
delete [] destA;
|
||||
}
|
||||
|
||||
@ -2308,7 +2308,7 @@ void ScintillaEditView::getGenericText(TCHAR *dest, size_t destlen, size_t start
|
||||
getText(destA, start, end);
|
||||
size_t cp = execute(SCI_GETCODEPAGE) ;
|
||||
const TCHAR *destW = wmc.char2wchar(destA, cp, mstart, mend);
|
||||
_tcsncpy_s(dest, destlen, destW, _TRUNCATE);
|
||||
wcsncpy_s(dest, destlen, destW, _TRUNCATE);
|
||||
delete [] destA;
|
||||
}
|
||||
|
||||
|
@ -1894,7 +1894,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
|
||||
else
|
||||
{
|
||||
TCHAR *finStr;
|
||||
style._fontSize = generic_strtol(intStr, &finStr, 10);
|
||||
style._fontSize = wcstol(intStr, &finStr, 10);
|
||||
if (*finStr != '\0')
|
||||
style._fontSize = -1;
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ public :
|
||||
_textValue = text2Set;
|
||||
_txtLen = txtLen;
|
||||
_shouldGotoCenter = bGotoCenter;
|
||||
if (restrictedChars && _tcslen(restrictedChars))
|
||||
if (restrictedChars && wcslen(restrictedChars))
|
||||
{
|
||||
_restrictedChars = restrictedChars;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ const TCHAR* TiXmlBase::GetEntity( const TCHAR* p, TCHAR* value )
|
||||
if (end && end - p <= 3 + 4)
|
||||
{
|
||||
TCHAR* hexend;
|
||||
auto val = generic_strtol(p + 3, &hexend, 16);
|
||||
auto val = wcstol(p + 3, &hexend, 16);
|
||||
if (hexend == end)
|
||||
{
|
||||
*value = static_cast<TCHAR>(val);
|
||||
|
@ -710,7 +710,7 @@ void WordStyleDlg::updateFontSize()
|
||||
else
|
||||
{
|
||||
TCHAR *finStr;
|
||||
style._fontSize = generic_strtol(intStr, &finStr, 10);
|
||||
style._fontSize = wcstol(intStr, &finStr, 10);
|
||||
if (*finStr != '\0')
|
||||
style._fontSize = STYLE_NOT_USED;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ bool findStrNoCase(const generic_string & strHaystack, const generic_string & st
|
||||
auto it = std::search(
|
||||
strHaystack.begin(), strHaystack.end(),
|
||||
strNeedle.begin(), strNeedle.end(),
|
||||
[](TCHAR ch1, TCHAR ch2){return _totupper(ch1) == _totupper(ch2); }
|
||||
[](wchar_t ch1, wchar_t ch2){return towupper(ch1) == towupper(ch2); }
|
||||
);
|
||||
return (it != strHaystack.end());
|
||||
}
|
||||
|
@ -3577,7 +3577,7 @@ intptr_t CALLBACK PrintSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
|
||||
if (!intStr[0])
|
||||
*pVal = 0;
|
||||
else
|
||||
*pVal = generic_strtol(intStr, NULL, 10);
|
||||
*pVal = wcstol(intStr, NULL, 10);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -103,7 +103,7 @@ struct NumericStringEquivalence
|
||||
}
|
||||
if (_istdigit(*str1) && _istdigit(*str2))
|
||||
{
|
||||
lcmp = generic_strtol(str1, &p1, 10) - generic_strtol(str2, &p2, 10);
|
||||
lcmp = wcstol(str1, &p1, 10) - wcstol(str2, &p2, 10);
|
||||
if ( lcmp == 0 )
|
||||
lcmp = static_cast<int32_t>((p2 - str2) - (p1 - str1));
|
||||
if ( lcmp != 0 )
|
||||
@ -113,11 +113,11 @@ struct NumericStringEquivalence
|
||||
else
|
||||
{
|
||||
if (_istascii(*str1) && _istupper(*str1))
|
||||
c1 = _totlower(*str1);
|
||||
c1 = towlower(*str1);
|
||||
else
|
||||
c1 = *str1;
|
||||
if (_istascii(*str2) && _istupper(*str2))
|
||||
c2 = _totlower(*str2);
|
||||
c2 = towlower(*str2);
|
||||
else
|
||||
c2 = *str2;
|
||||
lcmp = (c1 - c2);
|
||||
@ -427,7 +427,7 @@ intptr_t CALLBACK WindowsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
|
||||
if (static_cast<int>(text.length()) < pLvdi->item.cchTextMax)
|
||||
{
|
||||
// Copy the resulting text to destination with a null terminator.
|
||||
_tcscpy_s(pLvdi->item.pszText, text.length() + 1, text.c_str());
|
||||
wcscpy_s(pLvdi->item.pszText, text.length() + 1, text.c_str());
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user