MCPcopy Create free account
hub / github.com/NPP-JSONViewer/JSON-Viewer / PopulateTreeUsingSax

Method PopulateTreeUsingSax

src/NppJsonViewer/JsonViewDlg.cpp:404–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404auto JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string& jsonText) -> std::optional<std::wstring>
405{
406 std::optional<std::wstring> retVal = std::nullopt;
407
408 auto pTS = std::make_shared<TrackingStream>(jsonText);
409 RapidJsonHandler handler(this, tree_root, pTS);
410 rapidjson::StringBuffer sb;
411
412 Result res = JsonHandler(m_pSetting->parseOptions).ParseJson<flgBaseReader>(jsonText, sb, handler, pTS);
413 if (!res.success)
414 {
415 if (CheckForTokenUndefined(JsonViewDlg::eMethod::ParseJson, jsonText, res, tree_root))
416 return retVal;
417
418 // Intimate user
419 if (jsonText.empty())
420 {
421 retVal = std::make_optional<std::wstring>(JSON_ERR_PARSE);
422 }
423 else
424 {
425 // Mark the error position
426 size_t start = m_pEditor->GetSelectionStart();
427 size_t errPosition = start + static_cast<size_t>(res.error_pos);
428 m_pEditor->MakeSelection(errPosition, errPosition + 1);
429
430 std::string err = std::format("\n\nError: ({} : {})", res.error_code, res.error_str);
431 retVal = std::make_optional<std::wstring>((JSON_ERR_VALIDATE + StringHelper::ToWstring(err)));
432 }
433 }
434 else
435 {
436 HighlightAsJson();
437 }
438
439 return retVal;
440}
441
442HTREEITEM JsonViewDlg::InsertToTree(HTREEITEM parent, const std::string& text)
443{

Callers

nothing calls this directly

Calls 3

JsonHandlerClass · 0.85
GetSelectionStartMethod · 0.80
MakeSelectionMethod · 0.80

Tested by

no test coverage detected