MCPcopy Create free account
hub / github.com/beefytech/Beef / parse_object

Function parse_object

BeefySysLib/util/Json.cpp:421–460  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

419
420/* Build an object from the text. */
421static const char *parse_object(Json* item,const char *value)
422{
423 Json* child;
424 if (*value!='{') {ep=value;return 0;} /* not an object! */
425
426 item->mType=Json::Type_Object;
427 value=skip(value+1);
428 if (*value=='}') return value+1; /* empty array. */
429
430 item->mChild=child=New_Item();
431 value = skip(value);
432 child->mSrcStart = value;
433 if (!item->mChild) return 0;
434 value=skip(parse_string(child,value));
435 if (!value) return 0;
436 child->mName=child->mValueString;child->mValueString=0;
437 if (*value!=':') {ep=value;return 0;} /* fail! */
438 value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
439 if (!value) return 0;
440
441 while (*value==',')
442 {
443 Json* new_item;
444 if (!(new_item=New_Item())) return 0; /* memory fail */
445 child->mNext=new_item;new_item->mPrev=child;child=new_item;
446 value = skip(value+1);
447 child->mSrcStart = value;
448 value=skip(parse_string(child,value));
449 if (!value) return 0;
450 child->mName=child->mValueString;child->mValueString=0;
451 if (*value!=':') {ep=value;return 0;} /* fail! */
452 value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
453 if (!value) return 0;
454 }
455
456 child->mSrcEnd = value;
457
458 if (*value=='}') return value+1; /* end of array */
459 ep=value;return 0; /* malformed. */
460}
461
462/* Render an object to text. */
463static char *print_object(Json* item,int depth,int fmt)

Callers 1

parse_valueFunction · 0.85

Calls 4

skipFunction · 0.85
New_ItemFunction · 0.85
parse_valueFunction · 0.85
parse_stringFunction · 0.70

Tested by

no test coverage detected