src/json.c

changeset 1584
7a14af59d356
parent 1583
97fc8c55aeea
child 1585
8ccfbc00f690
equal deleted inserted replaced
1583:97fc8c55aeea 1584:7a14af59d356
1444 } 1444 }
1445 1445
1446 int cxJsonCompare(const CxJsonValue *json, const CxJsonValue *other) { 1446 int cxJsonCompare(const CxJsonValue *json, const CxJsonValue *other) {
1447 if (json == NULL && other == NULL) return 0; 1447 if (json == NULL && other == NULL) return 0;
1448 if (json == NULL || other == NULL) return -1; 1448 if (json == NULL || other == NULL) return -1;
1449 if (json->type != other->type) return -1; 1449 if (json->type != other->type) {
1450 if (!cxJsonIsNumber(json)) return -1;
1451 if (!cxJsonIsNumber(other)) return -1;
1452 }
1450 switch (json->type) { 1453 switch (json->type) {
1451 case CX_JSON_NOTHING: 1454 case CX_JSON_NOTHING:
1452 return 0; 1455 return 0;
1453 case CX_JSON_OBJECT: 1456 case CX_JSON_OBJECT:
1454 return cxMapCompare(json->object, other->object); 1457 return cxMapCompare(json->object, other->object);
1460 } 1463 }
1461 return 0; 1464 return 0;
1462 case CX_JSON_STRING: 1465 case CX_JSON_STRING:
1463 return cx_strcmp(json->string, other->string); 1466 return cx_strcmp(json->string, other->string);
1464 case CX_JSON_INTEGER: 1467 case CX_JSON_INTEGER:
1465 return cx_vcmp_int64(json->integer, other->integer); 1468 return cx_vcmp_int64(json->integer, cxJsonAsInteger(other));
1466 case CX_JSON_NUMBER: 1469 case CX_JSON_NUMBER:
1467 return cx_vcmp_double(json->number, other->number); 1470 return cx_vcmp_double(json->number, cxJsonAsDouble(other));
1468 case CX_JSON_LITERAL: 1471 case CX_JSON_LITERAL:
1469 return json->literal == other->literal ? 0 : -1; 1472 return json->literal == other->literal ? 0 : -1;
1470 default: 1473 default:
1471 // LCOV_EXCL_START 1474 // LCOV_EXCL_START
1472 // unreachable 1475 // unreachable

mercurial