| 69 | } |
| 70 | |
| 71 | static 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 | |
| 126 | static int parseAndSaveValueTree(const JSONCPP_STRING& input, |
| 127 | const JSONCPP_STRING& actual, |
no test coverage detected