@@ -68,19 +68,17 @@ static int dump_to_fd(const char *buffer, size_t size, void *data) {
68
68
/* 32 spaces (the maximum indentation size) */
69
69
static const char whitespace [] = " " ;
70
70
71
- static int dump_indent (size_t flags , int depth , int space ,
72
- json_dump_callback_t dump , void * data ) {
71
+ static int dump_indent (size_t flags , int depth , int space , json_dump_callback_t dump ,
72
+ void * data ) {
73
73
if (FLAGS_TO_INDENT (flags ) > 0 ) {
74
- unsigned int ws_count = FLAGS_TO_INDENT (flags ),
75
- n_spaces = depth * ws_count ;
74
+ unsigned int ws_count = FLAGS_TO_INDENT (flags ), n_spaces = depth * ws_count ;
76
75
77
76
if (dump ("\n" , 1 , data ))
78
77
return -1 ;
79
78
80
79
while (n_spaces > 0 ) {
81
- int cur_n = n_spaces < sizeof whitespace - 1
82
- ? n_spaces
83
- : sizeof whitespace - 1 ;
80
+ int cur_n =
81
+ n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1 ;
84
82
85
83
if (dump (whitespace , cur_n , data ))
86
84
return -1 ;
@@ -93,8 +91,8 @@ static int dump_indent(size_t flags, int depth, int space,
93
91
return 0 ;
94
92
}
95
93
96
- static int dump_string (const char * str , size_t len , json_dump_callback_t dump ,
97
- void * data , size_t flags ) {
94
+ static int dump_string (const char * str , size_t len , json_dump_callback_t dump , void * data ,
95
+ size_t flags ) {
98
96
const char * pos , * end , * lim ;
99
97
int32_t codepoint = 0 ;
100
98
@@ -139,19 +137,34 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
139
137
/* handle \, /, ", and control codes */
140
138
length = 2 ;
141
139
switch (codepoint ) {
142
- case '\\' : text = "\\\\" ; break ;
143
- case '\"' : text = "\\\"" ; break ;
144
- case '\b' : text = "\\b" ; break ;
145
- case '\f' : text = "\\f" ; break ;
146
- case '\n' : text = "\\n" ; break ;
147
- case '\r' : text = "\\r" ; break ;
148
- case '\t' : text = "\\t" ; break ;
149
- case '/' : text = "\\/" ; break ;
140
+ case '\\' :
141
+ text = "\\\\" ;
142
+ break ;
143
+ case '\"' :
144
+ text = "\\\"" ;
145
+ break ;
146
+ case '\b' :
147
+ text = "\\b" ;
148
+ break ;
149
+ case '\f' :
150
+ text = "\\f" ;
151
+ break ;
152
+ case '\n' :
153
+ text = "\\n" ;
154
+ break ;
155
+ case '\r' :
156
+ text = "\\r" ;
157
+ break ;
158
+ case '\t' :
159
+ text = "\\t" ;
160
+ break ;
161
+ case '/' :
162
+ text = "\\/" ;
163
+ break ;
150
164
default : {
151
165
/* codepoint is in BMP */
152
166
if (codepoint < 0x10000 ) {
153
- snprintf (seq , sizeof (seq ), "\\u%04X" ,
154
- (unsigned int )codepoint );
167
+ snprintf (seq , sizeof (seq ), "\\u%04X" , (unsigned int )codepoint );
155
168
length = 6 ;
156
169
}
157
170
@@ -163,8 +176,8 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
163
176
first = 0xD800 | ((codepoint & 0xffc00 ) >> 10 );
164
177
last = 0xDC00 | (codepoint & 0x003ff );
165
178
166
- snprintf (seq , sizeof (seq ), "\\u%04X\\u%04X" ,
167
- (unsigned int )first , ( unsigned int ) last );
179
+ snprintf (seq , sizeof (seq ), "\\u%04X\\u%04X" , ( unsigned int ) first ,
180
+ (unsigned int )last );
168
181
length = 12 ;
169
182
}
170
183
@@ -186,9 +199,8 @@ static int compare_keys(const void *key1, const void *key2) {
186
199
return strcmp (* (const char * * )key1 , * (const char * * )key2 );
187
200
}
188
201
189
- static int do_dump (const json_t * json , size_t flags , int depth ,
190
- hashtable_t * parents , json_dump_callback_t dump ,
191
- void * data ) {
202
+ static int do_dump (const json_t * json , size_t flags , int depth , hashtable_t * parents ,
203
+ json_dump_callback_t dump , void * data ) {
192
204
int embed = flags & JSON_EMBED ;
193
205
194
206
flags &= ~JSON_EMBED ;
@@ -197,18 +209,21 @@ static int do_dump(const json_t *json, size_t flags, int depth,
197
209
return -1 ;
198
210
199
211
switch (json_typeof (json )) {
200
- case JSON_NULL : return dump ("null" , 4 , data );
212
+ case JSON_NULL :
213
+ return dump ("null" , 4 , data );
201
214
202
- case JSON_TRUE : return dump ("true" , 4 , data );
215
+ case JSON_TRUE :
216
+ return dump ("true" , 4 , data );
203
217
204
- case JSON_FALSE : return dump ("false" , 5 , data );
218
+ case JSON_FALSE :
219
+ return dump ("false" , 5 , data );
205
220
206
221
case JSON_INTEGER : {
207
222
char buffer [MAX_INTEGER_STR_LENGTH ];
208
223
int size ;
209
224
210
- size = snprintf (buffer , MAX_INTEGER_STR_LENGTH ,
211
- "%" JSON_INTEGER_FORMAT , json_integer_value (json ));
225
+ size = snprintf (buffer , MAX_INTEGER_STR_LENGTH , "%" JSON_INTEGER_FORMAT ,
226
+ json_integer_value (json ));
212
227
if (size < 0 || size >= MAX_INTEGER_STR_LENGTH )
213
228
return -1 ;
214
229
@@ -229,8 +244,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
229
244
}
230
245
231
246
case JSON_STRING :
232
- return dump_string (json_string_value (json ),
233
- json_string_length ( json ), dump , data , flags );
247
+ return dump_string (json_string_value (json ), json_string_length ( json ), dump ,
248
+ data , flags );
234
249
235
250
case JSON_ARRAY : {
236
251
size_t n ;
@@ -255,8 +270,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
255
270
return -1 ;
256
271
257
272
for (i = 0 ; i < n ; ++ i ) {
258
- if (do_dump (json_array_get (json , i ), flags , depth + 1 , parents ,
259
- dump , data ))
273
+ if (do_dump (json_array_get (json , i ), flags , depth + 1 , parents , dump ,
274
+ data ))
260
275
return -1 ;
261
276
262
277
if (i < n - 1 ) {
@@ -360,8 +375,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
360
375
361
376
dump_string (key , strlen (key ), dump , data , flags );
362
377
if (dump (separator , separator_length , data ) ||
363
- do_dump (json_object_iter_value (iter ), flags , depth + 1 ,
364
- parents , dump , data ))
378
+ do_dump (json_object_iter_value (iter ), flags , depth + 1 , parents ,
379
+ dump , data ))
365
380
return -1 ;
366
381
367
382
if (next ) {
@@ -435,8 +450,8 @@ int json_dump_file(const json_t *json, const char *path, size_t flags) {
435
450
return result ;
436
451
}
437
452
438
- int json_dump_callback (const json_t * json , json_dump_callback_t callback ,
439
- void * data , size_t flags ) {
453
+ int json_dump_callback (const json_t * json , json_dump_callback_t callback , void * data ,
454
+ size_t flags ) {
440
455
int res ;
441
456
hashtable_t parents_set ;
442
457
0 commit comments