diff --git a/NppJSONViewer/DockingDlgInterface.h b/NppJSONViewer/DockingDlgInterface.h index d9bd175..edef060 100644 --- a/NppJSONViewer/DockingDlgInterface.h +++ b/NppJSONViewer/DockingDlgInterface.h @@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef DOCKINGDLGINTERFACE_H -#define DOCKINGDLGINTERFACE_H +#pragma once #include "StaticDialog.h" #include "dockingResource.h" @@ -29,9 +28,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. class DockingDlgInterface : public StaticDialog { public: - DockingDlgInterface(): StaticDialog() {}; - DockingDlgInterface(int dlgID): StaticDialog(), _dlgID(dlgID) {}; - + DockingDlgInterface() : StaticDialog() {}; + DockingDlgInterface(int dlgID) : StaticDialog(), _dlgID(dlgID) {}; + virtual void init(HINSTANCE hInst, HWND parent) { StaticDialog::init(hInst, parent); @@ -39,85 +38,83 @@ class DockingDlgInterface : public StaticDialog lstrcpy(_moduleName, PathFindFileName(_moduleName)); } - void create(tTbData * data, bool isRTL = false){ + void create(tTbData * data, bool isRTL = false) + { StaticDialog::create(_dlgID, isRTL); ::GetWindowText(_hSelf, _pluginName, sizeof(_pluginName)); - // user information - data->hClient = _hSelf; - data->pszName = _pluginName; + // user information + data->hClient = _hSelf; + data->pszName = _pluginName; // supported features by plugin - data->uMask = 0; + data->uMask = 0; // additional info - data->pszAddInfo = NULL; + data->pszAddInfo = NULL; _data = data; - }; + } - virtual void updateDockingDlg(void) { + virtual void updateDockingDlg(void) + { ::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf); } - virtual void destroy() { - }; + virtual void destroy() {} - virtual void display(bool toShow = true) const { - ::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf); - }; + virtual void display(bool toShow = true) const + { + ::SendMessage(_hParent, toShow ? NPPM_DMMSHOW : NPPM_DMMHIDE, 0, (LPARAM)_hSelf); + } - const TCHAR * getPluginFileName() const { - return _moduleName; - }; + const TCHAR * getPluginFileName() const { return _moduleName; } -protected : +protected: virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM /*wParam*/, LPARAM lParam) { - switch (message) + switch (message) { - case WM_NOTIFY: - { - LPNMHDR pnmh = (LPNMHDR)lParam; + case WM_NOTIFY: + { + LPNMHDR pnmh = (LPNMHDR)lParam; - if (pnmh->hwndFrom == _hParent) + if (pnmh->hwndFrom == _hParent) + { + switch (LOWORD(pnmh->code)) + { + case DMN_CLOSE: + { + break; + } + case DMN_FLOAT: + { + _isFloating = true; + break; + } + case DMN_DOCK: { - switch (LOWORD(pnmh->code)) - { - case DMN_CLOSE: - { - break; - } - case DMN_FLOAT: - { - _isFloating = true; - break; - } - case DMN_DOCK: - { - _isFloating = false; - break; - } - default: - break; - } + _isFloating = false; + break; + } + default: + break; } - break; } - default: - break; + break; + } + default: + break; } return FALSE; }; - + // Handles - HWND _HSource; - tTbData* _data; - int _dlgID; - bool _isFloating; - TCHAR _moduleName[MAX_PATH]; - TCHAR _pluginName[MAX_PATH]; + HWND _HSource = nullptr; + tTbData* _data = nullptr; + int _dlgID = 0; + bool _isFloating = false; + TCHAR _moduleName[MAX_PATH] = {}; + TCHAR _pluginName[MAX_PATH] = {}; }; - -#endif // DOCKINGDLGINTERFACE_H diff --git a/NppJSONViewer/JSONDialog.cpp b/NppJSONViewer/JSONDialog.cpp index 06ae8a5..e13cbcf 100644 --- a/NppJSONViewer/JSONDialog.cpp +++ b/NppJSONViewer/JSONDialog.cpp @@ -61,12 +61,12 @@ HTREEITEM JSONDialog::insertToTree(HWND hWndDlg,HTREEITEM parent, const char *te tvinsert.hInsertAfter=TVI_LAST; tvinsert.item.mask=TVIF_TEXT; - int len = strlen(text) + 1; + auto len = strlen(text) + 1; wchar_t *w_msg = new wchar_t[len]; if (w_msg) { memset(w_msg, 0, len); - MultiByteToWideChar(CP_UTF8, NULL, text, -1, w_msg, len); + MultiByteToWideChar(CP_UTF8, NULL, text, -1, w_msg, static_cast(len)); tvinsert.item.pszText = w_msg; item = (HTREEITEM)SendDlgItemMessage(hWndDlg, IDC_TREE1, TVM_INSERTITEM, 0, (LPARAM)&tvinsert); @@ -88,14 +88,16 @@ void JSONDialog::setJSON(char* json) drawTreeSaxParse(); } -void JSONDialog::populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char *json) { +void JSONDialog::populateTreeUsingSax(HWND /*hWndDlg*/, HTREEITEM tree_root, char *json) +{ //Stopwatch sw; //sw.Start(); TreeBuilder handler(this, tree_root); rapidjson::Reader reader; rapidjson::StringStream ss(json); - if (!reader.Parse(ss, handler)) { + if (!reader.Parse(ss, handler)) + { ::MessageBox(nppData._nppHandle, TEXT("Could not parse!!"), TEXT("JSON Viewer"), MB_OK | MB_ICONERROR); //mark the error position @@ -341,7 +343,8 @@ void JSONDialog::drawTreeSaxParse() HTREEITEM tree_root; tree_root = initTree(this->getHSelf()); - if (strlen(curJSON) == 0) { + if (strlen(curJSON) == 0) + { insertToTree(this->getHSelf(), tree_root, "Error:Please select a JSON String."); TreeView_Expand(GetDlgItem(this->getHSelf(), IDC_TREE1), tree_root, TVE_EXPAND); return; diff --git a/NppJSONViewer/JSONDialog.h b/NppJSONViewer/JSONDialog.h index 57b1715..ea43226 100644 --- a/NppJSONViewer/JSONDialog.h +++ b/NppJSONViewer/JSONDialog.h @@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef JSONDIALOG_H -#define JSONDIALOG_H +#pragma once #include "DockingDlgInterface.h" #include "PluginInterface.h" @@ -28,31 +27,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class JSONDialog : public DockingDlgInterface { - char *curJSON; - HANDLE hTree; + char *curJSON = nullptr; + HANDLE hTree = nullptr; //void drawTree(); void drawTreeSaxParse(); HTREEITEM initTree(HWND hWndDlg); - HTREEITEM insertToTree(HWND hWndDlg,HTREEITEM parent,const char *text); + HTREEITEM insertToTree(HWND hWndDlg, HTREEITEM parent, const char *text); //void populateTree (HWND hWndDlg, HTREEITEM tree_root, json_t * json_root, int level); void populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char * json); -public : - JSONDialog() : DockingDlgInterface(IDD_TREE){}; +public: + JSONDialog() : DockingDlgInterface(IDD_TREE) {}; HTREEITEM insertToTree(HTREEITEM parent, const char *text); - virtual void display(bool toShow = true) const { - DockingDlgInterface::display(toShow); - }; + virtual void display(bool toShow = true) const + { + DockingDlgInterface::display(toShow); + } - void setParent(HWND parent2set){ + void setParent(HWND parent2set) + { _hParent = parent2set; - }; + } void setJSON(char *json); -protected : +protected: virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); }; - -#endif //JSONDIALOG_H diff --git a/NppJSONViewer/NPPJSONViewer.vcxproj b/NppJSONViewer/NPPJSONViewer.vcxproj index 0f37810..1fd4ba6 100644 --- a/NppJSONViewer/NPPJSONViewer.vcxproj +++ b/NppJSONViewer/NPPJSONViewer.vcxproj @@ -98,6 +98,7 @@ EditAndContinue true true + true shlwapi.lib;comctl32.lib;%(AdditionalDependencies) @@ -116,6 +117,7 @@ ProgramDatabase true true + true shlwapi.lib;comctl32.lib;%(AdditionalDependencies) @@ -136,6 +138,7 @@ ProgramDatabase true true + true shlwapi.lib;comctl32.lib;%(AdditionalDependencies) @@ -159,6 +162,7 @@ EditAndContinue true true + true shlwapi.lib;comctl32.lib;%(AdditionalDependencies) diff --git a/NppJSONViewer/PluginDefinition.cpp b/NppJSONViewer/PluginDefinition.cpp index 2fc6c2d..1d1608b 100644 --- a/NppJSONViewer/PluginDefinition.cpp +++ b/NppJSONViewer/PluginDefinition.cpp @@ -228,7 +228,7 @@ void formatSelectedJSON() { rapidjson::StringBuffer sb; rapidjson::PrettyWriter pw(sb); bool useTabs = ::SendMessage(curScintilla, SCI_GETUSETABS, 0, 0); - int indentLen = useTabs ? 1 : ::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0); + unsigned indentLen = useTabs ? 1 : static_cast(::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0)); char indentChar = useTabs ? '\t' : ' '; pw.SetIndent(indentChar, indentLen); rapidjson::StringStream ss(curJSON); diff --git a/NppJSONViewer/StaticDialog.cpp b/NppJSONViewer/StaticDialog.cpp index abfb9cf..79f15d6 100644 --- a/NppJSONViewer/StaticDialog.cpp +++ b/NppJSONViewer/StaticDialog.cpp @@ -80,7 +80,7 @@ void StaticDialog::create(int dialogID, bool isRTL) { DWORD err = ::GetLastError(); char errMsg[256]; - sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %u", err); + sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %lu", err); ::MessageBoxA(NULL, errMsg, "In StaticDialog::create()", MB_OK); return; } diff --git a/NppJSONViewer/TreeBuilder.cpp b/NppJSONViewer/TreeBuilder.cpp index 515a39c..cb2398a 100644 --- a/NppJSONViewer/TreeBuilder.cpp +++ b/NppJSONViewer/TreeBuilder.cpp @@ -41,11 +41,13 @@ const char* NULL_STR = "null"; const char* TRUE_STR = "true"; const char* FALSE_STR = "false"; -bool TreeBuilder::Null() { +bool TreeBuilder::Null() +{ return this->String(NULL_STR, sizeof(NULL_STR), true); } -bool TreeBuilder::Bool(bool b) { +bool TreeBuilder::Bool(bool b) +{ if (b) return this->String(TRUE_STR, sizeof(TRUE_STR), true); return this->String(FALSE_STR, sizeof(FALSE_STR), true); @@ -57,16 +59,19 @@ bool TreeBuilder::Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; retur bool TreeBuilder::Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; } bool TreeBuilder::Double(double d) { cout << "Double(" << d << ")" << endl; return true; } -bool TreeBuilder::RawNumber(const char *str, SizeType length, bool copy) { +bool TreeBuilder::RawNumber(const char *str, SizeType length, bool copy) +{ return this->String(str, length, copy); } -bool TreeBuilder::String(const char* str, SizeType length, bool copy) { +bool TreeBuilder::String(const char* str, SizeType length, bool /*copy*/) +{ // copy and process TreeNode *parent = this->stack.top(); char *value = NULL; - int len; - if (!parent->isArray) { + size_t len = 0; + if (!parent->isArray) + { len = strlen(this->lastKey) + 3 + length + 1; value = new char[len]; snprintf(value, len, "%s : %s", this->lastKey, str); @@ -74,7 +79,8 @@ bool TreeBuilder::String(const char* str, SizeType length, bool copy) { delete[] this->lastKey; this->lastKey = NULL; } - else { + else + { string strCount = SSTR(parent->counter); len = strCount.size() + 3 + length + 1; value = new char[len]; @@ -91,27 +97,33 @@ bool TreeBuilder::String(const char* str, SizeType length, bool copy) { return true; } -bool TreeBuilder::StartObject() { +bool TreeBuilder::StartObject() +{ TreeNode *parent; - if (this->stack.empty()) { + if (this->stack.empty()) + { parent = new TreeNode; parent->isArray = false; parent->subRoot = treeRoot; parent->counter = 0; this->stack.push(parent); } - else { + else + { parent = this->stack.top(); } - if (this->lastKey != NULL || parent->isArray) { + if (this->lastKey != NULL || parent->isArray) + { HTREEITEM newNode; - if (!parent->isArray) { + if (!parent->isArray) + { newNode = this->dlg->insertToTree(parent->subRoot, this->lastKey); delete this->lastKey; this->lastKey = NULL; } - else { + else + { newNode = this->dlg->insertToTree(parent->subRoot, SSTR(parent->counter).c_str()); } @@ -125,8 +137,10 @@ bool TreeBuilder::StartObject() { return true; } -bool TreeBuilder::EndObject(SizeType memberCount) { - if (!this->stack.empty()) { +bool TreeBuilder::EndObject(SizeType /*memberCount*/) +{ + if (!this->stack.empty()) + { TreeNode *node = this->stack.top(); this->stack.pop(); delete node; @@ -134,34 +148,41 @@ bool TreeBuilder::EndObject(SizeType memberCount) { return true; } -bool TreeBuilder::Key(const char* str, SizeType length, bool copy) { +bool TreeBuilder::Key(const char* str, SizeType length, bool /*copy*/) +{ this->lastKey = new char[length + 1]; strncpy(this->lastKey, str, length); this->lastKey[length] = '\0'; return true; } -bool TreeBuilder::StartArray() { +bool TreeBuilder::StartArray() +{ TreeNode *parent; - if (this->stack.empty()) { + if (this->stack.empty()) + { parent = new TreeNode; parent->isArray = false; parent->subRoot = treeRoot; parent->counter = 0; this->stack.push(parent); } - else { + else + { parent = this->stack.top(); } - if (this->lastKey != NULL || parent->isArray) { + if (this->lastKey != NULL || parent->isArray) + { HTREEITEM newNode; - if (!parent->isArray) { + if (!parent->isArray) + { newNode = this->dlg->insertToTree(parent->subRoot, this->lastKey); delete this->lastKey; this->lastKey = NULL; } - else { + else + { newNode = this->dlg->insertToTree(parent->subRoot, SSTR(parent->counter).c_str()); } parent->counter++; @@ -174,8 +195,10 @@ bool TreeBuilder::StartArray() { return true; } -bool TreeBuilder::EndArray(SizeType elementCount) { - if (!this->stack.empty()) { +bool TreeBuilder::EndArray(SizeType /*elementCount*/) +{ + if (!this->stack.empty()) + { TreeNode *node = this->stack.top(); this->stack.pop(); delete node; @@ -183,14 +206,3 @@ bool TreeBuilder::EndArray(SizeType elementCount) { return true; } -TreeBuilder::TreeBuilder(JSONDialog *dlg, HTREEITEM treeRoot) { - this->dlg = dlg; - this->lastKey = NULL; - this->treeRoot = treeRoot; -} - - -TreeBuilder::~TreeBuilder() -{ -} - diff --git a/NppJSONViewer/TreeBuilder.h b/NppJSONViewer/TreeBuilder.h index 84230f0..ffbf394 100644 --- a/NppJSONViewer/TreeBuilder.h +++ b/NppJSONViewer/TreeBuilder.h @@ -17,13 +17,13 @@ struct TreeNode { class TreeBuilder : public BaseReaderHandler, TreeBuilder> { - JSONDialog *dlg; + JSONDialog *dlg = nullptr; std::stack stack; - HTREEITEM treeRoot; - char *lastKey; + HTREEITEM treeRoot = nullptr; + char *lastKey = nullptr; public: - TreeBuilder(JSONDialog *dlg, HTREEITEM treeRoot); - ~TreeBuilder(); + TreeBuilder(JSONDialog *dlg, HTREEITEM treeRoot) : dlg(dlg), treeRoot(treeRoot) {} + ~TreeBuilder() = default; bool Null(); bool Bool(bool b); diff --git a/NppJSONViewer/json.c b/NppJSONViewer/json.c index 72e7a04..712bba8 100644 --- a/NppJSONViewer/json.c +++ b/NppJSONViewer/json.c @@ -2165,7 +2165,7 @@ lexer (const char *buffer, const char **p, unsigned int *state, rcstring ** text break; default: - fprintf (stderr, "JSON: *state missing: %d\n", *state); + fprintf (stderr, "JSON: *state missing: %u\n", *state); return LEX_INVALID_CHARACTER; } @@ -4237,8 +4237,7 @@ json_saxy_parse (struct json_saxy_parser_status *jsps, struct json_saxy_function } return JSON_OK; } - - return JSON_UNKNOWN_PROBLEM; + //return JSON_UNKNOWN_PROBLEM; // unreachable code } diff --git a/NppJSONViewer/utils.h b/NppJSONViewer/utils.h index 5ca6772..ccb26bd 100644 --- a/NppJSONViewer/utils.h +++ b/NppJSONViewer/utils.h @@ -1,5 +1,5 @@ #pragma once #include -#define SSTR( x ) static_cast< std::ostringstream & >( \ - ( std::ostringstream() << std::dec << x ) ).str() +template +constexpr auto SSTR(T x) { return (std::ostringstream() << std::dec << x).str(); }