src/json.c

changeset 1020
e78e65405c56
parent 1014
56eb7da4f3e1
equal deleted inserted replaced
1019:09c6fe8fe3b9 1020:e78e65405c56
98 bool allocated = false; 98 bool allocated = false;
99 if (json->uncompleted.tokentype != CX_JSON_NO_TOKEN) { 99 if (json->uncompleted.tokentype != CX_JSON_NO_TOKEN) {
100 allocated = true; 100 allocated = true;
101 str = cx_strcat_m(json->uncompleted.content, 1, str); 101 str = cx_strcat_m(json->uncompleted.content, 1, str);
102 if (str.ptr == NULL) { 102 if (str.ptr == NULL) {
103 return (CxJsonToken){CX_JSON_NO_TOKEN, false, {0, 0}}; 103 return (CxJsonToken){CX_JSON_NO_TOKEN, false, {NULL, 0}};
104 } 104 }
105 } 105 }
106 json->uncompleted = (CxJsonToken){0}; 106 json->uncompleted = (CxJsonToken){0};
107 CxJsonTokenType ttype; 107 CxJsonTokenType ttype;
108 if (isstring) { 108 if (isstring) {
118 } 118 }
119 if (ttype == CX_JSON_TOKEN_ERROR) { 119 if (ttype == CX_JSON_TOKEN_ERROR) {
120 if (allocated) { 120 if (allocated) {
121 cx_strfree(&str); 121 cx_strfree(&str);
122 } 122 }
123 return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, {0, 0}}; 123 return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, {NULL, 0}};
124 } 124 }
125 return (CxJsonToken){ttype, allocated, str}; 125 return (CxJsonToken){ttype, allocated, str};
126 } 126 }
127 127
128 static CxJsonTokenType char2ttype(char c) { 128 static CxJsonTokenType char2ttype(char c) {
182 ttype = CX_JSON_TOKEN_STRING; 182 ttype = CX_JSON_TOKEN_STRING;
183 token_start = i; 183 token_start = i;
184 } else if (ctype != CX_JSON_NO_TOKEN) { 184 } else if (ctype != CX_JSON_NO_TOKEN) {
185 // single-char token 185 // single-char token
186 json->buffer.pos = i + 1; 186 json->buffer.pos = i + 1;
187 *result = (CxJsonToken){ctype, NULL, {0, 0}}; 187 *result = (CxJsonToken){ctype, false, {NULL, 0}};
188 return CX_JSON_NO_ERROR; 188 return CX_JSON_NO_ERROR;
189 } else { 189 } else {
190 ttype = CX_JSON_TOKEN_LITERAL; // number or literal 190 ttype = CX_JSON_TOKEN_LITERAL; // number or literal
191 token_start = i; 191 token_start = i;
192 } 192 }

mercurial