MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / serialize

Method serialize

lib/sarifreport.cpp:180–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180std::string SarifReport::serialize(std::string productName) const
181{
182 const auto nameAndVersion = Settings::getNameAndVersion(productName);
183 productName = nameAndVersion.first.empty() ? "Cppcheck" : nameAndVersion.first;
184 std::string version = nameAndVersion.first.empty() ? CppCheck::version() : nameAndVersion.second;
185 if (version.find(' ') != std::string::npos)
186 version.erase(version.find(' '), std::string::npos);
187
188 picojson::object doc;
189 doc["$schema"] = picojson::value(sarifSchema);
190 doc["runs"] = serializeRuns(productName, version);
191
192 // Insert "version" property at the start.
193 // From SARIF specification (https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790730):
194 // Although the order in which properties appear in a JSON object value is not semantically significant, the version property SHOULD appear first.
195
196 return "{\n \"version\": \"" + std::string(sarifVersion) + "\"," + picojson::value(doc).serialize(true).substr(1);
197}
198
199std::string SarifReport::sarifSeverity(const ErrorMessage& errmsg)
200{

Callers

nothing calls this directly

Calls 4

valueClass · 0.70
emptyMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected