src/json.c

changeset 1116
b381da3a9b19
parent 1083
cf54e413793c
child 1117
54df904472b0
equal deleted inserted replaced
1115:6db21dee4929 1116:b381da3a9b19
732 } 732 }
733 cxFree(value->allocator, value); 733 cxFree(value->allocator, value);
734 } 734 }
735 735
736 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator) { 736 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator) {
737 if (allocator == NULL) allocator = cxDefaultAllocator;
737 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 738 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
738 if (v == NULL) return NULL; 739 if (v == NULL) return NULL;
739 v->allocator = allocator; 740 v->allocator = allocator;
740 v->type = CX_JSON_OBJECT; 741 v->type = CX_JSON_OBJECT;
741 cx_array_initialize_a(allocator, v->value.object.values, 16); 742 cx_array_initialize_a(allocator, v->value.object.values, 16);
753 } 754 }
754 return v; 755 return v;
755 } 756 }
756 757
757 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator) { 758 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator) {
759 if (allocator == NULL) allocator = cxDefaultAllocator;
758 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 760 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
759 if (v == NULL) return NULL; 761 if (v == NULL) return NULL;
760 v->allocator = allocator; 762 v->allocator = allocator;
761 v->type = CX_JSON_ARRAY; 763 v->type = CX_JSON_ARRAY;
762 cx_array_initialize_a(allocator, v->value.array.array, 16); 764 cx_array_initialize_a(allocator, v->value.array.array, 16);
763 if (v->value.array.array == NULL) { cxFree(allocator, v); return NULL; } 765 if (v->value.array.array == NULL) { cxFree(allocator, v); return NULL; }
764 return v; 766 return v;
765 } 767 }
766 768
767 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num) { 769 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num) {
770 if (allocator == NULL) allocator = cxDefaultAllocator;
768 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 771 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
769 if (v == NULL) return NULL; 772 if (v == NULL) return NULL;
770 v->allocator = allocator; 773 v->allocator = allocator;
771 v->type = CX_JSON_NUMBER; 774 v->type = CX_JSON_NUMBER;
772 v->value.number = num; 775 v->value.number = num;
773 return v; 776 return v;
774 } 777 }
775 778
776 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num) { 779 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num) {
780 if (allocator == NULL) allocator = cxDefaultAllocator;
777 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 781 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
778 if (v == NULL) return NULL; 782 if (v == NULL) return NULL;
779 v->allocator = allocator; 783 v->allocator = allocator;
780 v->type = CX_JSON_INTEGER; 784 v->type = CX_JSON_INTEGER;
781 v->value.integer = num; 785 v->value.integer = num;
785 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char* str) { 789 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char* str) {
786 return cxJsonCreateCxString(allocator, cx_str(str)); 790 return cxJsonCreateCxString(allocator, cx_str(str));
787 } 791 }
788 792
789 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str) { 793 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str) {
794 if (allocator == NULL) allocator = cxDefaultAllocator;
790 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 795 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
791 if (v == NULL) return NULL; 796 if (v == NULL) return NULL;
792 v->allocator = allocator; 797 v->allocator = allocator;
793 v->type = CX_JSON_STRING; 798 v->type = CX_JSON_STRING;
794 cxmutstr s = cx_strdup_a(allocator, str); 799 cxmutstr s = cx_strdup_a(allocator, str);
796 v->value.string = s; 801 v->value.string = s;
797 return v; 802 return v;
798 } 803 }
799 804
800 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit) { 805 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit) {
806 if (allocator == NULL) allocator = cxDefaultAllocator;
801 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue)); 807 CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
802 if (v == NULL) return NULL; 808 if (v == NULL) return NULL;
803 v->allocator = allocator; 809 v->allocator = allocator;
804 v->type = CX_JSON_LITERAL; 810 v->type = CX_JSON_LITERAL;
805 v->value.literal = lit; 811 v->value.literal = lit;

mercurial