36 static const char *
ep;
42 if (!s1)
return (s1==s2)?0:1;
if (!s2)
return 1;
43 for(; tolower(*(
const unsigned char *)s1) == tolower(*(
const unsigned char *)s2); ++s1, ++s2)
if(*s1 == 0)
return 0;
44 return tolower(*(
const unsigned char *)s1) - tolower(*(
const unsigned char *)s2);
49 return(malloc(theSize));
64 const char *s = str ? str :
"";
80 cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
81 cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
110 double n=0,sign=1,scale=0;
int subscale=0,signsubscale=1;
113 if (*num==
'-') sign=-1,num++;
114 if (*num==
'0') num++;
115 if (*num>=
'1' && *num<=
'9')
do n=(n*10.0)+(*num++ -
'0');
while (*num>=
'0' && *num<=
'9');
116 if (*num==
'.' && num[1]>=
'0' && num[1]<=
'9') {num++;
do n=(n*10.0)+(*num++ -
'0'),scale--;
while (*num>=
'0' && *num<=
'9');}
117 if (*num==
'e' || *num==
'E')
118 { num++;
if (*num==
'+') num++;
else if (*num==
'-') signsubscale=-1,num++;
119 while (*num>=
'0' && *num<=
'9') subscale=(subscale*10)+(*num++ -
'0');
122 n=sign*n*pow(10.0,(scale+subscale*signsubscale));
135 if (fabs(((
double)item->
valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
138 if (str) sprintf(str,
"%d",item->
valueint);
145 if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,
"%.0f",d);
146 else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,
"%e",d);
147 else sprintf(str,
"%f",d);
153 #define is_hexdigit(c) ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
157 return sscanf(ptr,
"%4x", uc);
161 static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
164 const char *ptr=str+1;
char *ptr2;
char *out;
int len=0;
unsigned uc,uc2;
165 if (*str!=
'\"') {
ep=str;
return 0;}
167 while (*ptr!=
'\"' && *ptr && ++len)
if (*ptr++ ==
'\\') ptr++;
173 while (*ptr!=
'\"' && *ptr)
175 if (*ptr!=
'\\') *ptr2++=*ptr++;
181 case 'b': *ptr2++=
'\b';
break;
182 case 'f': *ptr2++=
'\f';
break;
183 case 'n': *ptr2++=
'\n';
break;
184 case 'r': *ptr2++=
'\r';
break;
185 case 't': *ptr2++=
'\t';
break;
190 if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0)
break;
192 if (uc>=0xD800 && uc<=0xDBFF)
194 if (ptr[1]!=
'\\' || ptr[2]!=
'u')
break;
197 if (uc2<0xDC00 || uc2>0xDFFF)
break;
198 uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
201 len=4;
if (uc<0x80) len=1;
else if (uc<0x800) len=2;
else if (uc<0x10000) len=3; ptr2+=
len;
204 case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
205 case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
206 case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
211 default: *ptr2++=*ptr;
break;
217 if (*ptr==
'\"') ptr++;
226 const char *ptr;
char *ptr2,*out;
int len=0;
unsigned char token;
229 ptr=str;
while ((token=*ptr) && ++len) {
if (strchr(
"\"\\\b\f\n\r\t",token)) len++;
else if (token<32) len+=5;ptr++;}
238 if ((
unsigned char)*ptr>31 && *ptr!=
'\"' && *ptr!=
'\\') *ptr2++=*ptr++;
242 switch (token=*ptr++)
244 case '\\': *ptr2++=
'\\';
break;
245 case '\"': *ptr2++=
'\"';
break;
246 case '\b': *ptr2++=
'b';
break;
247 case '\f': *ptr2++=
'f';
break;
248 case '\n': *ptr2++=
'n';
break;
249 case '\r': *ptr2++=
'r';
break;
250 case '\t': *ptr2++=
't';
break;
251 default: sprintf(ptr2,
"u%04x",token);ptr2+=5;
break;
255 *ptr2++=
'\"';*ptr2++=0;
270 static const char *
skip(
const char *
in) {
while (in && *in && (
unsigned char)*in<=32) in++;
return in;}
290 if (!value)
return 0;
291 if (!strncmp(value,
"null",4)) { item->
type=
cJSON_NULL;
return value+4; }
292 if (!strncmp(value,
"false",5)) { item->
type=
cJSON_False;
return value+5; }
295 if (*value==
'-' || (*value>=
'0' && *value<=
'9')) {
return parse_number(item,value); }
296 if (*value==
'[') {
return parse_array(item,value); }
307 switch ((item->
type)&255)
324 if (*value!=
'[') {
ep=value;
return 0;}
328 if (*value==
']')
return value+1;
331 if (!item->
child)
return 0;
333 if (!value)
return 0;
339 child->
next=new_item;new_item->
prev=child;child=new_item;
341 if (!value)
return 0;
344 if (*value==
']')
return value+1;
352 char *out=0,*ptr,*ret;
355 int numentries=0,i=0,
fail=0;
358 while (child) numentries++,child=child->
next;
361 if (!entries)
return 0;
362 memset(entries,0,numentries*
sizeof(
char*));
365 while (child && !
fail)
369 if (ret) len+=strlen(ret)+2+(fmt?1:0);
else fail=1;
381 for (i=0;i<numentries;i++)
if (entries[i])
cJSON_free(entries[i]);
389 for (i=0;i<numentries;i++)
391 strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
392 if (i!=numentries-1) {*ptr++=
',';
if(fmt)*ptr++=
' ';*ptr=0;}
404 if (*value!=
'{') {
ep=value;
return 0;}
408 if (*value==
'}')
return value+1;
411 if (!item->
child)
return 0;
413 if (!value)
return 0;
415 if (*value!=
':') {
ep=value;
return 0;}
417 if (!value)
return 0;
423 child->
next=new_item;new_item->
prev=child;child=new_item;
425 if (!value)
return 0;
427 if (*value!=
':') {
ep=value;
return 0;}
429 if (!value)
return 0;
432 if (*value==
'}')
return value+1;
439 char **entries=0,**names=0;
440 char *out=0,*ptr,*ret,*str;
int i=0,j;
443 int numentries=0,
fail=0;
445 while (child) numentries++,child=child->
next;
448 if (!entries)
return 0;
451 memset(entries,0,
sizeof(
char*)*numentries);
452 memset(names,0,
sizeof(
char*)*numentries);
455 child=item->
child;depth++;
if (fmt) len+=depth;
460 if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0);
else fail=1;
471 for (i=0;i<numentries;i++) {
if (names[i])
cJSON_free(names[i]);
if (entries[i])
cJSON_free(entries[i]);}
477 *out=
'{';ptr=out+1;
if (fmt)*ptr++=
'\n';*ptr=0;
478 for (i=0;i<numentries;i++)
480 if (fmt)
for (j=0;j<depth;j++) *ptr++=
'\t';
481 strcpy(ptr,names[i]);ptr+=strlen(names[i]);
482 *ptr++=
':';
if (fmt) *ptr++=
'\t';
483 strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
484 if (i!=numentries-1) *ptr++=
',';
485 if (fmt) *ptr++=
'\n';*ptr=0;
490 if (fmt)
for (i=0;i<depth-1;i++) *ptr++=
'\t';
555 cJSON *newitem,*cptr,*nptr=0,*newchild;
560 if (!newitem)
return 0;
566 if (!recurse)
return newitem;
572 if (nptr) {nptr->
next=newchild,newchild->
prev=nptr;nptr=newchild;}
573 else {newitem->
child=newchild;nptr=newchild;}
590 if (!str)
return NULL;
static void(* cJSON_free)(void *ptr)
int cJSON_GetArraySize(cJSON *array)
cJSON * cJSON_CreateString(const char *string)
static const char * parse_string(cJSON *item, const char *str)
void cJSON_DeleteItemFromObject(cJSON *object, const char *string)
struct switch_jb_node_s * next
static const char * parse_value(cJSON *item, const char *value)
cJSON * cJSON_DetachItemFromArray(cJSON *array, int which)
cJSON * cJSON_GetObjectItem(const cJSON *object, const char *string)
static cJSON * cJSON_New_Item()
static char * print_array(cJSON *item, int depth, int fmt)
cJSON * cJSON_CreateIntArray(int *numbers, int count)
void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
void cJSON_DeleteItemFromArray(cJSON *array, int which)
cJSON * cJSON_GetArrayItem(cJSON *array, int item)
void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
static cJSON * create_reference(cJSON *item)
static char * cJSON_strdup(const char *str)
void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
static void * glue_malloc(size_t theSize)
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
const char * cJSON_GetErrorPtr()
cJSON * cJSON_CreateObject()
void cJSON_Delete(cJSON *c)
cJSON * cJSON_CreateBool(int b)
void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
cJSON * cJSON_CreateFalse()
static void glue_free(void *thePtr)
static const char * parse_number(cJSON *item, const char *num)
#define cJSON_IsReference
static void suffix_object(cJSON *prev, cJSON *item)
static int scan_unicode(const char *ptr, unsigned int *uc)
cJSON * cJSON_CreateStringPrintf(const char *fmt,...)
cJSON * cJSON_CreateDoubleArray(double *numbers, int count)
static char * print_value(cJSON *item, int depth, int fmt)
cJSON * cJSON_CreateNull()
static char * print_string_ptr(const char *str)
cJSON * cJSON_Parse(const char *value)
cJSON * cJSON_CreateTrue()
void cJSON_AddItemToArray(cJSON *array, cJSON *item)
void cJSON_InitHooks(cJSON_Hooks *hooks)
cJSON * cJSON_Duplicate(cJSON *item, int recurse)
struct switch_jb_node_s * prev
static const char * skip(const char *in)
cJSON * cJSON_CreateFloatArray(float *numbers, int count)
static void *(* cJSON_malloc)(size_t sz)
char * cJSON_Print(cJSON *item)
static const char * parse_object(cJSON *item, const char *value)
char * cJSON_PrintUnformatted(cJSON *item)
static char * print_string(cJSON *item)
cJSON * cJSON_CreateArray()
static const unsigned char firstByteMark[7]
static const char * parse_array(cJSON *item, const char *value)
static char * print_object(cJSON *item, int depth, int fmt)
cJSON * cJSON_CreateStringArray(const char **strings, int count)
static char * print_number(cJSON *item)
char * switch_vmprintf(const char *zFormat, va_list ap)
cJSON * cJSON_CreateNumber(double num)
cJSON * cJSON_DetachItemFromObject(cJSON *object, const char *string)
static int cJSON_strcasecmp(const char *s1, const char *s2)
void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)