static void PrettyPrintNode(TxtNode *curr, int nest, str::Str<char>& res) { if (TextNode == curr->type) { PrettyPrintKeyVal(curr, nest, res); return; } if (StructNode == curr->type) { PrettyPrintKeyVal(curr, nest, res); res.Append(" + [\n"); } else if (nest >= 0) { CrashIf(ArrayNode != curr->type); AppendNest(res, nest); res.Append("[\n"); } TxtNode *child; for (size_t i = 0; i < curr->children->Count(); i++) { child = curr->children->At(i); PrettyPrintNode(child, nest + 1, res); } if (nest >= 0) { AppendNest(res, nest); res.Append("]\n"); } }
static void AppendKeyVal(EncodeState& es, const char *key, const char *val) { if (es.compact) { es.res.Append(" "); } else { AppendNest(es.res, es.nest); es.res.Append(key); es.res.Append(": "); } AppendVal(val, es.escapeChar, es.compact, es.res); }
static void PrettyPrintKeyVal(TxtNode *curr, int nest, str::Str<char>& res) { AppendNest(res, nest); if (curr->keyStart) { AppendWsTrimEnd(res, curr->keyStart, curr->keyEnd); if (StructNode != curr->type) res.Append(" + "); } AppendWsTrimEnd(res, curr->valStart, curr->valEnd); if (StructNode != curr->type) res.Append("\n"); }