src/json.c

changeset 1548
12315ee158ad
parent 1547
12da0654e4a9
equal deleted inserted replaced
1547:12da0654e4a9 1548:12315ee158ad
1176 // the name 1176 // the name
1177 actual += wfunc("\"", 1, 1, target); 1177 actual += wfunc("\"", 1, 1, target);
1178 cxstring key = cx_strn(member->key->data, member->key->len); 1178 cxstring key = cx_strn(member->key->data, member->key->len);
1179 cxmutstr name = escape_string(key, settings->escape_slash); 1179 cxmutstr name = escape_string(key, settings->escape_slash);
1180 actual += wfunc(name.ptr, 1, name.length, target); 1180 actual += wfunc(name.ptr, 1, name.length, target);
1181 if (name.ptr != key.ptr) {
1182 cx_strfree(&name);
1183 }
1184 actual += wfunc("\"", 1, 1, target); 1181 actual += wfunc("\"", 1, 1, target);
1185 const char *obj_name_sep = ": "; 1182 const char *obj_name_sep = ": ";
1186 if (settings->pretty) { 1183 if (settings->pretty) {
1187 actual += wfunc(obj_name_sep, 1, 2, target); 1184 actual += wfunc(obj_name_sep, 1, 2, target);
1188 // FIXME: is this really correct? should be the (escaped) name.length 1185 expected += 4 + name.length;
1189 expected += 4 + key.length;
1190 } else { 1186 } else {
1191 actual += wfunc(obj_name_sep, 1, 1, target); 1187 actual += wfunc(obj_name_sep, 1, 1, target);
1192 // FIXME: is this really correct? should be the (escaped) name.length 1188 expected += 3 + name.length;
1193 expected += 3 + key.length; 1189 }
1190 if (name.ptr != key.ptr) {
1191 cx_strfree(&name);
1194 } 1192 }
1195 1193
1196 // the value 1194 // the value
1197 if (cx_json_write_rec(target, member->value, wfunc, settings, depth)) return 1; 1195 if (cx_json_write_rec(target, member->value, wfunc, settings, depth)) return 1;
1198 1196
1251 case CX_JSON_STRING: { 1249 case CX_JSON_STRING: {
1252 actual += wfunc("\"", 1, 1, target); 1250 actual += wfunc("\"", 1, 1, target);
1253 cxmutstr str = escape_string(cx_strcast(value->string), 1251 cxmutstr str = escape_string(cx_strcast(value->string),
1254 settings->escape_slash); 1252 settings->escape_slash);
1255 actual += wfunc(str.ptr, 1, str.length, target); 1253 actual += wfunc(str.ptr, 1, str.length, target);
1254 actual += wfunc("\"", 1, 1, target);
1255 expected += 2 + str.length;
1256 if (str.ptr != value->string.ptr) { 1256 if (str.ptr != value->string.ptr) {
1257 cx_strfree(&str); 1257 cx_strfree(&str);
1258 } 1258 }
1259 actual += wfunc("\"", 1, 1, target);
1260 expected += 2 + value->string.length;
1261 break; 1259 break;
1262 } 1260 }
1263 case CX_JSON_NUMBER: { 1261 case CX_JSON_NUMBER: {
1264 int precision = settings->frac_max_digits; 1262 int precision = settings->frac_max_digits;
1265 // because of the way how %g is defined, we need to 1263 // because of the way how %g is defined, we need to

mercurial