| 74 | } |
| 75 | |
| 76 | static void |
| 77 | printValueTree(FILE* fout, Json::Value& value, const JSONCPP_STRING& path = ".") { |
| 78 | if (value.hasComment(Json::commentBefore)) { |
| 79 | fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str()); |
| 80 | } |
| 81 | switch (value.type()) { |
| 82 | case Json::nullValue: |
| 83 | fprintf(fout, "%s=null\n", path.c_str()); |
| 84 | break; |
| 85 | case Json::intValue: |
| 86 | fprintf(fout, |
| 87 | "%s=%s\n", |
| 88 | path.c_str(), |
| 89 | Json::valueToString(value.asLargestInt()).c_str()); |
| 90 | break; |
| 91 | case Json::uintValue: |
| 92 | fprintf(fout, |
| 93 | "%s=%s\n", |
| 94 | path.c_str(), |
| 95 | Json::valueToString(value.asLargestUInt()).c_str()); |
| 96 | break; |
| 97 | case Json::realValue: |
| 98 | fprintf(fout, |
| 99 | "%s=%s\n", |
| 100 | path.c_str(), |
| 101 | normalizeFloatingPointStr(value.asDouble()).c_str()); |
| 102 | break; |
| 103 | case Json::stringValue: |
| 104 | fprintf(fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str()); |
| 105 | break; |
| 106 | case Json::booleanValue: |
| 107 | fprintf(fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false"); |
| 108 | break; |
| 109 | case Json::arrayValue: { |
| 110 | fprintf(fout, "%s=[]\n", path.c_str()); |
| 111 | Json::ArrayIndex size = value.size(); |
| 112 | for (Json::ArrayIndex index = 0; index < size; ++index) { |
| 113 | static char buffer[16]; |
| 114 | #if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) |
| 115 | sprintf_s(buffer, sizeof(buffer), "[%d]", index); |
| 116 | #else |
| 117 | snprintf(buffer, sizeof(buffer), "[%d]", index); |
| 118 | #endif |
| 119 | printValueTree(fout, value[index], path + buffer); |
| 120 | } |
| 121 | } break; |
| 122 | case Json::objectValue: { |
| 123 | fprintf(fout, "%s={}\n", path.c_str()); |
| 124 | Json::Value::Members members(value.getMemberNames()); |
| 125 | std::sort(members.begin(), members.end()); |
| 126 | JSONCPP_STRING suffix = *(path.end() - 1) == '.' ? "" : "."; |
| 127 | for (Json::Value::Members::iterator it = members.begin(); |
| 128 | it != members.end(); |
| 129 | ++it) { |
| 130 | const JSONCPP_STRING name = *it; |
| 131 | printValueTree(fout, value[name], path + suffix + name); |
| 132 | } |
| 133 | } break; |
no test coverage detected