628 cx_strfree_a(json->allocator, &json->uncompleted_member.name); |
628 cx_strfree_a(json->allocator, &json->uncompleted_member.name); |
629 json->uncompleted_member = (CxJsonObjValue){{NULL, 0}, NULL}; |
629 json->uncompleted_member = (CxJsonObjValue){{NULL, 0}, NULL}; |
630 } |
630 } |
631 } |
631 } |
632 |
632 |
|
633 void cxJsonReset(CxJson *json) { |
|
634 const CxAllocator *allocator = json->allocator; |
|
635 cxJsonDestroy(json); |
|
636 cxJsonInit(json, allocator); |
|
637 } |
|
638 |
633 int cxJsonFilln(CxJson *json, const char *buf, size_t size) { |
639 int cxJsonFilln(CxJson *json, const char *buf, size_t size) { |
634 if (cxBufferEof(&json->buffer)) { |
640 if (cxBufferEof(&json->buffer)) { |
635 // reinitialize the buffer |
641 // reinitialize the buffer |
636 cxBufferDestroy(&json->buffer); |
642 cxBufferDestroy(&json->buffer); |
637 cxBufferInit(&json->buffer, (char*) buf, size, |
643 cxBufferInit(&json->buffer, (char*) buf, size, |
1122 if (count > 0) { |
1128 if (count > 0) { |
1123 memmove(value->value.array.array + index, value->value.array.array + index + 1, count * sizeof(CxJsonValue*)); |
1129 memmove(value->value.array.array + index, value->value.array.array + index + 1, count * sizeof(CxJsonValue*)); |
1124 } |
1130 } |
1125 value->value.array.array_size--; |
1131 value->value.array.array_size--; |
1126 return ret; |
1132 return ret; |
|
1133 } |
|
1134 |
|
1135 char *cxJsonAsString(const CxJsonValue *value) { |
|
1136 return value->value.string.ptr; |
|
1137 } |
|
1138 |
|
1139 cxstring cxJsonAsCxString(const CxJsonValue *value) { |
|
1140 return cx_strcast(value->value.string); |
|
1141 } |
|
1142 |
|
1143 cxmutstr cxJsonAsCxMutStr(const CxJsonValue *value) { |
|
1144 return value->value.string; |
|
1145 } |
|
1146 |
|
1147 double cxJsonAsDouble(const CxJsonValue *value) { |
|
1148 if (value->type == CX_JSON_INTEGER) { |
|
1149 return (double) value->value.integer; |
|
1150 } else { |
|
1151 return value->value.number; |
|
1152 } |
|
1153 } |
|
1154 |
|
1155 int64_t cxJsonAsInteger(const CxJsonValue *value) { |
|
1156 if (value->type == CX_JSON_INTEGER) { |
|
1157 return value->value.integer; |
|
1158 } else { |
|
1159 return (int64_t) value->value.number; |
|
1160 } |
1127 } |
1161 } |
1128 |
1162 |
1129 CxIterator cxJsonArrIter(const CxJsonValue *value) { |
1163 CxIterator cxJsonArrIter(const CxJsonValue *value) { |
1130 return cxIteratorPtr( |
1164 return cxIteratorPtr( |
1131 value->value.array.array, |
1165 value->value.array.array, |