diff --git a/PowerEditor/src/EncodingMapper.cpp b/PowerEditor/src/EncodingMapper.cpp index f61cb5c58..a232bd8de 100644 --- a/PowerEditor/src/EncodingMapper.cpp +++ b/PowerEditor/src/EncodingMapper.cpp @@ -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) diff --git a/PowerEditor/src/MISC/Common/FileInterface.cpp b/PowerEditor/src/MISC/Common/FileInterface.cpp index b76c81709..452ee5bf1 100644 --- a/PowerEditor/src/MISC/Common/FileInterface.cpp +++ b/PowerEditor/src/MISC/Common/FileInterface.cpp @@ -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); } diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp index fe378ab3c..6328daa24 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -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(valData), &valDataLen); if (res == ERROR_SUCCESS) ::RegSetValueEx(hKey, nppBackup, 0, REG_SZ, reinterpret_cast(valData), valDataLen); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index c5ce33531..eb1d0910e 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -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(data)); - const char *encodingAliasRegExpr = "[a-zA-Z0-9_-]+"; const size_t encodingStrLen = 128; if (langT == L_XML) { // find encoding by RegExpr - const char *xmlHeaderRegExpr = ""; + const char* encodingAliasRegExpr = "[a-zA-Z0-9_-]+"; + const char* xmlHeaderRegExpr = ""; 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(xmlHeaderRegExpr)); if (posFound >= 0) { - const char *encodingBlockRegExpr = "encoding[ \\t]*=[ \\t]*\"[^\".]+\""; + const char* encodingBlockRegExpr = "encoding[ \\t]*=[ \\t]*\"[^\".]+\""; _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingBlockRegExpr), reinterpret_cast(encodingBlockRegExpr)); - const char *encodingRegExpr = "\".+\""; + const char* encodingRegExpr = "\".+\""; _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingRegExpr), reinterpret_cast(encodingRegExpr)); _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingAliasRegExpr), reinterpret_cast(encodingAliasRegExpr)); @@ -1196,11 +1196,11 @@ int Notepad_plus::getHtmlXmlEncoding(const wchar_t *fileName) const } else // if (langT == L_HTML) { - const char *htmlHeaderRegExpr = ""; - const char *htmlHeaderRegExpr2 = ""; - const char *charsetBlock = "charset[ \\t]*=[ \\t]*[^\"']+"; - const char *intermediaire = "=[ \\t]*.+"; - const char *encodingStrRE = "[^ \\t=]+"; + const char* htmlHeaderRegExpr = ""; + const char* htmlHeaderRegExpr2 = ""; + 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 diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 49b4630a4..b166a6138 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -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(<ime); if (today) { + constexpr int temBufLen = 32; + wchar_t tmpbuf[temBufLen]{}; wcsftime(tmpbuf, temBufLen, L"%Y-%m-%d_%H%M%S", today); fn_bak += name; diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp index d2c91dfb4..ee629a3f6 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.cpp @@ -451,7 +451,7 @@ bool AutoCompletion::showApiAndWordComplete() return showAutoComplete(autocFuncAndWord, false); } -void AutoCompletion::getWordArray(vector & wordArray, wchar_t *beginChars, wchar_t *allChars) +void AutoCompletion::getWordArray(vector & 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(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); diff --git a/PowerEditor/src/ScintillaComponent/AutoCompletion.h b/PowerEditor/src/ScintillaComponent/AutoCompletion.h index 9448acd3c..d4e8e2469 100644 --- a/PowerEditor/src/ScintillaComponent/AutoCompletion.h +++ b/PowerEditor/src/ScintillaComponent/AutoCompletion.h @@ -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 & wordArray, wchar_t *beginChars, wchar_t *excludeChars); + void getWordArray(std::vector & wordArray, const wchar_t *beginChars, const wchar_t *excludeChars); // Type of autocomplete function enum AutocompleteType { diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 7720a2f83..dbd163289 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -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); diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index 9978ae6e7..b1a953e44 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -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 diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index d7ca7a695..e52c47844 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -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(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) { diff --git a/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp b/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp index 06d13c9a7..79e5bb616 100644 --- a/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp +++ b/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp @@ -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; diff --git a/PowerEditor/src/Utf8_16.cpp b/PowerEditor/src/Utf8_16.cpp index a59d79e21..42ee64e74 100644 --- a/PowerEditor/src/Utf8_16.cpp +++ b/PowerEditor/src/Utf8_16.cpp @@ -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(i) != L_USER) { int cmdID = nppParam.langTypeToCommandID(static_cast(i)); if ((cmdID != -1)) { + wstring str; getNameStrFromCmd(cmdID, str); if (str.length() > 0) { diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 4b71a6954..b2b424c77 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -455,7 +455,7 @@ void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem, const wchar SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0, reinterpret_cast(&tvItem)); if (tvItem.lParam) { - wstring *fn = (wstring *)tvItem.lParam; + const wstring *fn = reinterpret_cast(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; diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h index cdadba636..3442f7698 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h @@ -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 { diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 83d5d8270..ceeffe00c 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -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"\\"; diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.cpp b/PowerEditor/src/WinControls/TreeView/TreeView.cpp index d14774b42..4f42a0a1b 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.cpp +++ b/PowerEditor/src/WinControls/TreeView/TreeView.cpp @@ -281,7 +281,7 @@ HTREEITEM TreeView::searchSubItemByName(const wchar_t *itemName, HTREEITEM hPare return nullptr; } -bool TreeView::setImageList(std::vector imageIds, int imgSize) +bool TreeView::setImageList(const std::vector& imageIds, int imgSize) { const int nbImage = static_cast(imageIds.size()); if (imgSize <= 0) diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.h b/PowerEditor/src/WinControls/TreeView/TreeView.h index 231a974f5..77d999c31 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.h +++ b/PowerEditor/src/WinControls/TreeView/TreeView.h @@ -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 imageIds, int imgSize = 0); + bool setImageList(const std::vector& imageIds, int imgSize = 0); protected: HIMAGELIST _hImaLst = nullptr; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 941ec8080..1cdc13032 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -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); diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 203ed1eb5..6278318f3 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -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)