MCPcopy Index your code
hub / github.com/Kitware/CMake / cmJSONState

Method cmJSONState

Source/cmJSONState.cxx:19–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17#include "cmSystemTools.h"
18
19cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root)
20 : Filename(std::move(jsonFile))
21{
22 cmsys::ifstream fin(this->Filename.c_str(), std::ios::in | std::ios::binary);
23 if (!fin) {
24 this->AddError(cmStrCat("File not found: ", this->Filename));
25 return;
26 }
27 // If there's a BOM, toss it.
28 cmsys::FStream::ReadBOM(fin);
29
30 // Save the entire document.
31 std::streampos finBegin = fin.tellg();
32 this->doc = std::string(std::istreambuf_iterator<char>(fin),
33 std::istreambuf_iterator<char>());
34 if (this->doc.empty()) {
35 this->AddError("A JSON document cannot be empty");
36 return;
37 }
38 fin.seekg(finBegin);
39
40 Json::CharReaderBuilder builder;
41 Json::CharReaderBuilder::strictMode(&builder.settings_);
42 std::string errMsg;
43
44#if JSONCPP_VERSION_HEXA >= 0x01090600
45 // Has StructuredError
46 std::unique_ptr<Json::CharReader> const reader(builder.newCharReader());
47 reader->parse(doc.data(), doc.data() + doc.size(), root, &errMsg);
48 std::vector<Json::CharReader::StructuredError> structuredErrors =
49 reader->getStructuredErrors();
50 for (auto const& structuredError : structuredErrors) {
51 this->AddErrorAtOffset(structuredError.message,
52 structuredError.offset_start);
53 }
54#else
55 // No StructuredError Available, Use error string from jsonCpp
56 if (!Json::parseFromStream(builder, fin, root, &errMsg)) {
57 errMsg = cmStrCat("JSON Parse Error: ", this->Filename, ":\n", errMsg);
58 this->AddError(errMsg);
59 }
60#endif
61}
62
63void cmJSONState::AddError(std::string const& errMsg)
64{

Callers

nothing calls this directly

Calls 13

AddErrorMethod · 0.95
AddErrorAtOffsetMethod · 0.95
moveFunction · 0.85
ReadBOMFunction · 0.85
parseFromStreamFunction · 0.85
c_strMethod · 0.80
newCharReaderMethod · 0.80
cmStrCatFunction · 0.70
emptyMethod · 0.45
parseMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected