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' */
359 printbuf_memappend_fast(tok->pb, &c, 1);
360 size = json_min(tok->st_pos+1, json_null_str_len);
361 size_inf = json_min(tok->st_pos+1, json_inf_str_len);
362 char *infbuf = tok->pb->buf;
368 if ((!(tok->flags & JSON_TOKENER_STRICT) &&
369 strncasecmp(json_inf_str, infbuf, size_inf) == 0) ||
370 (strncmp(json_inf_str, infbuf, size_inf) == 0)
373 if (tok->st_pos == json_inf_str_len)
375 current = json_object_new_double(is_negative ? -INFINITY : INFINITY);
376 saved_state = json_tokener_state_finish;
377 state = json_tokener_state_eatws;
381 tok->err = json_tokener_error_parse_unexpected;
387 case json_tokener_state_null: /* aka starts with 'n' */
391 printbuf_memappend_fast(tok->pb, &c, 1);
392 size = json_min(tok->st_pos+1, json_null_str_len);
393 size_nan = json_min(tok->st_pos+1, json_nan_str_len);
394 if((!(tok->flags & JSON_TOKENER_STRICT) &&
395 strncasecmp(json_null_str, tok->pb->buf, size) == 0)
396 || (strncmp(json_null_str, tok->pb->buf, size) == 0)
398 if (tok->st_pos == json_null_str_len) {
400 saved_state = json_tokener_state_finish;
401 state = json_tokener_state_eatws;
405 else if ((!(tok->flags & JSON_TOKENER_STRICT) &&
406 strncasecmp(json_nan_str, tok->pb->buf, size_nan) == 0) ||
407 (strncmp(json_nan_str, tok->pb->buf, size_nan) == 0)
410 if (tok->st_pos == json_nan_str_len)
412 current = json_object_new_double(NAN);
413 saved_state = json_tokener_state_finish;
414 state = json_tokener_state_eatws;
418 tok->err = json_tokener_error_parse_null;
425 case json_tokener_state_comment_start:
427 state = json_tokener_state_comment;
428 } else if(c == '/') {
429 state = json_tokener_state_comment_eol;
431 tok->err = json_tokener_error_parse_comment;
434 printbuf_memappend_fast(tok->pb, &c, 1);
437 case json_tokener_state_comment:
439 /* Advance until we change state */
440 const char *case_start = str;
442 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
443 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
447 printbuf_memappend_fast(tok->pb, case_start, 1+str-case_start);
448 state = json_tokener_state_comment_end;
452 case json_tokener_state_comment_eol:
454 /* Advance until we change state */
455 const char *case_start = str;
457 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
458 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
462 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
463 MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf);
464 state = json_tokener_state_eatws;
468 case json_tokener_state_comment_end:
469 printbuf_memappend_fast(tok->pb, &c, 1);
471 MC_DEBUG("json_tokener_comment: %s\n", tok->pb->buf);
472 state = json_tokener_state_eatws;
474 state = json_tokener_state_comment;
478 case json_tokener_state_string:
480 /* Advance until we change state */
481 const char *case_start = str;
483 if(c == tok->quote_char) {
484 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
485 current = json_object_new_string_len(tok->pb->buf, tok->pb->bpos);
486 saved_state = json_tokener_state_finish;
487 state = json_tokener_state_eatws;
489 } else if(c == '\\') {
490 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
491 saved_state = json_tokener_state_string;
492 state = json_tokener_state_string_escape;
495 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
496 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
503 case json_tokener_state_string_escape:
508 printbuf_memappend_fast(tok->pb, &c, 1);
516 if(c == 'b') printbuf_memappend_fast(tok->pb, "\b", 1);
517 else if(c == 'n') printbuf_memappend_fast(tok->pb, "\n", 1);
518 else if(c == 'r') printbuf_memappend_fast(tok->pb, "\r", 1);
519 else if(c == 't') printbuf_memappend_fast(tok->pb, "\t", 1);
520 else if(c == 'f') printbuf_memappend_fast(tok->pb, "\f", 1);
526 state = json_tokener_state_escape_unicode;
529 tok->err = json_tokener_error_parse_string;
534 case json_tokener_state_escape_unicode:
536 unsigned int got_hi_surrogate = 0;
538 /* Handle a 4-byte sequence, or two sequences if a surrogate pair */
540 if(strchr(json_hex_chars, c)) {
541 tok->ucs_char += ((unsigned int)hexdigit(c) << ((3-tok->st_pos++)*4));
542 if(tok->st_pos == 4) {
543 unsigned char unescaped_utf[4];
545 if (got_hi_surrogate) {
546 if (IS_LOW_SURROGATE(tok->ucs_char)) {
547 /* Recalculate the ucs_char, then fall thru to process normally */
548 tok->ucs_char = DECODE_SURROGATE_PAIR(got_hi_surrogate, tok->ucs_char);
550 /* Hi surrogate was not followed by a low surrogate */
551 /* Replace the hi and process the rest normally */
552 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
554 got_hi_surrogate = 0;
557 if (tok->ucs_char < 0x80) {
558 unescaped_utf[0] = tok->ucs_char;
559 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 1);
560 } else if (tok->ucs_char < 0x800) {
561 unescaped_utf[0] = 0xc0 | (tok->ucs_char >> 6);
562 unescaped_utf[1] = 0x80 | (tok->ucs_char & 0x3f);
563 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 2);
564 } else if (IS_HIGH_SURROGATE(tok->ucs_char)) {
565 /* Got a high surrogate. Remember it and look for the
566 * the beginning of another sequence, which should be the
569 got_hi_surrogate = tok->ucs_char;
570 /* Not at end, and the next two chars should be "\u" */
571 if ((tok->char_offset+1 != len) &&
572 (tok->char_offset+2 != len) &&
576 /* Advance through the 16 bit surrogate, and move on to the
577 * next sequence. The next step is to process the following
580 if( !ADVANCE_CHAR(str, tok) || !ADVANCE_CHAR(str, tok) ) {
581 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
583 /* Advance to the first char of the next sequence and
584 * continue processing with the next sequence.
586 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
587 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
592 continue; /* other json_tokener_state_escape_unicode */
594 /* Got a high surrogate without another sequence following
595 * it. Put a replacement char in for the hi surrogate
596 * and pretend we finished.
598 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
600 } else if (IS_LOW_SURROGATE(tok->ucs_char)) {
601 /* Got a low surrogate not preceded by a high */
602 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
603 } else if (tok->ucs_char < 0x10000) {
604 unescaped_utf[0] = 0xe0 | (tok->ucs_char >> 12);
605 unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 6) & 0x3f);
606 unescaped_utf[2] = 0x80 | (tok->ucs_char & 0x3f);
607 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 3);
608 } else if (tok->ucs_char < 0x110000) {
609 unescaped_utf[0] = 0xf0 | ((tok->ucs_char >> 18) & 0x07);
610 unescaped_utf[1] = 0x80 | ((tok->ucs_char >> 12) & 0x3f);
611 unescaped_utf[2] = 0x80 | ((tok->ucs_char >> 6) & 0x3f);
612 unescaped_utf[3] = 0x80 | (tok->ucs_char & 0x3f);
613 printbuf_memappend_fast(tok->pb, (char*)unescaped_utf, 4);
615 /* Don't know what we got--insert the replacement char */
616 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
622 tok->err = json_tokener_error_parse_string;
625 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
626 if (got_hi_surrogate) /* Clean up any pending chars */
627 printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
634 case json_tokener_state_boolean:
637 printbuf_memappend_fast(tok->pb, &c, 1);
638 size1 = json_min(tok->st_pos+1, json_true_str_len);
639 size2 = json_min(tok->st_pos+1, json_false_str_len);
640 if((!(tok->flags & JSON_TOKENER_STRICT) &&
641 strncasecmp(json_true_str, tok->pb->buf, size1) == 0)
642 || (strncmp(json_true_str, tok->pb->buf, size1) == 0)
644 if(tok->st_pos == json_true_str_len) {
645 current = json_object_new_boolean(1);
646 saved_state = json_tokener_state_finish;
647 state = json_tokener_state_eatws;
650 } else if((!(tok->flags & JSON_TOKENER_STRICT) &&
651 strncasecmp(json_false_str, tok->pb->buf, size2) == 0)
652 || (strncmp(json_false_str, tok->pb->buf, size2) == 0)) {
653 if(tok->st_pos == json_false_str_len) {
654 current = json_object_new_boolean(0);
655 saved_state = json_tokener_state_finish;
656 state = json_tokener_state_eatws;
660 tok->err = json_tokener_error_parse_boolean;
667 case json_tokener_state_number:
669 /* Advance until we change state */
670 const char *case_start = str;
672 while(c && strchr(json_number_chars, c)) {
674 if(c == '.' || c == 'e' || c == 'E')
676 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
677 printbuf_memappend_fast(tok->pb, case_start, case_len);
682 printbuf_memappend_fast(tok->pb, case_start, case_len);
684 // Check for -Infinity
685 if (tok->pb->buf[0] == '-' && case_len == 1 &&
686 (c == 'i' || c == 'I'))
688 state = json_tokener_state_inf;
695 if (!tok->is_double && json_parse_int64(tok->pb->buf, &num64) == 0) {
696 if (num64 && tok->pb->buf[0]=='0' && (tok->flags & JSON_TOKENER_STRICT)) {
697 /* in strict mode, number must not start with 0 */
698 tok->err = json_tokener_error_parse_number;
701 current = json_object_new_int64(num64);
703 else if(tok->is_double && json_parse_double(tok->pb->buf, &numd) == 0)
705 current = json_object_new_double_s(numd, tok->pb->buf);
707 tok->err = json_tokener_error_parse_number;
710 saved_state = json_tokener_state_finish;
711 state = json_tokener_state_eatws;
716 case json_tokener_state_array_after_sep:
717 case json_tokener_state_array:
719 if (state == json_tokener_state_array_after_sep &&
720 (tok->flags & JSON_TOKENER_STRICT))
722 tok->err = json_tokener_error_parse_unexpected;
725 saved_state = json_tokener_state_finish;
726 state = json_tokener_state_eatws;
728 if(tok->depth >= tok->max_depth-1) {
729 tok->err = json_tokener_error_depth;
732 state = json_tokener_state_array_add;
734 json_tokener_reset_level(tok, tok->depth);
739 case json_tokener_state_array_add:
740 json_object_array_add(current, obj);
741 saved_state = json_tokener_state_array_sep;
742 state = json_tokener_state_eatws;
745 case json_tokener_state_array_sep:
747 saved_state = json_tokener_state_finish;
748 state = json_tokener_state_eatws;
749 } else if(c == ',') {
750 saved_state = json_tokener_state_array_after_sep;
751 state = json_tokener_state_eatws;
753 tok->err = json_tokener_error_parse_array;
758 case json_tokener_state_object_field_start:
759 case json_tokener_state_object_field_start_after_sep:
761 if (state == json_tokener_state_object_field_start_after_sep &&
762 (tok->flags & JSON_TOKENER_STRICT))
764 tok->err = json_tokener_error_parse_unexpected;
767 saved_state = json_tokener_state_finish;
768 state = json_tokener_state_eatws;
769 } else if (c == '"' || c == '\'') {
771 printbuf_reset(tok->pb);
772 state = json_tokener_state_object_field;
774 tok->err = json_tokener_error_parse_object_key_name;
779 case json_tokener_state_object_field:
781 /* Advance until we change state */
782 const char *case_start = str;
784 if(c == tok->quote_char) {
785 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
786 obj_field_name = strdup(tok->pb->buf);
787 saved_state = json_tokener_state_object_field_end;
788 state = json_tokener_state_eatws;
790 } else if(c == '\\') {
791 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
792 saved_state = json_tokener_state_object_field;
793 state = json_tokener_state_string_escape;
796 if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
797 printbuf_memappend_fast(tok->pb, case_start, str-case_start);
804 case json_tokener_state_object_field_end:
806 saved_state = json_tokener_state_object_value;
807 state = json_tokener_state_eatws;
809 tok->err = json_tokener_error_parse_object_key_sep;
814 case json_tokener_state_object_value:
815 if(tok->depth >= tok->max_depth-1) {
816 tok->err = json_tokener_error_depth;
819 state = json_tokener_state_object_value_add;
821 json_tokener_reset_level(tok, tok->depth);
824 case json_tokener_state_object_value_add:
825 json_object_object_add(current, obj_field_name, obj);
826 free(obj_field_name);
827 obj_field_name = NULL;
828 saved_state = json_tokener_state_object_sep;
829 state = json_tokener_state_eatws;
832 case json_tokener_state_object_sep:
834 saved_state = json_tokener_state_finish;
835 state = json_tokener_state_eatws;
836 } else if(c == ',') {
837 saved_state = json_tokener_state_object_field_start_after_sep;
838 state = json_tokener_state_eatws;
840 tok->err = json_tokener_error_parse_object_value_sep;
846 if (!ADVANCE_CHAR(str, tok))
848 } /* while(POP_CHAR) */
852 (state == json_tokener_state_finish) &&
854 (tok->flags & JSON_TOKENER_STRICT)) {
855 /* unexpected char after JSON data */
856 tok->err = json_tokener_error_parse_unexpected;
858 if (!c) { /* We hit an eof char (0) */
859 if(state != json_tokener_state_finish &&
860 saved_state != json_tokener_state_finish)
861 tok->err = json_tokener_error_parse_eof;
864 #ifdef HAVE_SETLOCALE
865 setlocale(LC_NUMERIC, oldlocale);
866 if (oldlocale) free(oldlocale);
869 if (tok->err == json_tokener_success)
871 json_object *ret = json_object_get(current);
874 /* Partially reset, so we parse additional objects on subsequent calls. */
875 for(ii = tok->depth; ii >= 0; ii--)
876 json_tokener_reset_level(tok, ii);
880 MC_DEBUG("json_tokener_parse_ex: error %s at offset %d\n",
881 json_tokener_errors[tok->err], tok->char_offset);
885 void json_tokener_set_flags(struct json_tokener *tok, int flags)