2 * $Id: json_tokener.c,v 1.20 2006/07/25 03:24:50 mclark Exp $
4 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5 * Michael Clark <michael@metaparadigm.com>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the MIT license. See COPYING for details.
11 * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
12 * The copyrights to the contents of this file are licensed under the MIT License
13 * (http://www.opensource.org/licenses/mit-license.php)
29 #include "arraylist.h"
30 #include "json_inttypes.h"
31 #include "json_object.h"
32 #include "json_tokener.h"
33 #include "json_util.h"
37 #endif /* HAVE_LOCALE_H */
39 #if !HAVE_STRDUP && defined(_MSC_VER)
40 /* MSC has the version as _strdup */
41 # define strdup _strdup
43 # error You do not have strdup on your system.
44 #endif /* HAVE_STRDUP */
46 #if !HAVE_STRNCASECMP && defined(_MSC_VER)
47 /* MSC has the version as _strnicmp */
48 # define strncasecmp _strnicmp
49 #elif !HAVE_STRNCASECMP
50 # error You do not have strncasecmp on your system.
51 #endif /* HAVE_STRNCASECMP */
53 /* Use C99 NAN by default; if not available, nan("") should work too. */
58 static const char json_null_str[] = "null";
59 static const int json_null_str_len = sizeof(json_null_str) - 1;
60 static const char json_inf_str[] = "Infinity";
61 static const int json_inf_str_len = sizeof(json_inf_str) - 1;
62 static const char json_nan_str[] = "NaN";
63 static const int json_nan_str_len = sizeof(json_nan_str) - 1;
64 static const char json_true_str[] = "true";
65 static const int json_true_str_len = sizeof(json_true_str) - 1;
66 static const char json_false_str[] = "false";
67 static const int json_false_str_len = sizeof(json_false_str) - 1;
69 static const char* json_tokener_errors[] = {
73 "unexpected end of data",
74 "unexpected character",
78 "array value separator ',' expected",
79 "quoted object property name expected",
80 "object property name separator ':' expected",
81 "object value separator ',' expected",
82 "invalid string sequence",
84 "buffer size overflow"
87 const char *json_tokener_error_desc(enum json_tokener_error jerr)
89 int jerr_int = (int)jerr;
90 if (jerr_int < 0 || jerr_int >= (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
91 return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
92 return json_tokener_errors[jerr];
95 enum json_tokener_error json_tokener_get_error(json_tokener *tok)
100 /* Stuff for decoding unicode sequences */
101 #define IS_HIGH_SURROGATE(uc) (((uc) & 0xFC00) == 0xD800)
102 #define IS_LOW_SURROGATE(uc) (((uc) & 0xFC00) == 0xDC00)
103 #define DECODE_SURROGATE_PAIR(hi,lo) ((((hi) & 0x3FF) << 10) + ((lo) & 0x3FF) + 0x10000)
104 static unsigned char utf8_replacement_char[3] = { 0xEF, 0xBF, 0xBD };
106 struct json_tokener* json_tokener_new_ex(int depth)
108 struct json_tokener *tok;
110 tok = (struct json_tokener*)calloc(1, sizeof(struct json_tokener));
111 if (!tok) return NULL;
112 tok->stack = (struct json_tokener_srec *)calloc(depth, sizeof(struct json_tokener_srec));
117 tok->pb = printbuf_new();
118 tok->max_depth = depth;
119 json_tokener_reset(tok);
123 struct json_tokener* json_tokener_new(void)
125 return json_tokener_new_ex(JSON_TOKENER_DEFAULT_DEPTH);
128 void json_tokener_free(struct json_tokener *tok)
130 json_tokener_reset(tok);
131 if (tok->pb) printbuf_free(tok->pb);
132 if (tok->stack) free(tok->stack);
136 static void json_tokener_reset_level(struct json_tokener *tok, int depth)
138 tok->stack[depth].state = json_tokener_state_eatws;
139 tok->stack[depth].saved_state = json_tokener_state_start;
140 json_object_put(tok->stack[depth].current);
141 tok->stack[depth].current = NULL;
142 free(tok->stack[depth].obj_field_name);
143 tok->stack[depth].obj_field_name = NULL;
146 void json_tokener_reset(struct json_tokener *tok)
152 for(i = tok->depth; i >= 0; i--)
153 json_tokener_reset_level(tok, i);
155 tok->err = json_tokener_success;
158 struct json_object* json_tokener_parse(const char *str)
160 enum json_tokener_error jerr_ignored;
161 struct json_object* obj;
162 obj = json_tokener_parse_verbose(str, &jerr_ignored);
166 struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error)
168 struct json_tokener* tok;
169 struct json_object* obj;
171 tok = json_tokener_new();
174 obj = json_tokener_parse_ex(tok, str, -1);
176 if(tok->err != json_tokener_success) {
178 json_object_put(obj);
182 json_tokener_free(tok);
186 #define state tok->stack[tok->depth].state
187 #define saved_state tok->stack[tok->depth].saved_state
188 #define current tok->stack[tok->depth].current
189 #define obj_field_name tok->stack[tok->depth].obj_field_name
192 * json_tokener_parse_ex() consumed a lot of CPU in its main loop,
193 * iterating character-by character. A large performance boost is
194 * achieved by using tighter loops to locally handle units such as
195 * comments and strings. Loops that handle an entire token within
196 * their scope also gather entire strings and pass them to
197 * printbuf_memappend() in a single call, rather than calling
198 * printbuf_memappend() one char at a time.
200 * PEEK_CHAR() and ADVANCE_CHAR() macros are used for code that is
201 * common to both the main loop and the tighter loops.
204 /* PEEK_CHAR(dest, tok) macro:
205 * Peeks at the current char and stores it in dest.
206 * Returns 1 on success, sets tok->err and returns 0 if no more chars.
207 * Implicit inputs: str, len vars
209 #define PEEK_CHAR(dest, tok) \
210 (((tok)->char_offset == len) ? \
211 (((tok)->depth == 0 && state == json_tokener_state_eatws && saved_state == json_tokener_state_finish) ? \
212 (((tok)->err = json_tokener_success), 0) \
214 (((tok)->err = json_tokener_continue), 0) \
216 (((dest) = *str), 1) \
219 /* ADVANCE_CHAR() macro:
220 * Incrementes str & tok->char_offset.
221 * For convenience of existing conditionals, returns the old value of c (0 on eof)
222 * Implicit inputs: c var
224 #define ADVANCE_CHAR(str, tok) \
225 ( ++(str), ((tok)->char_offset)++, c)
228 /* End optimization macro defs */
231 struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
232 const char *str, int len)
234 struct json_object *obj = NULL;
236 #ifdef HAVE_SETLOCALE
237 char *oldlocale=NULL, *tmplocale;
239 tmplocale = setlocale(LC_NUMERIC, NULL);
240 if (tmplocale) oldlocale = strdup(tmplocale);
241 setlocale(LC_NUMERIC, "C");
244 tok->char_offset = 0;
245 tok->err = json_tokener_success;
247 /* this interface is presently not 64-bit clean due to the int len argument
248 and the internal printbuf interface that takes 32-bit int len arguments
249 so the function limits the maximum string size to INT32_MAX (2GB).
250 If the function is called with len == -1 then strlen is called to check
251 the string length is less than INT32_MAX (2GB) */
252 if ((len < -1) || (len == -1 && strlen(str) > INT32_MAX)) {
253 tok->err = json_tokener_error_size;
257 while (PEEK_CHAR(c, tok)) {
262 case json_tokener_state_eatws:
263 /* Advance until we change state */
264 while (isspace((int)c)) {
265 if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok)))
268 if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) {
269 printbuf_reset(tok->pb);
270 printbuf_memappend_fast(tok->pb, &c, 1);
271 state = json_tokener_state_comment_start;
278 case json_tokener_state_start:
281 state = json_tokener_state_eatws;
282 saved_state = json_tokener_state_object_field_start;
283 current = json_object_new_object();
286 state = json_tokener_state_eatws;
287 saved_state = json_tokener_state_array;
288 current = json_object_new_array();
292 state = json_tokener_state_inf;
293 printbuf_reset(tok->pb);
298 state = json_tokener_state_null; // or NaN
299 printbuf_reset(tok->pb);
303 if (tok->flags & JSON_TOKENER_STRICT) {
304 /* in STRICT mode only double-quote are allowed */
305 tok->err = json_tokener_error_parse_unexpected;
309 state = json_tokener_state_string;
310 printbuf_reset(tok->pb);
317 state = json_tokener_state_boolean;
318 printbuf_reset(tok->pb);
321 #if defined(__GNUC__)
336 state = json_tokener_state_number;
337 printbuf_reset(tok->pb);
341 tok->err = json_tokener_error_parse_unexpected;
346 case json_tokener_state_finish:
347 if(tok->depth == 0) goto out;
348 obj = json_object_get(current);
349 json_tokener_reset_level(tok, tok->depth);
353 case json_tokener_state_inf: /* aka starts with 'i' */
358 printbuf_memappend_fast(tok->pb, &c, 1);
359 size_inf = json_min(tok->st_pos+1, json_inf_str_len);
360 char *infbuf = tok->pb->buf;
366 if ((!(tok->flags & JSON_TOKENER_STRICT) &&
367 strncasecmp(json_inf_str, infbuf, size_inf) == 0) ||
368 (strncmp(json_inf_str, infbuf, size_inf) == 0)
371 if (tok->st_pos == json_inf_str_len)
373 current = json_object_new_double(is_negative ? -INFINITY : INFINITY);
374 saved_state = json_tokener_state_finish;
375 state = json_tokener_state_eatws;
379 tok->err = json_tokener_error_parse_unexpected;
385 case json_tokener_state_null: /* aka starts with 'n' */
389 printbuf_memappend_fast(tok->pb, &c, 1);
390 size = json_min(tok->st_pos+1, json_null_str_len);
391 size_nan = json_min(tok->st_pos+1, json_nan_str_len);
392 if((!(tok->flags & JSON_TOKENER_STRICT) &&
393 strncasecmp(json_null_str, tok->pb->buf, size) == 0)
394 || (strncmp(json_null_str, tok->pb->buf, size) == 0)
396 if (tok->st_pos == json_null_str_len) {
398 saved_state = json_tokener_state_finish;
399 state = json_tokener_state_eatws;
403 else if ((!(tok->flags & JSON_TOKENER_STRICT) &&
404 strncasecmp(json_nan_str, tok->pb->buf, size_nan) == 0) ||
405 (strncmp(json_nan_str, tok->pb->buf, size_nan) == 0)
408 if (tok->st_pos == json_nan_str_len)
410 current = json_object_new_double(NAN);
411 saved_state = json_tokener_state_finish;
412 state = json_tokener_state_eatws;
416 tok->err = json_tokener_error_parse_null;
423 case json_tokener_state_comment_start:
425 state = json_tokener_state_comment;
426 } else if(c == '/') {
427 state = json_tokener_state_comment_eol;
429 tok->err = json_tokener_error_parse_comment;
432 printbuf_memappend_fast(tok->pb, &c, 1);
435 case json_tokener_state_comment:
437 /* Advance until we change state */
438 const char *case_start = str;
440 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
441 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
445 printbuf_memappend_fast(tok->pb, case_start, 1+str-case_start);
446 state = json_tokener_state_comment_end;
450 case json_tokener_state_comment_eol:
452 /* Advance until we change state */
453 const char *case_start = str;
455 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
456 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
460 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
461 MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf);
462 state = json_tokener_state_eatws;
466 case json_tokener_state_comment_end:
467 printbuf_memappend_fast(tok->pb, &c, 1);
469 MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf);
470 state = json_tokener_state_eatws;
472 state = json_tokener_state_comment;
476 case json_tokener_state_string:
478 /* Advance until we change state */
479 const char *case_start = str;
481 if(c == tok->quote_char) {
482 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
483 current = json_object_new_string_len(tok->pb->buf, tok->pb->bpos);
484 saved_state = json_tokener_state_finish;
485 state = json_tokener_state_eatws;
487 } else if(c == '\\') {
488 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
489 saved_state = json_tokener_state_string;
490 state = json_tokener_state_string_escape;
493 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
494 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
501 case json_tokener_state_string_escape:
506 printbuf_memappend_fast(tok->pb, &c, 1);
514 if(c == 'b') printbuf_memappend_fast(tok->pb, "\b", 1);
515 else if(c == 'n') printbuf_memappend_fast(tok->pb, "\n", 1);
516 else if(c == 'r') printbuf_memappend_fast(tok->pb, "\r", 1);
517 else if(c == 't') printbuf_memappend_fast(tok->pb, "\t", 1);
518 else if(c == 'f') printbuf_memappend_fast(tok->pb, "\f", 1);
524 state = json_tokener_state_escape_unicode;
527 tok->err = json_tokener_error_parse_string;
532 case json_tokener_state_escape_unicode:
534 unsigned int got_hi_surrogate = 0;
536 /* Handle a 4-byte sequence, or two sequences if a surrogate pair */
538 if(strchr(json_hex_chars, c)) {
539 tok->ucs_char += ((unsigned int)hexdigit(c) << ((3-tok->st_pos++)*4));
540 if(tok->st_pos == 4) {
541 unsigned char unescaped_utf[4];
543 if (got_hi_surrogate) {
544 if (IS_LOW_SURROGATE(tok->ucs_char)) {
545 /* Recalculate the ucs_char, then fall thru to process normally */
546 tok->ucs_char = DECODE_SURROGATE_PAIR(got_hi_surrogate, tok->ucs_char);
548 /* Hi surrogate was not followed by a low surrogate */
549 /* Replace the hi and process the rest normally */
550 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
552 got_hi_surrogate = 0;
555 if (tok->ucs_char < 0x80) {
556 unescaped_utf[0] = tok->ucs_char;
557 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 1);
558 } else if (tok->ucs_char < 0x800) {
559 unescaped_utf[0] = 0xc0 | (tok->ucs_char >> 6);
560 unescaped_utf[1] = 0x80 | (tok->ucs_char & 0x3f);
561 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 2);
562 } else if (IS_HIGH_SURROGATE(tok->ucs_char)) {
563 /* Got a high surrogate. Remember it and look for the
564 * the beginning of another sequence, which should be the
567 got_hi_surrogate = tok->ucs_char;
568 /* Not at end, and the next two chars should be "\u" */
569 if ((tok->char_offset+1 != len) &&
570 (tok->char_offset+2 != len) &&
574 /* Advance through the 16 bit surrogate, and move on to the
575 * next sequence. The next step is to process the following
578 if( !ADVANCE_CHAR(str, tok) || !ADVANCE_CHAR(str, tok) ) {
579 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
581 /* Advance to the first char of the next sequence and
582 * continue processing with the next sequence.
584 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
585 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
590 continue; /* other json_tokener_state_escape_unicode */
592 /* Got a high surrogate without another sequence following
593 * it. Put a replacement char in for the hi surrogate
594 * and pretend we finished.
596 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
598 } else if (IS_LOW_SURROGATE(tok->ucs_char)) {
599 /* Got a low surrogate not preceded by a high */
600 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
601 } else if (tok->ucs_char < 0x10000) {
602 unescaped_utf[0] = 0xe0 | (tok->ucs_char >> 12);
603 unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 6) & 0x3f);
604 unescaped_utf[2] = 0x80 | (tok->ucs_char & 0x3f);
605 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 3);
606 } else if (tok->ucs_char < 0x110000) {
607 unescaped_utf[0] = 0xf0 | ((tok->ucs_char >> 18) & 0x07);
608 unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 12) & 0x3f);
609 unescaped_utf[2] = 0x80 | ((tok->ucs_char >> 6) & 0x3f);
610 unescaped_utf[3] = 0x80 | (tok->ucs_char & 0x3f);
611 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 4);
613 /* Don't know what we got--insert the replacement char */
614 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
620 tok->err = json_tokener_error_parse_string;
623 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
624 if (got_hi_surrogate) /* Clean up any pending chars */
625 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
632 case json_tokener_state_boolean:
635 printbuf_memappend_fast(tok->pb, &c, 1);
636 size1 = json_min(tok->st_pos+1, json_true_str_len);
637 size2 = json_min(tok->st_pos+1, json_false_str_len);
638 if((!(tok->flags & JSON_TOKENER_STRICT) &&
639 strncasecmp(json_true_str, tok->pb->buf, size1) == 0)
640 || (strncmp(json_true_str, tok->pb->buf, size1) == 0)
642 if(tok->st_pos == json_true_str_len) {
643 current = json_object_new_boolean(1);
644 saved_state = json_tokener_state_finish;
645 state = json_tokener_state_eatws;
648 } else if((!(tok->flags & JSON_TOKENER_STRICT) &&
649 strncasecmp(json_false_str, tok->pb->buf, size2) == 0)
650 || (strncmp(json_false_str, tok->pb->buf, size2) == 0)) {
651 if(tok->st_pos == json_false_str_len) {
652 current = json_object_new_boolean(0);
653 saved_state = json_tokener_state_finish;
654 state = json_tokener_state_eatws;
658 tok->err = json_tokener_error_parse_boolean;
665 case json_tokener_state_number:
667 /* Advance until we change state */
668 const char *case_start = str;
670 while(c && strchr(json_number_chars, c)) {
672 if(c == '.' || c == 'e' || c == 'E')
674 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
675 printbuf_memappend_fast(tok->pb, case_start, case_len);
680 printbuf_memappend_fast(tok->pb, case_start, case_len);
682 // Check for -Infinity
683 if (tok->pb->buf[0] == '-' && case_len == 1 &&
684 (c == 'i' || c == 'I'))
686 state = json_tokener_state_inf;
693 if (!tok->is_double && json_parse_int64(tok->pb->buf, &num64) == 0) {
694 if (num64 && tok->pb->buf[0]=='0' && (tok->flags & JSON_TOKENER_STRICT)) {
695 /* in strict mode, number must not start with 0 */
696 tok->err = json_tokener_error_parse_number;
699 current = json_object_new_int64(num64);
701 else if(tok->is_double && json_parse_double(tok->pb->buf, &numd) == 0)
703 current = json_object_new_double_s(numd, tok->pb->buf);
705 tok->err = json_tokener_error_parse_number;
708 saved_state = json_tokener_state_finish;
709 state = json_tokener_state_eatws;
714 case json_tokener_state_array_after_sep:
715 case json_tokener_state_array:
717 if (state == json_tokener_state_array_after_sep &&
718 (tok->flags & JSON_TOKENER_STRICT))
720 tok->err = json_tokener_error_parse_unexpected;
723 saved_state = json_tokener_state_finish;
724 state = json_tokener_state_eatws;
726 if(tok->depth >= tok->max_depth-1) {
727 tok->err = json_tokener_error_depth;
730 state = json_tokener_state_array_add;
732 json_tokener_reset_level(tok, tok->depth);
737 case json_tokener_state_array_add:
738 json_object_array_add(current, obj);
739 saved_state = json_tokener_state_array_sep;
740 state = json_tokener_state_eatws;
743 case json_tokener_state_array_sep:
745 saved_state = json_tokener_state_finish;
746 state = json_tokener_state_eatws;
747 } else if(c == ',') {
748 saved_state = json_tokener_state_array_after_sep;
749 state = json_tokener_state_eatws;
751 tok->err = json_tokener_error_parse_array;
756 case json_tokener_state_object_field_start:
757 case json_tokener_state_object_field_start_after_sep:
759 if (state == json_tokener_state_object_field_start_after_sep &&
760 (tok->flags & JSON_TOKENER_STRICT))
762 tok->err = json_tokener_error_parse_unexpected;
765 saved_state = json_tokener_state_finish;
766 state = json_tokener_state_eatws;
767 } else if (c == '"' || c == '\'') {
769 printbuf_reset(tok->pb);
770 state = json_tokener_state_object_field;
772 tok->err = json_tokener_error_parse_object_key_name;
777 case json_tokener_state_object_field:
779 /* Advance until we change state */
780 const char *case_start = str;
782 if(c == tok->quote_char) {
783 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
784 obj_field_name = strdup(tok->pb->buf);
785 saved_state = json_tokener_state_object_field_end;
786 state = json_tokener_state_eatws;
788 } else if(c == '\\') {
789 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
790 saved_state = json_tokener_state_object_field;
791 state = json_tokener_state_string_escape;
794 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
795 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
802 case json_tokener_state_object_field_end:
804 saved_state = json_tokener_state_object_value;
805 state = json_tokener_state_eatws;
807 tok->err = json_tokener_error_parse_object_key_sep;
812 case json_tokener_state_object_value:
813 if(tok->depth >= tok->max_depth-1) {
814 tok->err = json_tokener_error_depth;
817 state = json_tokener_state_object_value_add;
819 json_tokener_reset_level(tok, tok->depth);
822 case json_tokener_state_object_value_add:
823 json_object_object_add(current, obj_field_name, obj);
824 free(obj_field_name);
825 obj_field_name = NULL;
826 saved_state = json_tokener_state_object_sep;
827 state = json_tokener_state_eatws;
830 case json_tokener_state_object_sep:
832 saved_state = json_tokener_state_finish;
833 state = json_tokener_state_eatws;
834 } else if(c == ',') {
835 saved_state = json_tokener_state_object_field_start_after_sep;
836 state = json_tokener_state_eatws;
838 tok->err = json_tokener_error_parse_object_value_sep;
844 if (!ADVANCE_CHAR(str, tok))
846 } /* while(POP_CHAR) */
850 (state == json_tokener_state_finish) &&
852 (tok->flags & JSON_TOKENER_STRICT)) {
853 /* unexpected char after JSON data */
854 tok->err = json_tokener_error_parse_unexpected;
856 if (!c) { /* We hit an eof char (0) */
857 if(state != json_tokener_state_finish &&
858 saved_state != json_tokener_state_finish)
859 tok->err = json_tokener_error_parse_eof;
862 #ifdef HAVE_SETLOCALE
863 setlocale(LC_NUMERIC, oldlocale);
864 if (oldlocale) free(oldlocale);
867 if (tok->err == json_tokener_success)
869 json_object *ret = json_object_get(current);
872 /* Partially reset, so we parse additional objects on subsequent calls. */
873 for(ii = tok->depth; ii >= 0; ii--)
874 json_tokener_reset_level(tok, ii);
878 MC_DEBUG("json_tokener_parse_ex: error %s at offset %d\n",
879 json_tokener_errors[tok->err], tok->char_offset);
883 void json_tokener_set_flags(struct json_tokener *tok, int flags)