Eric Blake <ebl...@redhat.com> writes: > The next patch will add pretty indentation to the JSON visitor. > But in order to support pretty output in the type_any() callback, > we need to prefix every line of the QObject visitor by the current > indentation in the JSON visitor. Hence, a new function > qobject_to_json_pretty_indent(), and the old function becomes a > thin wrapper to the expanded behavior. > > While at it, change 'pretty' to be a bool, to match its usage. > > Note that the new simple_pretty() test is a bit sensitive to our > current notion of prettiness, as well as to the hash ordering in > QDict (most of the tests in check-qobject-json intentionally do > not compare the original string to the round-trip string, because > we liberally accept more input forms than the canonical form that > we output). > > Signed-off-by: Eric Blake <ebl...@redhat.com> > > --- > v3: no change > v2: no change > --- > include/qapi/qmp/qobject-json.h | 1 + > qobject/qobject-json.c | 40 ++++++++++++++++++------- > tests/check-qobject-json.c | 65 > +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 95 insertions(+), 11 deletions(-) > > diff --git a/include/qapi/qmp/qobject-json.h b/include/qapi/qmp/qobject-json.h > index 02b1f2c..d420c71 100644 > --- a/include/qapi/qmp/qobject-json.h > +++ b/include/qapi/qmp/qobject-json.h > @@ -23,5 +23,6 @@ QObject *qobject_from_jsonv(const char *string, va_list > *ap) GCC_FMT_ATTR(1, 0); > > QString *qobject_to_json(const QObject *obj); > QString *qobject_to_json_pretty(const QObject *obj); > +QString *qobject_to_json_pretty_prefix(const QObject *obj, const char > *prefix);
Why a string prefix, and not indentation? > > #endif /* QJSON_H */ [...]