static void parsebuffer(void *dat, const XML_Char *s, int len) { struct parse *p = dat; if (0 == len) return; assert(len > 0); bufappend(&p->buf, s, (size_t)len); }
static void json_stringify_inplace(const Jsonnode *node,char **bufp,int *szp,int *lenp){ static char tempbuf[64]; int nwr; switch(node->type){ case JSON_NUMBER: nwr=snprintf(tempbuf,sizeof(tempbuf),"%g",node->numval); bufappend(bufp,szp,lenp,tempbuf,nwr); break; case JSON_STRING: stringrepr_inplace(bufp,szp,lenp,node->strval); break; case JSON_BOOL: bufappend(bufp,szp,lenp,node->boolval?"true":"false",4+!node->boolval); break; case JSON_NULL: bufappend(bufp,szp,lenp,"null",4); break; case JSON_ARRAY: bufappend(bufp,szp,lenp,"[",1); for(int i=0;i<node->arrval.length;i++){ if(i!=0)bufappend(bufp,szp,lenp,",",1); json_stringify_inplace(node->arrval.elems[i],bufp,szp,lenp); } bufappend(bufp,szp,lenp,"]",1); break; case JSON_OBJECT: bufappend(bufp,szp,lenp,"{",1); for(int i=0;i<node->objval.numkeys;i++){ if(i!=0)bufappend(bufp,szp,lenp,",",1); stringrepr_inplace(bufp,szp,lenp,node->objval.keys[i]); bufappend(bufp,szp,lenp,":",1); json_stringify_inplace(node->objval.values[i],bufp,szp,lenp); } bufappend(bufp,szp,lenp,"}",1); break; } }