MCPcopy Create free account
hub / github.com/ComodoSecurity/openedr / printValueTree

Function printValueTree

edrav2/eprj/jsoncpp/src/jsontestrunner/main.cpp:71–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71static void printValueTree(FILE* fout,
72 Json::Value& value,
73 const JSONCPP_STRING& path = ".") {
74 if (value.hasComment(Json::commentBefore)) {
75 fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
76 }
77 switch (value.type()) {
78 case Json::nullValue:
79 fprintf(fout, "%s=null\n", path.c_str());
80 break;
81 case Json::intValue:
82 fprintf(fout, "%s=%s\n", path.c_str(),
83 Json::valueToString(value.asLargestInt()).c_str());
84 break;
85 case Json::uintValue:
86 fprintf(fout, "%s=%s\n", path.c_str(),
87 Json::valueToString(value.asLargestUInt()).c_str());
88 break;
89 case Json::realValue:
90 fprintf(fout, "%s=%s\n", path.c_str(),
91 normalizeFloatingPointStr(value.asDouble()).c_str());
92 break;
93 case Json::stringValue:
94 fprintf(fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str());
95 break;
96 case Json::booleanValue:
97 fprintf(fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false");
98 break;
99 case Json::arrayValue: {
100 fprintf(fout, "%s=[]\n", path.c_str());
101 Json::ArrayIndex size = value.size();
102 for (Json::ArrayIndex index = 0; index < size; ++index) {
103 static char buffer[16];
104 jsoncpp_snprintf(buffer, sizeof(buffer), "[%u]", index);
105 printValueTree(fout, value[index], path + buffer);
106 }
107 } break;
108 case Json::objectValue: {
109 fprintf(fout, "%s={}\n", path.c_str());
110 Json::Value::Members members(value.getMemberNames());
111 std::sort(members.begin(), members.end());
112 JSONCPP_STRING suffix = *(path.end() - 1) == '.' ? "" : ".";
113 for (auto name : members) {
114 printValueTree(fout, value[name], path + suffix + name);
115 }
116 } break;
117 default:
118 break;
119 }
120
121 if (value.hasComment(Json::commentAfter)) {
122 fprintf(fout, "%s\n", value.getComment(Json::commentAfter).c_str());
123 }
124}
125
126static int parseAndSaveValueTree(const JSONCPP_STRING& input,
127 const JSONCPP_STRING& actual,

Callers 1

parseAndSaveValueTreeFunction · 0.85

Calls 15

valueToStringFunction · 0.85
hasCommentMethod · 0.80
getCommentMethod · 0.80
asLargestIntMethod · 0.80
asLargestUIntMethod · 0.80
asDoubleMethod · 0.80
asStringMethod · 0.80
asBoolMethod · 0.80
getMemberNamesMethod · 0.80
sortFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected