From f8d0e01e46cd9452b5d7780906029d899215cb89 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Fri, 13 Aug 2010 22:11:04 +0300 Subject: [PATCH] Change the maximum indentation size to 32 spaces in encoder This is to free up bits from the flags parameter of json_dump functions. I'm pretty sure no-one needs 256 spaces of indentation when pretty-printing JSON values... This is a backwards incompatible change. --- doc/apiref.rst | 2 +- src/dump.c | 4 ++-- src/jansson.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/apiref.rst b/doc/apiref.rst index 91de0c8..aad0d6c 100644 --- a/doc/apiref.rst +++ b/doc/apiref.rst @@ -618,7 +618,7 @@ can be ORed together to obtain *flags*. ``JSON_INDENT(n)`` Pretty-print the result, using newlines between array and object items, and indenting with *n* spaces. The valid range for *n* is - between 0 and 255, other values result in an undefined output. If + between 0 and 32, other values result in an undefined output. If ``JSON_INDENT`` is not used or *n* is 0, no newlines are inserted between array and object items. diff --git a/src/dump.c b/src/dump.c index b887515..42eb256 100644 --- a/src/dump.c +++ b/src/dump.c @@ -41,8 +41,8 @@ static int dump_to_file(const char *buffer, int size, void *data) return 0; } -/* 256 spaces (the maximum indentation size) */ -static char whitespace[] = " "; +/* 32 spaces (the maximum indentation size) */ +static char whitespace[] = " "; static int dump_indent(size_t flags, int depth, int space, dump_func dump, void *data) { diff --git a/src/jansson.h b/src/jansson.h index 5324e57..5d335ae 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -181,11 +181,11 @@ json_t *json_loads(const char *input, json_error_t *error); json_t *json_loadf(FILE *input, json_error_t *error); json_t *json_load_file(const char *path, json_error_t *error); -#define JSON_INDENT(n) (n & 0xFF) -#define JSON_COMPACT 0x100 -#define JSON_ENSURE_ASCII 0x200 -#define JSON_SORT_KEYS 0x400 -#define JSON_PRESERVE_ORDER 0x800 +#define JSON_INDENT(n) (n & 0x1F) +#define JSON_COMPACT 0x20 +#define JSON_ENSURE_ASCII 0x40 +#define JSON_SORT_KEYS 0x80 +#define JSON_PRESERVE_ORDER 0x100 char *json_dumps(const json_t *json, size_t flags); int json_dumpf(const json_t *json, FILE *output, size_t flags);