src/json.c

changeset 1033
e3009345984b
parent 1020
e78e65405c56
child 1037
83620ba72cc1
equal deleted inserted replaced
1032:aaad28e23dac 1033:e3009345984b
672 return &cx_json_value_nothing; 672 return &cx_json_value_nothing;
673 } 673 }
674 return value->value.array.array[index]; 674 return value->value.array.array[index];
675 } 675 }
676 676
677 static void *cx_json_iter_current(const void *it) {
678 const CxIterator *iter = it;
679 return *(CxJsonValue**)iter->elem_handle;
680 }
681
682 static bool cx_json_iter_valid(const void *it) {
683 const CxIterator *iter = it;
684 return iter->index < iter->elem_count;
685 }
686
687 static void cx_json_iter_next(void *it) {
688 CxIterator *iter = it;
689 iter->index++;
690 iter->elem_handle = (char *) iter->elem_handle + sizeof(void *);
691 }
692
693 CxIterator cxJsonArrIter(const CxJsonValue *value) {
694 CxIterator iter;
695
696 iter.index = 0;
697 iter.elem_count = value->value.array.array_size;
698 iter.src_handle.m = value->value.array.array;
699 iter.elem_handle = iter.src_handle.m;
700 iter.elem_size = sizeof(CxJsonValue*);
701 iter.base.valid = cx_json_iter_valid;
702 iter.base.current = cx_json_iter_current;
703 iter.base.next = cx_json_iter_next;
704 iter.base.remove = false;
705 iter.base.mutating = false;
706
707 return iter;
708 }
709
677 CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { 710 CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
678 const CxJsonObject *obj = &(value->value.object); 711 const CxJsonObject *obj = &(value->value.object);
679 // TODO: think about sorting the object so that we can use binary search here 712 // TODO: think about sorting the object so that we can use binary search here
680 for (size_t i = 0; i < obj->values_size; i++) { 713 for (size_t i = 0; i < obj->values_size; i++) {
681 if (0 == strcmp(name, obj->values[i].name)) { 714 if (0 == strcmp(name, obj->values[i].name)) {

mercurial