mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-03-29 07:58:06 -04:00
json-builder: add raw mode that leaves keys/strings like they are
This commit is contained in:
parent
7dd924797b
commit
bdbb5f6d27
1 changed files with 5 additions and 3 deletions
|
|
@ -49,6 +49,7 @@ struct spa_json_builder {
|
||||||
#define SPA_JSON_BUILDER_FLAG_PRETTY (SPA_JSON_BUILDER_FLAG_INDENT|SPA_JSON_BUILDER_FLAG_SPACE)
|
#define SPA_JSON_BUILDER_FLAG_PRETTY (SPA_JSON_BUILDER_FLAG_INDENT|SPA_JSON_BUILDER_FLAG_SPACE)
|
||||||
#define SPA_JSON_BUILDER_FLAG_COLOR (1<<3)
|
#define SPA_JSON_BUILDER_FLAG_COLOR (1<<3)
|
||||||
#define SPA_JSON_BUILDER_FLAG_SIMPLE (1<<4)
|
#define SPA_JSON_BUILDER_FLAG_SIMPLE (1<<4)
|
||||||
|
#define SPA_JSON_BUILDER_FLAG_RAW (1<<5)
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t indent_off;
|
uint32_t indent_off;
|
||||||
uint32_t level;
|
uint32_t level;
|
||||||
|
|
@ -151,6 +152,7 @@ void spa_json_builder_add_simple(struct spa_json_builder *b, const char *key, in
|
||||||
{
|
{
|
||||||
bool indent = b->indent_off == 0 && (b->flags & SPA_JSON_BUILDER_FLAG_INDENT);
|
bool indent = b->indent_off == 0 && (b->flags & SPA_JSON_BUILDER_FLAG_INDENT);
|
||||||
bool space = b->flags & SPA_JSON_BUILDER_FLAG_SPACE;
|
bool space = b->flags & SPA_JSON_BUILDER_FLAG_SPACE;
|
||||||
|
bool force_raw = b->flags & SPA_JSON_BUILDER_FLAG_RAW;
|
||||||
bool raw = true, simple = b->flags & SPA_JSON_BUILDER_FLAG_SIMPLE;
|
bool raw = true, simple = b->flags & SPA_JSON_BUILDER_FLAG_SIMPLE;
|
||||||
int color;
|
int color;
|
||||||
|
|
||||||
|
|
@ -185,8 +187,8 @@ void spa_json_builder_add_simple(struct spa_json_builder *b, const char *key, in
|
||||||
fprintf(b->f, "%s%s%*s", b->delim, indent ? b->count == 0 ? "" : "\n" : space ? " " : "",
|
fprintf(b->f, "%s%s%*s", b->delim, indent ? b->count == 0 ? "" : "\n" : space ? " " : "",
|
||||||
indent ? b->level : 0, "");
|
indent ? b->level : 0, "");
|
||||||
if (key) {
|
if (key) {
|
||||||
bool key_raw = (simple && spa_json_make_simple_string(&key, &key_len)) ||
|
bool key_raw = force_raw || (simple && spa_json_make_simple_string(&key, &key_len)) ||
|
||||||
spa_json_is_string(key, key_len);
|
spa_json_is_string(key, key_len);
|
||||||
spa_json_builder_encode_string(b, key_raw,
|
spa_json_builder_encode_string(b, key_raw,
|
||||||
b->color[1], key, key_len, b->color[0]);
|
b->color[1], key, key_len, b->color[0]);
|
||||||
fprintf(b->f, "%s%s", b->key_sep, space ? " " : "");
|
fprintf(b->f, "%s%s", b->key_sep, space ? " " : "");
|
||||||
|
|
@ -219,7 +221,7 @@ void spa_json_builder_add_simple(struct spa_json_builder *b, const char *key, in
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
color = SPA_JSON_BUILDER_COLOR_STRING;
|
color = SPA_JSON_BUILDER_COLOR_STRING;
|
||||||
raw = simple && spa_json_make_simple_string(&val, &val_len);
|
raw = force_raw || (simple && spa_json_make_simple_string(&val, &val_len));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
spa_json_builder_encode_string(b, raw, b->color[color], val, val_len, b->color[0]);
|
spa_json_builder_encode_string(b, raw, b->color[color], val, val_len, b->color[0]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue