Skip to content

Commit 328de8a

Browse files
committed
writer-json-simple: factor out simpleEncodeEvents()
... to make the code easier to follow. No change in behavior intended with this commit. Related: #98
1 parent dbd78b8 commit 328de8a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/lib/writer-json-simple.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ void SimpleTreeEncoder::importScanProps(const TScanProps &scanProps)
3131
root_["scan"] = jsonSerializeScanProps(scanProps);
3232
}
3333

34-
void SimpleTreeEncoder::appendDef(const Defect &def)
34+
static array simpleEncodeEvents(const TEvtList &events)
3535
{
36-
// go through events
3736
array evtList;
38-
for (const DefEvent &evt : def.events) {
37+
38+
// go through events
39+
for (const DefEvent &evt : events) {
3940
object evtNode;
4041

4142
// describe the location
@@ -57,13 +58,18 @@ void SimpleTreeEncoder::appendDef(const Defect &def)
5758
evtList.push_back(std::move(evtNode));
5859
}
5960

61+
return evtList;
62+
}
63+
64+
void SimpleTreeEncoder::appendDef(const Defect &def)
65+
{
6066
// create a node for a single defect
6167
object defNode;
6268
defNode["checker"] = def.checker;
69+
70+
// encode optional per-finding properties
6371
if (!def.annotation.empty())
6472
defNode["annotation"] = def.annotation;
65-
66-
// write "defect_id", "cwe", etc. if available
6773
if (0 < def.defectId)
6874
defNode["defect_id"] = def.defectId;
6975
if (0 < def.cwe)
@@ -77,8 +83,9 @@ void SimpleTreeEncoder::appendDef(const Defect &def)
7783
if (!def.tool.empty())
7884
defNode["tool"] = def.tool;
7985

86+
// encode events
8087
defNode["key_event_idx"] = def.keyEventIdx;
81-
defNode["events"] = std::move(evtList);
88+
defNode["events"] = simpleEncodeEvents(def.events);
8289

8390
// create the node representing the list of defects
8491
if (!pDefects_)

0 commit comments

Comments
 (0)