Skip to content

Commit 17b9ed2

Browse files
committed
json-parser: factor out sarifReadMsg() helper
No changes in behavior intended by this commit.
1 parent a9e466b commit 17b9ed2

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/json-parser.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,10 @@ void SarifTreeDecoder::readRoot(
427427
pDefList = nullptr;
428428
}
429429

430-
void sarifReadLocation(DefEvent *pEvt, const pt::ptree &defNode)
430+
static void sarifReadLocation(DefEvent *pEvt, const pt::ptree &loc)
431431
{
432-
const pt::ptree *locs;
433-
if (!findChildOf(&locs, defNode, "locations") || locs->empty())
434-
// no location info available
435-
return;
436-
437432
const pt::ptree *pl;
438-
if (!findChildOf(&pl, locs->begin()->second, "physicalLocation"))
433+
if (!findChildOf(&pl, loc, "physicalLocation"))
439434
// unknown location info format
440435
return;
441436

@@ -455,6 +450,13 @@ void sarifReadLocation(DefEvent *pEvt, const pt::ptree &defNode)
455450
}
456451
}
457452

453+
static void sarifReadMsg(std::string *pDst, const pt::ptree &node)
454+
{
455+
const pt::ptree *msgNode;
456+
if (findChildOf(&msgNode, node, "message"))
457+
*pDst = valueOf<std::string>(*msgNode, "text", "<unknown>");
458+
}
459+
458460
bool SarifTreeDecoder::readNode(
459461
Defect *def,
460462
pt::ptree::const_iterator defIter)
@@ -485,14 +487,12 @@ bool SarifTreeDecoder::readNode(
485487
}
486488
}
487489

488-
// read location
490+
// read location and diagnostic message
489491
keyEvent.fileName = "<unknown>";
490-
sarifReadLocation(&keyEvent, defNode);
491-
492-
// read diagnostic message
493-
const pt::ptree *msgNode;
494-
if (findChildOf(&msgNode, defNode, "message"))
495-
keyEvent.msg = valueOf<std::string>(*msgNode, "text", "<unknown>");
492+
const pt::ptree *locs;
493+
if (findChildOf(&locs, defNode, "locations") && !locs->empty())
494+
sarifReadLocation(&keyEvent, locs->begin()->second);
495+
sarifReadMsg(&keyEvent.msg, defNode);
496496

497497
return true;
498498
}

0 commit comments

Comments
 (0)