| 68 | |
| 69 | template <typename JSONParser> |
| 70 | void jsonElementToString(const typename JSONParser::Element & element, WriteBuffer & buf, const FormatSettings & format_settings) |
| 71 | { |
| 72 | if (element.isInt64()) |
| 73 | { |
| 74 | writeIntText(element.getInt64(), buf); |
| 75 | return; |
| 76 | } |
| 77 | if (element.isUInt64()) |
| 78 | { |
| 79 | writeIntText(element.getUInt64(), buf); |
| 80 | return; |
| 81 | } |
| 82 | if (element.isDouble()) |
| 83 | { |
| 84 | writeFloatText(element.getDouble(), buf); |
| 85 | return; |
| 86 | } |
| 87 | if (element.isBool()) |
| 88 | { |
| 89 | if (element.getBool()) |
| 90 | writeCString("true", buf); |
| 91 | else |
| 92 | writeCString("false", buf); |
| 93 | return; |
| 94 | } |
| 95 | if (element.isString()) |
| 96 | { |
| 97 | writeJSONString(element.getString(), buf, format_settings); |
| 98 | return; |
| 99 | } |
| 100 | if (element.isArray()) |
| 101 | { |
| 102 | writeChar('[', buf); |
| 103 | bool need_comma = false; |
| 104 | for (auto value : element.getArray()) |
| 105 | { |
| 106 | if (std::exchange(need_comma, true)) |
| 107 | writeChar(',', buf); |
| 108 | jsonElementToString<JSONParser>(value, buf, format_settings); |
| 109 | } |
| 110 | writeChar(']', buf); |
| 111 | return; |
| 112 | } |
| 113 | if (element.isObject()) |
| 114 | { |
| 115 | writeChar('{', buf); |
| 116 | bool need_comma = false; |
| 117 | for (auto [key, value] : element.getObject()) |
| 118 | { |
| 119 | if (std::exchange(need_comma, true)) |
| 120 | writeChar(',', buf); |
| 121 | writeJSONString(key, buf, format_settings); |
| 122 | writeChar(':', buf); |
| 123 | jsonElementToString<JSONParser>(value, buf, format_settings); |
| 124 | } |
| 125 | writeChar('}', buf); |
| 126 | return; |
| 127 | } |
nothing calls this directly
no test coverage detected