| 1425 static cxmutstr cx_json_to_string(CxJsonValue *value, const CxAllocator *allocator, CxJsonWriter *writer) { |
1425 static cxmutstr cx_json_to_string(CxJsonValue *value, const CxAllocator *allocator, CxJsonWriter *writer) { |
| 1426 if (allocator == NULL) allocator = cxDefaultAllocator; |
1426 if (allocator == NULL) allocator = cxDefaultAllocator; |
| 1427 CxBuffer buffer; |
1427 CxBuffer buffer; |
| 1428 if (cxBufferInit(&buffer, allocator, NULL, 128, |
1428 if (cxBufferInit(&buffer, allocator, NULL, 128, |
| 1429 CX_BUFFER_AUTO_EXTEND | CX_BUFFER_DO_NOT_FREE)) { |
1429 CX_BUFFER_AUTO_EXTEND | CX_BUFFER_DO_NOT_FREE)) { |
| 1430 return CX_NULLSTR; |
1430 return CX_NULLSTR; // LCOV_EXCL_LINE |
| 1431 } |
1431 } |
| 1432 if (cx_json_write_rec(&buffer, value, cxBufferWriteFunc, writer, 0) |
1432 if (cx_json_write_rec(&buffer, value, cxBufferWriteFunc, writer, 0) |
| 1433 || cxBufferTerminate(&buffer)) { |
1433 || cxBufferTerminate(&buffer)) { |
| 1434 // LCOV_EXCL_START |
1434 // LCOV_EXCL_START |
| 1435 buffer.flags &= ~CX_BUFFER_DO_NOT_FREE; |
1435 buffer.flags &= ~CX_BUFFER_DO_NOT_FREE; |
| 1483 } |
1483 } |
| 1484 case CX_JSON_NUMBER: |
1484 case CX_JSON_NUMBER: |
| 1485 return cx_vcmp_double(json->number, cxJsonAsDouble(other)); |
1485 return cx_vcmp_double(json->number, cxJsonAsDouble(other)); |
| 1486 case CX_JSON_LITERAL: |
1486 case CX_JSON_LITERAL: |
| 1487 return json->literal == other->literal ? 0 : -1; |
1487 return json->literal == other->literal ? 0 : -1; |
| 1488 default: |
1488 default: // LCOV_EXCL_START |
| 1489 // LCOV_EXCL_START |
|
| 1490 // unreachable |
1489 // unreachable |
| 1491 assert(false); |
1490 assert(false); |
| 1492 return -1; |
1491 return -1; |
| 1493 // LCOV_EXCL_STOP |
1492 // LCOV_EXCL_STOP |
| 1494 } |
1493 } |
| 1534 CxJsonValue *arr = cxJsonCreateArr(allocator, elem_count); |
1533 CxJsonValue *arr = cxJsonCreateArr(allocator, elem_count); |
| 1535 if (arr == NULL) return NULL; // LCOV_EXCL_LINE |
1534 if (arr == NULL) return NULL; // LCOV_EXCL_LINE |
| 1536 arr->array.size = elem_count; |
1535 arr->array.size = elem_count; |
| 1537 for (size_t i = 0 ; i < elem_count ; i++) { |
1536 for (size_t i = 0 ; i < elem_count ; i++) { |
| 1538 CxJsonValue *e = cx_json_clone_func(NULL, source->array.data[i], allocator, NULL); |
1537 CxJsonValue *e = cx_json_clone_func(NULL, source->array.data[i], allocator, NULL); |
| 1539 if (e == NULL) { |
1538 if (e == NULL) { // LCOV_EXCL_START |
| 1540 // LCOV_EXCL_START |
|
| 1541 cxJsonValueFree(arr); |
1539 cxJsonValueFree(arr); |
| 1542 return NULL; |
1540 return NULL; |
| 1543 // LCOV_EXCL_STOP |
1541 // LCOV_EXCL_STOP |
| 1544 } |
1542 } |
| 1545 arr->array.data[i] = e; |
1543 arr->array.data[i] = e; |
| 1552 return_value(cxJsonCreateInteger(allocator, source->integer)); |
1550 return_value(cxJsonCreateInteger(allocator, source->integer)); |
| 1553 case CX_JSON_NUMBER: |
1551 case CX_JSON_NUMBER: |
| 1554 return_value(cxJsonCreateNumber(allocator, source->number)); |
1552 return_value(cxJsonCreateNumber(allocator, source->number)); |
| 1555 case CX_JSON_LITERAL: |
1553 case CX_JSON_LITERAL: |
| 1556 return_value(cxJsonCreateLiteral(allocator, source->literal)); |
1554 return_value(cxJsonCreateLiteral(allocator, source->literal)); |
| 1557 default: |
1555 default: // LCOV_EXCL_START |
| 1558 // LCOV_EXCL_START |
|
| 1559 // unreachable |
1556 // unreachable |
| 1560 assert(false); |
1557 assert(false); |
| 1561 return NULL; |
1558 return NULL; |
| 1562 // LCOV_EXCL_STOP |
1559 // LCOV_EXCL_STOP |
| 1563 } |
1560 } |