forked from osmocom/wireshark
json_dumper: add support to convert dots in underscores.
This is needed for ek json compatibility. Change-Id: I75c74a1dc7996f3f4c17071508655ae6e3c6b94c Reviewed-on: https://code.wireshark.org/review/30993 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
3f09bf685f
commit
3f01aaac49
|
@ -37,7 +37,7 @@ enum json_dumper_change {
|
|||
};
|
||||
|
||||
static void
|
||||
json_puts_string(FILE *fp, const char *str)
|
||||
json_puts_string(FILE *fp, const char *str, gboolean dot_to_underscore)
|
||||
{
|
||||
if (!str) {
|
||||
fputs("null", fp);
|
||||
|
@ -58,7 +58,10 @@ json_puts_string(FILE *fp, const char *str)
|
|||
if (str[i] == '\\' || str[i] == '"') {
|
||||
fputc('\\', fp);
|
||||
}
|
||||
fputc(str[i], fp);
|
||||
if (dot_to_underscore && str[i] == '.')
|
||||
fputc('_', fp);
|
||||
else
|
||||
fputc(str[i], fp);
|
||||
}
|
||||
}
|
||||
fputc('"', fp);
|
||||
|
@ -200,7 +203,7 @@ json_dumper_set_member_name(json_dumper *dumper, const char *name)
|
|||
}
|
||||
|
||||
prepare_token(dumper);
|
||||
json_puts_string(dumper->output_file, name);
|
||||
json_puts_string(dumper->output_file, name, dumper->flags & JSON_DUMPER_DOT_TO_UNDERSCORE);
|
||||
fputc(':', dumper->output_file);
|
||||
if ((dumper->flags & JSON_DUMPER_FLAGS_PRETTY_PRINT)) {
|
||||
fputc(' ', dumper->output_file);
|
||||
|
@ -256,7 +259,7 @@ json_dumper_value_string(json_dumper *dumper, const char *value)
|
|||
}
|
||||
|
||||
prepare_token(dumper);
|
||||
json_puts_string(dumper->output_file, value);
|
||||
json_puts_string(dumper->output_file, value, FALSE);
|
||||
|
||||
dumper->state[dumper->current_depth] = JSON_DUMPER_TYPE_VALUE;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ extern "C" {
|
|||
typedef struct json_dumper {
|
||||
FILE *output_file; /**< Output file, must be set. */
|
||||
#define JSON_DUMPER_FLAGS_PRETTY_PRINT (1 << 0) /* Enable pretty printing. */
|
||||
#define JSON_DUMPER_DOT_TO_UNDERSCORE (1 << 1) /* Convert dots to underscores in keys */
|
||||
int flags;
|
||||
/* for internal use, initialize with zeroes. */
|
||||
int current_depth;
|
||||
|
|
Loading…
Reference in New Issue