Several enhancements for code - part III

This commit is contained in:
Don Ho 2024-08-06 21:51:07 +02:00
parent bf72b5ec4a
commit 72751182bf
20 changed files with 52 additions and 51 deletions

View File

@ -77,7 +77,7 @@ bool isInListA(const char *token, const char *list)
if ((!token) || (!list))
return false;
char word[64] = { '\0' };
char word[64] {};
size_t i = 0;
size_t j = 0;
for (size_t len = strlen(list); i <= len; ++i)

View File

@ -254,8 +254,7 @@ bool Win32_IO_File::write(const void *wbuf, size_t buf_size)
}
}
if (!_written)
_written = true;
_written = true;
return (total_bytes_written == buf_size);
}

View File

@ -364,11 +364,11 @@ void RegExtDlg::addExt(wchar_t *ext)
if (nRet == ERROR_SUCCESS)
{
wchar_t valData[MAX_PATH] = { '\0' };
DWORD valDataLen = MAX_PATH * sizeof(wchar_t);
if (dwDisp == REG_OPENED_EXISTING_KEY)
{
wchar_t valData[MAX_PATH] {};
DWORD valDataLen = MAX_PATH * sizeof(wchar_t);
int res = ::RegQueryValueEx(hKey, L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(valData), &valDataLen);
if (res == ERROR_SUCCESS)
::RegSetValueEx(hKey, nppBackup, 0, REG_SZ, reinterpret_cast<LPBYTE>(valData), valDataLen);

View File

@ -1120,10 +1120,10 @@ void Notepad_plus::saveFindHistory()
}
int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const
int Notepad_plus::getHtmlXmlEncoding(const wchar_t* fileName) const
{
// Get Language type
wchar_t *ext = PathFindExtension(fileName);
wchar_t* ext = PathFindExtension(fileName);
if (*ext == '.') //extension found
{
ext += 1;
@ -1139,7 +1139,7 @@ int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const
return -1;
// Get the beginning of file data
FILE *f = _wfopen(fileName, L"rb");
FILE* f = _wfopen(fileName, L"rb");
if (!f)
return -1;
const int blockSize = 1024; // To ensure that length is long enough to capture the encoding in html
@ -1151,13 +1151,13 @@ int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const
_invisibleEditView.execute(SCI_CLEARALL);
_invisibleEditView.execute(SCI_APPENDTEXT, lenFile, reinterpret_cast<LPARAM>(data));
const char *encodingAliasRegExpr = "[a-zA-Z0-9_-]+";
const size_t encodingStrLen = 128;
if (langT == L_XML)
{
// find encoding by RegExpr
const char *xmlHeaderRegExpr = "<?xml[ \\t]+version[ \\t]*=[ \\t]*\"[^\"]+\"[ \\t]+encoding[ \\t]*=[ \\t]*\"[^\"]+\"[ \\t]*.*?>";
const char* encodingAliasRegExpr = "[a-zA-Z0-9_-]+";
const char* xmlHeaderRegExpr = "<?xml[ \\t]+version[ \\t]*=[ \\t]*\"[^\"]+\"[ \\t]+encoding[ \\t]*=[ \\t]*\"[^\"]+\"[ \\t]*.*?>";
size_t startPos = 0;
size_t endPos = lenFile-1;
@ -1168,10 +1168,10 @@ int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const
auto posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(xmlHeaderRegExpr), reinterpret_cast<LPARAM>(xmlHeaderRegExpr));
if (posFound >= 0)
{
const char *encodingBlockRegExpr = "encoding[ \\t]*=[ \\t]*\"[^\".]+\"";
const char* encodingBlockRegExpr = "encoding[ \\t]*=[ \\t]*\"[^\".]+\"";
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingBlockRegExpr), reinterpret_cast<LPARAM>(encodingBlockRegExpr));
const char *encodingRegExpr = "\".+\"";
const char* encodingRegExpr = "\".+\"";
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingRegExpr), reinterpret_cast<LPARAM>(encodingRegExpr));
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingAliasRegExpr), reinterpret_cast<LPARAM>(encodingAliasRegExpr));
@ -1196,11 +1196,11 @@ int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const
}
else // if (langT == L_HTML)
{
const char *htmlHeaderRegExpr = "<meta[ \\t]+http-equiv[ \\t]*=[ \\t\"']*Content-Type[ \\t\"']*content[ \\t]*= *[\"']text/html;[ \\t]+charset[ \\t]*=[ \\t]*.+[\"'] */*>";
const char *htmlHeaderRegExpr2 = "<meta[ \\t]+content[ \\t]*= *[\"']text/html;[ \\t]+charset[ \\t]*=[ \\t]*.+[ \\t\"']http-equiv[ \\t]*=[ \\t\"']*Content-Type[ \\t\"']*/*>";
const char *charsetBlock = "charset[ \\t]*=[ \\t]*[^\"']+";
const char *intermediaire = "=[ \\t]*.+";
const char *encodingStrRE = "[^ \\t=]+";
const char* htmlHeaderRegExpr = "<meta[ \\t]+http-equiv[ \\t]*=[ \\t\"']*Content-Type[ \\t\"']*content[ \\t]*= *[\"']text/html;[ \\t]+charset[ \\t]*=[ \\t]*.+[\"'] */*>";
const char* htmlHeaderRegExpr2 = "<meta[ \\t]+content[ \\t]*= *[\"']text/html;[ \\t]+charset[ \\t]*=[ \\t]*.+[ \\t\"']http-equiv[ \\t]*=[ \\t\"']*Content-Type[ \\t\"']*/*>";
const char* charsetBlock = "charset[ \\t]*=[ \\t]*[^\"']+";
const char* intermediaire = "=[ \\t]*.+";
const char* encodingStrRE = "[^ \\t=]+";
intptr_t startPos = 0;
auto endPos = lenFile - 1;
@ -5603,17 +5603,19 @@ bool Notepad_plus::doStreamComment()
bool move_caret = caretPosition < selectionEnd;
// if there is no selection?
if (selectionEnd - selectionStart <= 0)
if (selectionEnd <= selectionStart)
{
auto selLine = _pEditView->execute(SCI_LINEFROMPOSITION, selectionStart);
selectionStart = _pEditView->execute(SCI_GETLINEINDENTPOSITION, selLine);
selectionEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, selLine);
}
_pEditView->execute(SCI_BEGINUNDOACTION);
_pEditView->insertGenericTextFrom(selectionStart, start_comment.c_str());
selectionEnd += start_comment_length;
selectionStart += start_comment_length;
_pEditView->insertGenericTextFrom(selectionEnd, end_comment.c_str());
if (move_caret)
{
// moving caret to the beginning of selected block

View File

@ -1002,8 +1002,7 @@ int Notepad_plus::setFileOpenSaveDlgFilters(CustomFileDialog & fDlg, bool showAl
const wchar_t *lName = ulc.getName();
wstring list(L"");
if (extList)
list += extList;
list += extList;
wstring stringFilters = exts2Filters(list, showAllExt ? -1 : 40);
const wchar_t *filters = stringFilters.c_str();
@ -1679,14 +1678,14 @@ bool Notepad_plus::fileSave(BufferID id)
}
else if (backup == bak_verbose)
{
constexpr int temBufLen = 32;
wchar_t tmpbuf[temBufLen]{};
time_t ltime = time(0);
const struct tm* today;
today = localtime(&ltime);
if (today)
{
constexpr int temBufLen = 32;
wchar_t tmpbuf[temBufLen]{};
wcsftime(tmpbuf, temBufLen, L"%Y-%m-%d_%H%M%S", today);
fn_bak += name;

View File

@ -451,7 +451,7 @@ bool AutoCompletion::showApiAndWordComplete()
return showAutoComplete(autocFuncAndWord, false);
}
void AutoCompletion::getWordArray(vector<wstring> & wordArray, wchar_t *beginChars, wchar_t *allChars)
void AutoCompletion::getWordArray(vector<wstring> & wordArray, const wchar_t *beginChars, const wchar_t *allChars)
{
const size_t bufSize = 256;
const NppGUI & nppGUI = NppParameters::getInstance().getNppGUI();
@ -1106,15 +1106,16 @@ bool AutoCompletion::setLanguage(LangType language)
TiXmlNode * pNode = _pXmlFile->FirstChild(L"NotepadPlus");
if (!pNode)
return false;
pAutoNode = pNode = pNode->FirstChildElement(L"AutoComplete");
if (!pNode)
return false;
pNode = pNode->FirstChildElement(L"KeyWord");
if (!pNode)
return false;
_pXmlKeyword = reinterpret_cast<TiXmlElement *>(pNode);
if (!_pXmlKeyword)
return false;
_funcCompletionActive = true;
}
@ -1216,7 +1217,7 @@ const wchar_t * AutoCompletion::getApiFileName()
{
if (_curLang == L_USER)
{
Buffer * currentBuf = _pEditView->getCurrentBuffer();
const Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (currentBuf->isUserDefineLangExt())
{
return currentBuf->getUserDefineLangName();
@ -1297,7 +1298,7 @@ void AutoCompletion::setColour(COLORREF colour2Set, AutocompleteColorIndex i)
}
}
void AutoCompletion::drawAutocomplete(ScintillaEditView* pEditView)
void AutoCompletion::drawAutocomplete(const ScintillaEditView* pEditView)
{
pEditView->setElementColour(SC_ELEMENT_LIST, _autocompleteText);
pEditView->setElementColour(SC_ELEMENT_LIST_BACK, _autocompleteBg);

View File

@ -82,7 +82,7 @@ public:
void getCloseTag(char *closeTag, size_t closeTagLen, size_t caretPos, bool isHTML);
static void setColour(COLORREF colour2Set, AutocompleteColorIndex i);
static void drawAutocomplete(ScintillaEditView* pEditView);
static void drawAutocomplete(const ScintillaEditView* pEditView);
protected:
static COLORREF _autocompleteBg;
@ -113,7 +113,7 @@ private:
FunctionCallTip _funcCalltip;
const wchar_t * getApiFileName();
void getWordArray(std::vector<std::wstring> & wordArray, wchar_t *beginChars, wchar_t *excludeChars);
void getWordArray(std::vector<std::wstring> & wordArray, const wchar_t *beginChars, const wchar_t *excludeChars);
// Type of autocomplete function
enum AutocompleteType {

View File

@ -666,7 +666,7 @@ void FileManager::addBufferReference(BufferID buffer, ScintillaEditView * identi
}
void FileManager::closeBuffer(BufferID id, ScintillaEditView * identifier)
void FileManager::closeBuffer(BufferID id, const ScintillaEditView* identifier)
{
int index = getBufferIndexByID(id);
Buffer* buf = getBufferByIndex(index);

View File

@ -83,7 +83,7 @@ public:
void beNotifiedOfBufferChange(Buffer * theBuf, int mask);
void closeBuffer(BufferID, ScintillaEditView * identifer); //called by Notepad++
void closeBuffer(BufferID, const ScintillaEditView* identifer); //called by Notepad++
void addBufferReference(BufferID id, ScintillaEditView * identifer); //called by Scintilla etc indirectly

View File

@ -99,10 +99,10 @@ int Searching::convertExtendedToString(const wchar_t * query, wchar_t * result,
{ //query may equal to result, since it always gets smaller
int i = 0, j = 0;
int charLeft = length;
wchar_t current;
while (i < length)
{ //because the backslash escape quences always reduce the size of the wstring, no overflow checks have to be made for target, assuming parameters are correct
current = query[i];
wchar_t current = query[i];
--charLeft;
if (current == '\\' && charLeft)
{ //possible escape sequence
@ -193,10 +193,10 @@ bool Searching::readBase(const wchar_t * str, int * value, int base, int size)
int i = 0, temp = 0;
*value = 0;
wchar_t max = '0' + static_cast<wchar_t>(base) - 1;
wchar_t current;
while (i < size)
{
current = str[i];
wchar_t current = str[i];
if (current >= 'A')
{
current &= 0xdf;
@ -3237,7 +3237,6 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
}
intptr_t targetStart = 0;
intptr_t targetEnd = 0;
//Initial range for searching
pEditView->execute(SCI_SETSEARCHFLAGS, flags);
@ -3260,7 +3259,7 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
if (targetStart == FIND_INVALID_REGULAR_EXPRESSION)
return FIND_INVALID_REGULAR_EXPRESSION;
targetEnd = pEditView->execute(SCI_GETTARGETEND);
intptr_t targetEnd = pEditView->execute(SCI_GETTARGETEND);
if (targetEnd > findReplaceInfo._endRange)
{

View File

@ -154,11 +154,11 @@ bool FunctionCallTip::getCursorFunction()
//token is identifier or some expression, whitespace is ignored
std::vector< Token > tokenVector;
int tokenLen = 0;
wchar_t ch;
for (int i = 0; i < offset; ++i) //we dont care about stuff after the offset
{
//tokenVector.push_back(pair(lineData+i, len));
ch = lineData[i];
wchar_t ch = lineData[i];
if (isBasicWordChar(ch) || isAdditionalWordChar(ch)) //part of identifier
{
tokenLen = 0;

View File

@ -46,8 +46,8 @@ u78 Utf8_16_Read::utf8_7bits_8bits()
{
int rv = 1;
int ASCII7only = 1;
utf8 *sx = (utf8 *)m_pBuf;
utf8 *endx = sx + m_nLen;
utf8* sx = (utf8 *)m_pBuf;
utf8* endx = sx + m_nLen;
while (sx<endx)
{

View File

@ -3658,12 +3658,12 @@ intptr_t CALLBACK LanguageSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
//
for (int i = L_TEXT ; i < nppParam.L_END ; ++i)
{
wstring str;
if (static_cast<LangType>(i) != L_USER)
{
int cmdID = nppParam.langTypeToCommandID(static_cast<LangType>(i));
if ((cmdID != -1))
{
wstring str;
getNameStrFromCmd(cmdID, str);
if (str.length() > 0)
{

View File

@ -455,7 +455,7 @@ void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem, const wchar
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
if (tvItem.lParam)
{
wstring *fn = (wstring *)tvItem.lParam;
const wstring *fn = reinterpret_cast<const wstring *>(tvItem.lParam);
wstring newFn = getRelativePath(*fn, fn2write);
TiXmlNode *fileLeaf = node->InsertEndChild(TiXmlElement(L"File"));
fileLeaf->ToElement()->SetAttribute(L"name", newFn.c_str());
@ -1215,9 +1215,10 @@ bool ProjectPanel::saveWorkSpaceAs(bool saveCopyAs)
void ProjectPanel::setFileExtFilter(CustomFileDialog & fDlg)
{
const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedWorkspaceExt.c_str();
wstring workspaceExt = L"";
if (*ext != '\0')
{
wstring workspaceExt = L"";
if (*ext != '.')
workspaceExt += L".";
workspaceExt += ext;

View File

@ -69,7 +69,7 @@ public:
_hParent = parent2set;
};
void setPanelTitle(std::wstring title) {
void setPanelTitle(const std::wstring& title) {
_panelTitle = title;
};
const wchar_t * getPanelTitle() const {

View File

@ -87,7 +87,7 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot)
size_t i = 0;
wstring disabled_suffix = L"_disabled";
wstring ext = L".ico";
for (ToolbarIconIdUnit icoUnit : toolbarIconIDs)
for (const ToolbarIconIdUnit& icoUnit : toolbarIconIDs)
{
wstring locator = iconFolderDir;
locator += L"\\";

View File

@ -281,7 +281,7 @@ HTREEITEM TreeView::searchSubItemByName(const wchar_t *itemName, HTREEITEM hPare
return nullptr;
}
bool TreeView::setImageList(std::vector<int> imageIds, int imgSize)
bool TreeView::setImageList(const std::vector<int>& imageIds, int imgSize)
{
const int nbImage = static_cast<int>(imageIds.size());
if (imgSize <= 0)

View File

@ -116,7 +116,7 @@ public:
bool searchLeafAndBuildTree(const TreeView & tree2Build, const std::wstring & text2Search, int index2Search);
void sort(HTREEITEM hTreeItem, bool isRecusive);
void customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecursive);
bool setImageList(std::vector<int> imageIds, int imgSize = 0);
bool setImageList(const std::vector<int>& imageIds, int imgSize = 0);
protected:
HIMAGELIST _hImaLst = nullptr;

View File

@ -533,7 +533,7 @@ intptr_t CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam,
void VerticalFileSwitcher::initPopupMenus()
{
NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
NppGUI& nppGUI = NppParameters::getInstance().getNppGUI();
const NppGUI& nppGUI = NppParameters::getInstance().getNppGUI();
wstring extStr = pNativeSpeaker->getAttrNameStr(L"Ext.", FS_ROOTNODE, FS_CLMNEXT);
wstring pathStr = pNativeSpeaker->getAttrNameStr(L"Path", FS_ROOTNODE, FS_CLMNPATH);

View File

@ -131,7 +131,7 @@ void parseCommandLine(const wchar_t* commandLine, ParamVector& paramVector)
++zArg; // zArg == 2
}
}
else if (isBetweenFileNameQuotes)
else //if (isBetweenFileNameQuotes)
{
isBetweenFileNameQuotes = false;
//because we dont want to leave in any quotes in the filename, remove them now (with zero terminator)