Tweak clang-format configuration a bit

Set ColumnLimit to 90, remove AllowShortCaseLabelsOnASingleLine.
This commit is contained in:
Petri Lehtinen
2019-10-19 20:35:28 +03:00
parent 7c0297abe8
commit a8f5fa5f5a
30 changed files with 577 additions and 606 deletions

View File

@@ -68,19 +68,17 @@ static int dump_to_fd(const char *buffer, size_t size, void *data) {
/* 32 spaces (the maximum indentation size) */
static const char whitespace[] = " ";
static int dump_indent(size_t flags, int depth, int space,
json_dump_callback_t dump, void *data) {
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump,
void *data) {
if (FLAGS_TO_INDENT(flags) > 0) {
unsigned int ws_count = FLAGS_TO_INDENT(flags),
n_spaces = depth * ws_count;
unsigned int ws_count = FLAGS_TO_INDENT(flags), n_spaces = depth * ws_count;
if (dump("\n", 1, data))
return -1;
while (n_spaces > 0) {
int cur_n = n_spaces < sizeof whitespace - 1
? n_spaces
: sizeof whitespace - 1;
int cur_n =
n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
if (dump(whitespace, cur_n, data))
return -1;
@@ -93,8 +91,8 @@ static int dump_indent(size_t flags, int depth, int space,
return 0;
}
static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
void *data, size_t flags) {
static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data,
size_t flags) {
const char *pos, *end, *lim;
int32_t codepoint = 0;
@@ -139,19 +137,34 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
/* handle \, /, ", and control codes */
length = 2;
switch (codepoint) {
case '\\': text = "\\\\"; break;
case '\"': text = "\\\""; break;
case '\b': text = "\\b"; break;
case '\f': text = "\\f"; break;
case '\n': text = "\\n"; break;
case '\r': text = "\\r"; break;
case '\t': text = "\\t"; break;
case '/': text = "\\/"; break;
case '\\':
text = "\\\\";
break;
case '\"':
text = "\\\"";
break;
case '\b':
text = "\\b";
break;
case '\f':
text = "\\f";
break;
case '\n':
text = "\\n";
break;
case '\r':
text = "\\r";
break;
case '\t':
text = "\\t";
break;
case '/':
text = "\\/";
break;
default: {
/* codepoint is in BMP */
if (codepoint < 0x10000) {
snprintf(seq, sizeof(seq), "\\u%04X",
(unsigned int)codepoint);
snprintf(seq, sizeof(seq), "\\u%04X", (unsigned int)codepoint);
length = 6;
}
@@ -163,8 +176,8 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
first = 0xD800 | ((codepoint & 0xffc00) >> 10);
last = 0xDC00 | (codepoint & 0x003ff);
snprintf(seq, sizeof(seq), "\\u%04X\\u%04X",
(unsigned int)first, (unsigned int)last);
snprintf(seq, sizeof(seq), "\\u%04X\\u%04X", (unsigned int)first,
(unsigned int)last);
length = 12;
}
@@ -186,9 +199,8 @@ static int compare_keys(const void *key1, const void *key2) {
return strcmp(*(const char **)key1, *(const char **)key2);
}
static int do_dump(const json_t *json, size_t flags, int depth,
hashtable_t *parents, json_dump_callback_t dump,
void *data) {
static int do_dump(const json_t *json, size_t flags, int depth, hashtable_t *parents,
json_dump_callback_t dump, void *data) {
int embed = flags & JSON_EMBED;
flags &= ~JSON_EMBED;
@@ -197,18 +209,21 @@ static int do_dump(const json_t *json, size_t flags, int depth,
return -1;
switch (json_typeof(json)) {
case JSON_NULL: return dump("null", 4, data);
case JSON_NULL:
return dump("null", 4, data);
case JSON_TRUE: return dump("true", 4, data);
case JSON_TRUE:
return dump("true", 4, data);
case JSON_FALSE: return dump("false", 5, data);
case JSON_FALSE:
return dump("false", 5, data);
case JSON_INTEGER: {
char buffer[MAX_INTEGER_STR_LENGTH];
int size;
size = snprintf(buffer, MAX_INTEGER_STR_LENGTH,
"%" JSON_INTEGER_FORMAT, json_integer_value(json));
size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%" JSON_INTEGER_FORMAT,
json_integer_value(json));
if (size < 0 || size >= MAX_INTEGER_STR_LENGTH)
return -1;
@@ -229,8 +244,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
}
case JSON_STRING:
return dump_string(json_string_value(json),
json_string_length(json), dump, data, flags);
return dump_string(json_string_value(json), json_string_length(json), dump,
data, flags);
case JSON_ARRAY: {
size_t n;
@@ -255,8 +270,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
return -1;
for (i = 0; i < n; ++i) {
if (do_dump(json_array_get(json, i), flags, depth + 1, parents,
dump, data))
if (do_dump(json_array_get(json, i), flags, depth + 1, parents, dump,
data))
return -1;
if (i < n - 1) {
@@ -360,8 +375,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
dump_string(key, strlen(key), dump, data, flags);
if (dump(separator, separator_length, data) ||
do_dump(json_object_iter_value(iter), flags, depth + 1,
parents, dump, data))
do_dump(json_object_iter_value(iter), flags, depth + 1, parents,
dump, data))
return -1;
if (next) {
@@ -435,8 +450,8 @@ int json_dump_file(const json_t *json, const char *path, size_t flags) {
return result;
}
int json_dump_callback(const json_t *json, json_dump_callback_t callback,
void *data, size_t flags) {
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data,
size_t flags) {
int res;
hashtable_t parents_set;

View File

@@ -39,9 +39,8 @@ void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
va_end(ap);
}
void jsonp_error_vset(json_error_t *error, int line, int column,
size_t position, enum json_error_code code,
const char *msg, va_list ap) {
void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
enum json_error_code code, const char *msg, va_list ap) {
if (!error)
return;

View File

@@ -54,13 +54,11 @@ static JSON_INLINE void list_remove(list_t *list) {
list->next->prev = list->prev;
}
static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable,
bucket_t *bucket) {
static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket) {
return bucket->first == &hashtable->list && bucket->first == bucket->last;
}
static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
list_t *list) {
static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket, list_t *list) {
if (bucket_is_empty(hashtable, bucket)) {
list_insert(&hashtable->list, list);
bucket->first = bucket->last = list;
@@ -94,8 +92,7 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
}
/* returns 0 on success, -1 if key was not found */
static int hashtable_do_del(hashtable_t *hashtable, const char *key,
size_t hash) {
static int hashtable_do_del(hashtable_t *hashtable, const char *key, size_t hash) {
pair_t *pair;
bucket_t *bucket;
size_t index;
@@ -156,8 +153,7 @@ static int hashtable_do_rehash(hashtable_t *hashtable) {
hashtable->order = new_order;
for (i = 0; i < hashsize(hashtable->order); i++) {
hashtable->buckets[i].first = hashtable->buckets[i].last =
&hashtable->list;
hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
list = hashtable->list.next;
@@ -178,8 +174,7 @@ int hashtable_init(hashtable_t *hashtable) {
hashtable->size = 0;
hashtable->order = INITIAL_HASHTABLE_ORDER;
hashtable->buckets =
jsonp_malloc(hashsize(hashtable->order) * sizeof(bucket_t));
hashtable->buckets = jsonp_malloc(hashsize(hashtable->order) * sizeof(bucket_t));
if (!hashtable->buckets)
return -1;
@@ -187,8 +182,7 @@ int hashtable_init(hashtable_t *hashtable) {
list_init(&hashtable->ordered_list);
for (i = 0; i < hashsize(hashtable->order); i++) {
hashtable->buckets[i].first = hashtable->buckets[i].last =
&hashtable->list;
hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
return 0;
@@ -272,8 +266,7 @@ void hashtable_clear(hashtable_t *hashtable) {
hashtable_do_clear(hashtable);
for (i = 0; i < hashsize(hashtable->order); i++) {
hashtable->buckets[i].first = hashtable->buckets[i].last =
&hashtable->list;
hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
list_init(&hashtable->list);

View File

@@ -40,7 +40,7 @@ typedef struct hashtable {
struct hashtable_list ordered_list;
} hashtable_t;
#define hashtable_key_to_iter(key_) \
#define hashtable_key_to_iter(key_) \
(&(container_of(key_, struct hashtable_pair, key)->ordered_list))
/**

View File

@@ -94,12 +94,10 @@ static int seed_from_urandom(uint32_t *seed) {
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
#include <wincrypt.h>
typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,
LPCSTR pszContainer,
typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContainer,
LPCSTR pszProvider, DWORD dwProvType,
DWORD dwFlags);
typedef BOOL(WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen,
BYTE *pbBuffer);
typedef BOOL(WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
typedef BOOL(WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV hProv, DWORD dwFlags);
static int seed_from_windows_cryptoapi(uint32_t *seed) {
@@ -120,8 +118,7 @@ static int seed_from_windows_cryptoapi(uint32_t *seed) {
if (!pCryptAcquireContext)
return 1;
pCryptGenRandom =
(CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, "CryptGenRandom");
pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, "CryptGenRandom");
if (!pCryptGenRandom)
return 1;
@@ -196,8 +193,7 @@ static uint32_t generate_seed() {
volatile uint32_t hashtable_seed = 0;
#if defined(HAVE_ATOMIC_BUILTINS) && \
(defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
#if defined(HAVE_ATOMIC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
static volatile char seed_initialized = 0;
void json_object_seed(size_t seed) {
@@ -220,8 +216,7 @@ void json_object_seed(size_t seed) {
}
}
}
#elif defined(HAVE_SYNC_BUILTINS) && \
(defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
#elif defined(HAVE_SYNC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
void json_object_seed(size_t seed) {
uint32_t new_seed = (uint32_t)seed;

View File

@@ -29,8 +29,8 @@ extern "C" {
/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this
for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */
#define JANSSON_VERSION_HEX \
((JANSSON_MAJOR_VERSION << 16) | (JANSSON_MINOR_VERSION << 8) | \
#define JANSSON_VERSION_HEX \
((JANSSON_MAJOR_VERSION << 16) | (JANSSON_MINOR_VERSION << 8) | \
(JANSSON_MICRO_VERSION << 0))
/* If __atomic or __sync builtins are available the library is thread
@@ -107,9 +107,9 @@ json_t *json_null(void);
/* do not call JSON_INTERNAL_INCREF or JSON_INTERNAL_DECREF directly */
#if JSON_HAVE_ATOMIC_BUILTINS
#define JSON_INTERNAL_INCREF(json) \
#define JSON_INTERNAL_INCREF(json) \
__atomic_add_fetch(&json->refcount, 1, __ATOMIC_ACQUIRE)
#define JSON_INTERNAL_DECREF(json) \
#define JSON_INTERNAL_DECREF(json) \
__atomic_sub_fetch(&json->refcount, 1, __ATOMIC_RELEASE)
#elif JSON_HAVE_SYNC_BUILTINS
#define JSON_INTERNAL_INCREF(json) __sync_add_and_fetch(&json->refcount, 1)
@@ -204,28 +204,25 @@ const char *json_object_iter_key(void *iter);
json_t *json_object_iter_value(void *iter);
int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
#define json_object_foreach(object, key, value) \
for (key = json_object_iter_key(json_object_iter(object)); \
key && \
(value = json_object_iter_value(json_object_key_to_iter(key))); \
key = json_object_iter_key( \
#define json_object_foreach(object, key, value) \
for (key = json_object_iter_key(json_object_iter(object)); \
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
key = json_object_iter_key( \
json_object_iter_next(object, json_object_key_to_iter(key))))
#define json_object_foreach_safe(object, n, key, value) \
for (key = json_object_iter_key(json_object_iter(object)), \
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
key && \
(value = json_object_iter_value(json_object_key_to_iter(key))); \
key = json_object_iter_key(n), \
#define json_object_foreach_safe(object, n, key, value) \
for (key = json_object_iter_key(json_object_iter(object)), \
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
key = json_object_iter_key(n), \
n = json_object_iter_next(object, json_object_key_to_iter(key)))
#define json_array_foreach(array, index, value) \
for (index = 0; index < json_array_size(array) && \
(value = json_array_get(array, index)); \
#define json_array_foreach(array, index, value) \
for (index = 0; \
index < json_array_size(array) && (value = json_array_get(array, index)); \
index++)
static JSON_INLINE int json_object_set(json_t *object, const char *key,
json_t *value) {
static JSON_INLINE int json_object_set(json_t *object, const char *key, json_t *value) {
return json_object_set_new(object, key, json_incref(value));
}
@@ -234,8 +231,7 @@ static JSON_INLINE int json_object_set_nocheck(json_t *object, const char *key,
return json_object_set_new_nocheck(object, key, json_incref(value));
}
static JSON_INLINE int json_object_iter_set(json_t *object, void *iter,
json_t *value) {
static JSON_INLINE int json_object_iter_set(json_t *object, void *iter, json_t *value) {
return json_object_iter_set_new(object, iter, json_incref(value));
}
@@ -267,8 +263,7 @@ int json_array_remove(json_t *array, size_t index);
int json_array_clear(json_t *array);
int json_array_extend(json_t *array, json_t *other);
static JSON_INLINE int json_array_set(json_t *array, size_t ind,
json_t *value) {
static JSON_INLINE int json_array_set(json_t *array, size_t ind, json_t *value) {
return json_array_set_new(array, ind, json_incref(value));
}
@@ -276,8 +271,7 @@ static JSON_INLINE int json_array_append(json_t *array, json_t *value) {
return json_array_append_new(array, json_incref(value));
}
static JSON_INLINE int json_array_insert(json_t *array, size_t ind,
json_t *value) {
static JSON_INLINE int json_array_insert(json_t *array, size_t ind, json_t *value) {
return json_array_insert_new(array, ind, json_incref(value));
}
@@ -299,17 +293,16 @@ int json_real_set(json_t *real, double value);
json_t *json_pack(const char *fmt, ...) JANSSON_ATTRS((warn_unused_result));
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...)
JANSSON_ATTRS((warn_unused_result));
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt,
va_list ap) JANSSON_ATTRS((warn_unused_result));
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap)
JANSSON_ATTRS((warn_unused_result));
#define JSON_VALIDATE_ONLY 0x1
#define JSON_STRICT 0x2
int json_unpack(json_t *root, const char *fmt, ...);
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags,
const char *fmt, ...);
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
const char *fmt, va_list ap);
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...);
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
va_list ap);
/* sprintf */
@@ -339,17 +332,16 @@ typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
json_t *json_loads(const char *input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags,
json_error_t *error) JANSSON_ATTRS((warn_unused_result));
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_loadfd(int input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_load_callback(json_load_callback_t callback, void *data,
size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags,
json_error_t *error) JANSSON_ATTRS((warn_unused_result));
/* encoding */
@@ -364,17 +356,15 @@ json_t *json_load_callback(json_load_callback_t callback, void *data,
#define JSON_REAL_PRECISION(n) (((n)&0x1F) << 11)
#define JSON_EMBED 0x10000
typedef int (*json_dump_callback_t)(const char *buffer, size_t size,
void *data);
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
char *json_dumps(const json_t *json, size_t flags)
JANSSON_ATTRS((warn_unused_result));
char *json_dumps(const json_t *json, size_t flags) JANSSON_ATTRS((warn_unused_result));
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
int json_dumpf(const json_t *json, FILE *output, size_t flags);
int json_dumpfd(const json_t *json, int output, size_t flags);
int json_dump_file(const json_t *json, const char *path, size_t flags);
int json_dump_callback(const json_t *json, json_dump_callback_t callback,
void *data, size_t flags);
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data,
size_t flags);
/* custom memory allocation */

View File

@@ -14,7 +14,7 @@
#include "strbuffer.h"
#include <stddef.h>
#define container_of(ptr_, type_, member_) \
#define container_of(ptr_, type_, member_) \
((type_ *)((char *)ptr_ - offsetof(type_, member_)))
/* On some platforms, max() may already be defined */
@@ -74,9 +74,8 @@ void jsonp_error_init(json_error_t *error, const char *source);
void jsonp_error_set_source(json_error_t *error, const char *source);
void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
enum json_error_code code, const char *msg, ...);
void jsonp_error_vset(json_error_t *error, int line, int column,
size_t position, enum json_error_code code,
const char *msg, va_list ap);
void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
enum json_error_code code, const char *msg, va_list ap);
/* Locale independent string<->double conversions */
int jsonp_strtod(strbuffer_t *strbuffer, double *out);
@@ -85,11 +84,9 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
/* Wrappers for custom memory functions */
void *jsonp_malloc(size_t size) JANSSON_ATTRS((warn_unused_result));
void jsonp_free(void *ptr);
char *jsonp_strndup(const char *str, size_t length)
JANSSON_ATTRS((warn_unused_result));
char *jsonp_strndup(const char *str, size_t length) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strdup(const char *str) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strndup(const char *str, size_t len)
JANSSON_ATTRS((warn_unused_result));
char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS((warn_unused_result));
/* Circular reference check*/
/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
@@ -100,11 +97,11 @@ int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key,
/* Windows compatibility */
#if defined(_WIN32) || defined(WIN32)
#if defined(_MSC_VER) /* MS compiller */
#if (_MSC_VER < 1900) && \
#if (_MSC_VER < 1900) && \
!defined(snprintf) /* snprintf not defined yet & not introduced */
#define snprintf _snprintf
#endif
#if (_MSC_VER < 1500) && \
#if (_MSC_VER < 1500) && \
!defined(vsnprintf) /* vsnprintf not defined yet & not introduced */
#define vsnprintf(b, c, f, a) _vsnprintf(b, c, f, a)
#endif

View File

@@ -43,7 +43,7 @@
#define l_islower(c) ('a' <= (c) && (c) <= 'z')
#define l_isalpha(c) (l_isupper(c) || l_islower(c))
#define l_isdigit(c) ('0' <= (c) && (c) <= '9')
#define l_isxdigit(c) \
#define l_isxdigit(c) \
(l_isdigit(c) || ('A' <= (c) && (c) <= 'F') || ('a' <= (c) && (c) <= 'f'))
/* Read one byte from stream, convert to unsigned char, then int, and
@@ -82,8 +82,8 @@ typedef struct {
/*** error reporting ***/
static void error_set(json_error_t *error, const lex_t *lex,
enum json_error_code code, const char *msg, ...) {
static void error_set(json_error_t *error, const lex_t *lex, enum json_error_code code,
const char *msg, ...) {
va_list ap;
char msg_text[JSON_ERROR_TEXT_LENGTH];
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
@@ -109,8 +109,8 @@ static void error_set(json_error_t *error, const lex_t *lex,
if (saved_text && saved_text[0]) {
if (lex->saved_text.length <= 20) {
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
"%s near '%s'", msg_text, saved_text);
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'",
msg_text, saved_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}
@@ -123,8 +123,8 @@ static void error_set(json_error_t *error, const lex_t *lex,
/* No context for UTF-8 decoding errors */
result = msg_text;
} else {
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
"%s near end of file", msg_text);
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file",
msg_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}
@@ -227,9 +227,7 @@ static int lex_get(lex_t *lex, json_error_t *error) {
return stream_get(&lex->stream, error);
}
static void lex_save(lex_t *lex, int c) {
strbuffer_append_byte(&lex->saved_text, c);
}
static void lex_save(lex_t *lex, int c) { strbuffer_append_byte(&lex->saved_text, c); }
static int lex_get_save(lex_t *lex, json_error_t *error) {
int c = stream_get(&lex->stream, error);
@@ -320,11 +318,10 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
/* control character */
lex_unget_unsave(lex, c);
if (c == '\n')
error_set(error, lex, json_error_invalid_syntax,
"unexpected newline");
error_set(error, lex, json_error_invalid_syntax, "unexpected newline");
else
error_set(error, lex, json_error_invalid_syntax,
"control character 0x%x", c);
error_set(error, lex, json_error_invalid_syntax, "control character 0x%x",
c);
goto out;
}
@@ -340,12 +337,11 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
}
c = lex_get_save(lex, error);
}
} else if (c == '"' || c == '\\' || c == '/' || c == 'b' ||
c == 'f' || c == 'n' || c == 'r' || c == 't')
} else if (c == '"' || c == '\\' || c == '/' || c == 'b' || c == 'f' ||
c == 'n' || c == 'r' || c == 't')
c = lex_get_save(lex, error);
else {
error_set(error, lex, json_error_invalid_syntax,
"invalid escape");
error_set(error, lex, json_error_invalid_syntax, "invalid escape");
goto out;
}
} else
@@ -397,13 +393,12 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
if (0xDC00 <= value2 && value2 <= 0xDFFF) {
/* valid second surrogate */
value = ((value - 0xD800) << 10) +
(value2 - 0xDC00) + 0x10000;
value =
((value - 0xD800) << 10) + (value2 - 0xDC00) + 0x10000;
} else {
/* invalid second surrogate */
error_set(error, lex, json_error_invalid_syntax,
"invalid Unicode '\\u%04X\\u%04X'", value,
value2);
"invalid Unicode '\\u%04X\\u%04X'", value, value2);
goto out;
}
} else {
@@ -425,13 +420,26 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
switch (*p) {
case '"':
case '\\':
case '/': *t = *p; break;
case 'b': *t = '\b'; break;
case 'f': *t = '\f'; break;
case 'n': *t = '\n'; break;
case 'r': *t = '\r'; break;
case 't': *t = '\t'; break;
default: assert(0);
case '/':
*t = *p;
break;
case 'b':
*t = '\b';
break;
case 'f':
*t = '\f';
break;
case 'n':
*t = '\n';
break;
case 'r':
*t = '\r';
break;
case 't':
*t = '\t';
break;
default:
assert(0);
}
t++;
p++;
@@ -485,8 +493,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
goto out;
}
if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && c != '.' && c != 'E' &&
c != 'e') {
if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && c != '.' && c != 'E' && c != 'e') {
json_int_t intval;
lex_unget_unsave(lex, c);
@@ -500,8 +507,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
error_set(error, lex, json_error_numeric_overflow,
"too big negative integer");
else
error_set(error, lex, json_error_numeric_overflow,
"too big integer");
error_set(error, lex, json_error_numeric_overflow, "too big integer");
goto out;
}
@@ -543,8 +549,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
lex_unget_unsave(lex, c);
if (jsonp_strtod(&lex->saved_text, &doubleval)) {
error_set(error, lex, json_error_numeric_overflow,
"real number overflow");
error_set(error, lex, json_error_numeric_overflow, "real number overflow");
goto out;
}
@@ -669,8 +674,7 @@ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
json_t *value;
if (lex->token != TOKEN_STRING) {
error_set(error, lex, json_error_invalid_syntax,
"string or '}' expected");
error_set(error, lex, json_error_invalid_syntax, "string or '}' expected");
goto error;
}
@@ -687,8 +691,7 @@ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
if (flags & JSON_REJECT_DUPLICATES) {
if (json_object_get(object, key)) {
jsonp_free(key);
error_set(error, lex, json_error_duplicate_key,
"duplicate object key");
error_set(error, lex, json_error_duplicate_key, "duplicate object key");
goto error;
}
}
@@ -775,8 +778,7 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
lex->depth++;
if (lex->depth > JSON_PARSER_MAX_DEPTH) {
error_set(error, lex, json_error_stack_overflow,
"maximum parsing depth reached");
error_set(error, lex, json_error_stack_overflow, "maximum parsing depth reached");
return NULL;
}
@@ -809,23 +811,32 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
break;
}
case TOKEN_TRUE: json = json_true(); break;
case TOKEN_TRUE:
json = json_true();
break;
case TOKEN_FALSE: json = json_false(); break;
case TOKEN_FALSE:
json = json_false();
break;
case TOKEN_NULL: json = json_null(); break;
case TOKEN_NULL:
json = json_null();
break;
case '{': json = parse_object(lex, flags, error); break;
case '{':
json = parse_object(lex, flags, error);
break;
case '[': json = parse_array(lex, flags, error); break;
case '[':
json = parse_array(lex, flags, error);
break;
case TOKEN_INVALID:
error_set(error, lex, json_error_invalid_syntax, "invalid token");
return NULL;
default:
error_set(error, lex, json_error_invalid_syntax,
"unexpected token");
error_set(error, lex, json_error_invalid_syntax, "unexpected token");
return NULL;
}
@@ -844,8 +855,7 @@ static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error) {
lex_scan(lex, error);
if (!(flags & JSON_DECODE_ANY)) {
if (lex->token != '[' && lex->token != '{') {
error_set(error, lex, json_error_invalid_syntax,
"'[' or '{' expected");
error_set(error, lex, json_error_invalid_syntax, "'[' or '{' expected");
return NULL;
}
}
@@ -930,8 +940,7 @@ static int buffer_get(void *data) {
return (unsigned char)c;
}
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags,
json_error_t *error) {
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error) {
lex_t lex;
json_t *result;
buffer_data_t stream_data;
@@ -1032,8 +1041,8 @@ json_t *json_load_file(const char *path, size_t flags, json_error_t *error) {
fp = fopen(path, "rb");
if (!fp) {
error_set(error, NULL, json_error_cannot_open_file,
"unable to open %s: %s", path, strerror(errno));
error_set(error, NULL, json_error_cannot_open_file, "unable to open %s: %s", path,
strerror(errno));
return NULL;
}
@@ -1069,8 +1078,8 @@ static int callback_get(void *data) {
return (unsigned char)c;
}
json_t *json_load_callback(json_load_callback_t callback, void *arg,
size_t flags, json_error_t *error) {
json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags,
json_error_t *error) {
lex_t lex;
json_t *result;

View File

@@ -99,13 +99,13 @@ static void prev_token(scanner_t *s) {
s->token = s->prev_token;
}
static void set_error(scanner_t *s, const char *source,
enum json_error_code code, const char *fmt, ...) {
static void set_error(scanner_t *s, const char *source, enum json_error_code code,
const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos,
code, fmt, ap);
jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos, code, fmt,
ap);
jsonp_error_set_source(s->error, source);
@@ -116,8 +116,8 @@ static json_t *pack(scanner_t *s, va_list *ap);
/* ours will be set to 1 if jsonp_free() must be called for the result
afterwards */
static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
size_t *out_len, int *ours, int optional) {
static char *read_string(scanner_t *s, va_list *ap, const char *purpose, size_t *out_len,
int *ours, int optional) {
char t;
strbuffer_t strbuff;
const char *str;
@@ -134,8 +134,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
if (!str) {
if (!optional) {
set_error(s, "<args>", json_error_null_value, "NULL %s",
purpose);
set_error(s, "<args>", json_error_null_value, "NULL %s", purpose);
s->has_error = 1;
}
return NULL;
@@ -144,8 +143,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
length = strlen(str);
if (!utf8_check_string(str, length)) {
set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s",
purpose);
set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s", purpose);
s->has_error = 1;
return NULL;
}
@@ -183,10 +181,8 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
length = s->has_error ? 0 : strlen(str);
}
if (!s->has_error &&
strbuffer_append_bytes(&strbuff, str, length) == -1) {
set_error(s, "<internal>", json_error_out_of_memory,
"Out of memory");
if (!s->has_error && strbuffer_append_bytes(&strbuff, str, length) == -1) {
set_error(s, "<internal>", json_error_out_of_memory, "Out of memory");
s->has_error = 1;
}
@@ -203,8 +199,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
}
if (!utf8_check_string(strbuff.value, strbuff.length)) {
set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s",
purpose);
set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s", purpose);
strbuffer_close(&strbuff);
s->has_error = 1;
return NULL;
@@ -252,8 +247,7 @@ static json_t *pack_object(scanner_t *s, va_list *ap) {
jsonp_free(key);
if (valueOptional != '*') {
set_error(s, "<args>", json_error_null_value,
"NULL object value");
set_error(s, "<args>", json_error_null_value, "NULL object value");
s->has_error = 1;
}
@@ -378,9 +372,12 @@ static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref) {
return need_incref ? json_incref(json) : json;
switch (ntoken) {
case '?': return json_null();
case '*': return NULL;
default: break;
case '?':
return json_null();
case '*':
return NULL;
default:
break;
}
set_error(s, "<args>", json_error_null_value, "NULL object");
@@ -425,13 +422,17 @@ static json_t *pack_real(scanner_t *s, double value) {
static json_t *pack(scanner_t *s, va_list *ap) {
switch (token(s)) {
case '{': return pack_object(s, ap);
case '{':
return pack_object(s, ap);
case '[': return pack_array(s, ap);
case '[':
return pack_array(s, ap);
case 's': /* string */ return pack_string(s, ap);
case 's': /* string */
return pack_string(s, ap);
case 'n': /* null */ return json_null();
case 'n': /* null */
return json_null();
case 'b': /* boolean */
return va_arg(*ap, int) ? json_true() : json_false();
@@ -442,7 +443,8 @@ static json_t *pack(scanner_t *s, va_list *ap) {
case 'I': /* integer from json_int_t */
return pack_integer(s, va_arg(*ap, json_int_t));
case 'f': /* real */ return pack_real(s, va_arg(*ap, double));
case 'f': /* real */
return pack_real(s, va_arg(*ap, double));
case 'O': /* a json_t object; increments refcount */
return pack_object_inter(s, ap, 1);
@@ -478,8 +480,8 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
}
if (root && !json_is_object(root)) {
set_error(s, "<validation>", json_error_wrong_type,
"Expected object, got %s", type_name(root));
set_error(s, "<validation>", json_error_wrong_type, "Expected object, got %s",
type_name(root));
goto out;
}
next_token(s);
@@ -491,8 +493,8 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (strict != 0) {
set_error(s, "<format>", json_error_invalid_format,
"Expected '}' after '%c', got '%c'",
(strict == 1 ? '!' : '*'), token(s));
"Expected '}' after '%c', got '%c'", (strict == 1 ? '!' : '*'),
token(s));
goto out;
}
@@ -567,21 +569,19 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (keys_res == 1) {
keys_res = strbuffer_init(&unrecognized_keys);
} else if (!keys_res) {
keys_res =
strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
keys_res = strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
}
if (!keys_res)
keys_res = strbuffer_append_bytes(&unrecognized_keys,
key, strlen(key));
keys_res =
strbuffer_append_bytes(&unrecognized_keys, key, strlen(key));
}
}
}
if (unpacked) {
set_error(s, "<validation>", json_error_end_of_input_expected,
"%li object item(s) left unpacked: %s", unpacked,
keys_res ? "<unknown>"
: strbuffer_value(&unrecognized_keys));
keys_res ? "<unknown>" : strbuffer_value(&unrecognized_keys));
strbuffer_close(&unrecognized_keys);
goto out;
}
@@ -599,8 +599,8 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
int strict = 0;
if (root && !json_is_array(root)) {
set_error(s, "<validation>", json_error_wrong_type,
"Expected array, got %s", type_name(root));
set_error(s, "<validation>", json_error_wrong_type, "Expected array, got %s",
type_name(root));
return -1;
}
next_token(s);
@@ -610,8 +610,8 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
if (strict != 0) {
set_error(s, "<format>", json_error_invalid_format,
"Expected ']' after '%c', got '%c'",
(strict == 1 ? '!' : '*'), token(s));
"Expected ']' after '%c', got '%c'", (strict == 1 ? '!' : '*'),
token(s));
return -1;
}
@@ -667,9 +667,11 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
static int unpack(scanner_t *s, json_t *root, va_list *ap) {
switch (token(s)) {
case '{': return unpack_object(s, root, ap);
case '{':
return unpack_object(s, root, ap);
case '[': return unpack_array(s, root, ap);
case '[':
return unpack_array(s, root, ap);
case 's':
if (root && !json_is_string(root)) {
@@ -684,8 +686,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap) {
str_target = va_arg(*ap, const char **);
if (!str_target) {
set_error(s, "<args>", json_error_null_value,
"NULL string argument");
set_error(s, "<args>", json_error_null_value, "NULL string argument");
return -1;
}
@@ -814,8 +815,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap) {
}
}
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt,
va_list ap) {
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap) {
scanner_t s;
va_list ap_copy;
json_t *value;
@@ -872,15 +872,14 @@ json_t *json_pack(const char *fmt, ...) {
return value;
}
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
const char *fmt, va_list ap) {
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
va_list ap) {
scanner_t s;
va_list ap_copy;
if (!root) {
jsonp_error_init(error, "<root>");
jsonp_error_set(error, -1, -1, 0, json_error_null_value,
"NULL root value");
jsonp_error_set(error, -1, -1, 0, json_error_null_value, "NULL root value");
return -1;
}
@@ -912,8 +911,8 @@ int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
return 0;
}
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags,
const char *fmt, ...) {
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
...) {
int ret;
va_list ap;

View File

@@ -45,9 +45,7 @@ void strbuffer_clear(strbuffer_t *strbuff) {
strbuff->value[0] = '\0';
}
const char *strbuffer_value(const strbuffer_t *strbuff) {
return strbuff->value;
}
const char *strbuffer_value(const strbuffer_t *strbuff) { return strbuff->value; }
char *strbuffer_steal_value(strbuffer_t *strbuff) {
char *result = strbuff->value;
@@ -59,8 +57,7 @@ int strbuffer_append_byte(strbuffer_t *strbuff, char byte) {
return strbuffer_append_bytes(strbuff, &byte, 1);
}
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data,
size_t size) {
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) {
if (size >= strbuff->size - strbuff->length) {
size_t new_size;
char *new_value;
@@ -71,8 +68,7 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data,
strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
return -1;
new_size =
max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1);
new_size = max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1);
new_value = jsonp_malloc(new_size);
if (!new_value)

View File

@@ -1,10 +1,10 @@
#include "jansson_private.h"
#include "strbuffer.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "jansson_private.h"
#include "strbuffer.h"
/* need jansson_private_config.h to get the correct snprintf */
#ifdef HAVE_CONFIG_H

View File

@@ -113,8 +113,7 @@ size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint) {
return 1;
}
const char *utf8_iterate(const char *buffer, size_t bufsize,
int32_t *codepoint) {
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint) {
size_t count;
int32_t value;

View File

@@ -198,8 +198,7 @@ int json_object_update_missing(json_t *object, json_t *other) {
return 0;
}
int do_object_update_recursive(json_t *object, json_t *other,
hashtable_t *parents) {
int do_object_update_recursive(json_t *object, json_t *other, hashtable_t *parents) {
const char *key;
json_t *value;
char loop_key[LOOP_KEY_LEN];
@@ -332,14 +331,12 @@ static json_t *json_object_copy(json_t *object) {
if (!result)
return NULL;
json_object_foreach(object, key, value)
json_object_set_nocheck(result, key, value);
json_object_foreach(object, key, value) json_object_set_nocheck(result, key, value);
return result;
}
static json_t *json_object_deep_copy(const json_t *object,
hashtable_t *parents) {
static json_t *json_object_deep_copy(const json_t *object, hashtable_t *parents) {
json_t *result;
void *iter;
char loop_key[LOOP_KEY_LEN];
@@ -360,8 +357,7 @@ static json_t *json_object_deep_copy(const json_t *object,
key = json_object_iter_key(iter);
value = json_object_iter_value(iter);
if (json_object_set_new_nocheck(result, key,
do_deep_copy(value, parents))) {
if (json_object_set_new_nocheck(result, key, do_deep_copy(value, parents))) {
json_decref(result);
result = NULL;
break;
@@ -447,8 +443,7 @@ int json_array_set_new(json_t *json, size_t index, json_t *value) {
return 0;
}
static void array_move(json_array_t *array, size_t dest, size_t src,
size_t count) {
static void array_move(json_array_t *array, size_t dest, size_t src, size_t count) {
memmove(&array->table[dest], &array->table[src], count * sizeof(json_t *));
}
@@ -532,8 +527,7 @@ int json_array_insert_new(json_t *json, size_t index, json_t *value) {
if (old_table != array->table) {
array_copy(array->table, 0, old_table, 0, index);
array_copy(array->table, index + 1, old_table, index,
array->entries - index);
array_copy(array->table, index + 1, old_table, index, array->entries - index);
jsonp_free(old_table);
} else
array_move(array, index + 1, index, array->entries - index);
@@ -648,8 +642,8 @@ static json_t *json_array_deep_copy(const json_t *array, hashtable_t *parents) {
goto out;
for (i = 0; i < json_array_size(array); i++) {
if (json_array_append_new(
result, do_deep_copy(json_array_get(array, i), parents))) {
if (json_array_append_new(result,
do_deep_copy(json_array_get(array, i), parents))) {
json_decref(result);
result = NULL;
break;
@@ -785,8 +779,7 @@ static int json_string_equal(const json_t *string1, const json_t *string2) {
s1 = json_to_string(string1);
s2 = json_to_string(string2);
return s1->length == s2->length &&
!memcmp(s1->value, s2->value, s1->length);
return s1->length == s2->length && !memcmp(s1->value, s2->value, s1->length);
}
static json_t *json_string_copy(const json_t *string) {
@@ -865,9 +858,7 @@ int json_integer_set(json_t *json, json_int_t value) {
return 0;
}
static void json_delete_integer(json_integer_t *integer) {
jsonp_free(integer);
}
static void json_delete_integer(json_integer_t *integer) { jsonp_free(integer); }
static int json_integer_equal(const json_t *integer1, const json_t *integer2) {
return json_integer_value(integer1) == json_integer_value(integer2);
@@ -955,12 +946,23 @@ void json_delete(json_t *json) {
return;
switch (json_typeof(json)) {
case JSON_OBJECT: json_delete_object(json_to_object(json)); break;
case JSON_ARRAY: json_delete_array(json_to_array(json)); break;
case JSON_STRING: json_delete_string(json_to_string(json)); break;
case JSON_INTEGER: json_delete_integer(json_to_integer(json)); break;
case JSON_REAL: json_delete_real(json_to_real(json)); break;
default: return;
case JSON_OBJECT:
json_delete_object(json_to_object(json));
break;
case JSON_ARRAY:
json_delete_array(json_to_array(json));
break;
case JSON_STRING:
json_delete_string(json_to_string(json));
break;
case JSON_INTEGER:
json_delete_integer(json_to_integer(json));
break;
case JSON_REAL:
json_delete_real(json_to_real(json));
break;
default:
return;
}
/* json_delete is not called for true, false or null */
@@ -980,12 +982,18 @@ int json_equal(const json_t *json1, const json_t *json2) {
return 1;
switch (json_typeof(json1)) {
case JSON_OBJECT: return json_object_equal(json1, json2);
case JSON_ARRAY: return json_array_equal(json1, json2);
case JSON_STRING: return json_string_equal(json1, json2);
case JSON_INTEGER: return json_integer_equal(json1, json2);
case JSON_REAL: return json_real_equal(json1, json2);
default: return 0;
case JSON_OBJECT:
return json_object_equal(json1, json2);
case JSON_ARRAY:
return json_array_equal(json1, json2);
case JSON_STRING:
return json_string_equal(json1, json2);
case JSON_INTEGER:
return json_integer_equal(json1, json2);
case JSON_REAL:
return json_real_equal(json1, json2);
default:
return 0;
}
}
@@ -996,15 +1004,22 @@ json_t *json_copy(json_t *json) {
return NULL;
switch (json_typeof(json)) {
case JSON_OBJECT: return json_object_copy(json);
case JSON_ARRAY: return json_array_copy(json);
case JSON_STRING: return json_string_copy(json);
case JSON_INTEGER: return json_integer_copy(json);
case JSON_REAL: return json_real_copy(json);
case JSON_OBJECT:
return json_object_copy(json);
case JSON_ARRAY:
return json_array_copy(json);
case JSON_STRING:
return json_string_copy(json);
case JSON_INTEGER:
return json_integer_copy(json);
case JSON_REAL:
return json_real_copy(json);
case JSON_TRUE:
case JSON_FALSE:
case JSON_NULL: return json;
default: return NULL;
case JSON_NULL:
return json;
default:
return NULL;
}
}
@@ -1025,17 +1040,23 @@ json_t *do_deep_copy(const json_t *json, hashtable_t *parents) {
return NULL;
switch (json_typeof(json)) {
case JSON_OBJECT: return json_object_deep_copy(json, parents);
case JSON_OBJECT:
return json_object_deep_copy(json, parents);
case JSON_ARRAY:
return json_array_deep_copy(json, parents);
/* for the rest of the types, deep copying doesn't differ from
shallow copying */
case JSON_STRING: return json_string_copy(json);
case JSON_INTEGER: return json_integer_copy(json);
case JSON_REAL: return json_real_copy(json);
case JSON_STRING:
return json_string_copy(json);
case JSON_INTEGER:
return json_integer_copy(json);
case JSON_REAL:
return json_real_copy(json);
case JSON_TRUE:
case JSON_FALSE:
case JSON_NULL: return (json_t *)json;
default: return NULL;
case JSON_NULL:
return (json_t *)json;
default:
return NULL;
}
}