| 235 | } |
| 236 | |
| 237 | static void append_sub_jw(struct json_writer *jw, |
| 238 | const struct json_writer *value) |
| 239 | { |
| 240 | /* |
| 241 | * If both are pretty, increase the indentation of the sub_jw |
| 242 | * to better fit under the super. |
| 243 | * |
| 244 | * If the super is pretty, but the sub_jw is compact, leave the |
| 245 | * sub_jw compact. (We don't want to parse and rebuild the sub_jw |
| 246 | * for this debug-ish feature.) |
| 247 | * |
| 248 | * If the super is compact, and the sub_jw is pretty, convert |
| 249 | * the sub_jw to compact. |
| 250 | * |
| 251 | * If both are compact, keep the sub_jw compact. |
| 252 | */ |
| 253 | if (jw->pretty && jw->open_stack.len && value->pretty) { |
| 254 | struct strbuf sb = STRBUF_INIT; |
| 255 | increase_indent(&sb, value, jw->open_stack.len * 2); |
| 256 | strbuf_addbuf(&jw->json, &sb); |
| 257 | strbuf_release(&sb); |
| 258 | return; |
| 259 | } |
| 260 | if (!jw->pretty && value->pretty) { |
| 261 | struct strbuf sb = STRBUF_INIT; |
| 262 | kill_indent(&sb, value); |
| 263 | strbuf_addbuf(&jw->json, &sb); |
| 264 | strbuf_release(&sb); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | strbuf_addbuf(&jw->json, &value->json); |
| 269 | } |
| 270 | |
| 271 | void jw_object_sub_jw(struct json_writer *jw, const char *key, |
| 272 | const struct json_writer *value) |
no test coverage detected