Lines Matching refs:buffer

314 /* check if the given size is left to read in a given parse buffer (starting with 1) */
315 #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
316 /* check if the buffer can be accessed at the given index (starting with 0) */
317 #define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
318 #define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
319 /* get a pointer to the buffer at the position */
320 #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
339 /* copy the number into a temporary buffer and replace '.' with the decimal point
436 /* copy the number into a temporary buffer and replace '.' with the decimal point
595 unsigned char *buffer;
610 if ((p == NULL) || (p->buffer == NULL))
630 return p->buffer + p->offset;
637 /* calculate new buffer size */
658 newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize);
661 p->hooks.deallocate(p->buffer);
663 p->buffer = NULL;
674 p->hooks.deallocate(p->buffer);
676 p->buffer = NULL;
681 memcpy(newbuffer, p->buffer, p->offset + 1);
682 p->hooks.deallocate(p->buffer);
685 p->buffer = newbuffer;
691 static void update_offset(printbuffer * const buffer)
694 if ((buffer == NULL) || (buffer->buffer == NULL))
698 buffer_pointer = buffer->buffer + buffer->offset;
700 buffer->offset += strlen((const char*)buffer_pointer);
719 unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */
754 /* sprintf failed or buffer overrun occurred */
793 unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */
824 /* sprintf failed or buffer overrun occurred */
1040 /* prevent buffer overflow when last input character is a backslash */
1281 static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer)
1283 if ((buffer == NULL) || (buffer->content == NULL))
1288 if (cannot_access_at_index(buffer, 0))
1290 return buffer;
1293 while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32))
1295 buffer->offset++;
1298 if (buffer->offset == buffer->length)
1300 buffer->offset--;
1303 return buffer;
1306 /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */
1307 static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
1309 if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0))
1314 if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0))
1316 buffer->offset += 3;
1319 return buffer;
1340 parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
1352 buffer.content = (const unsigned char*)value;
1353 buffer.length = buffer_length;
1354 buffer.offset = 0;
1355 buffer.hooks = global_hooks;
1363 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
1372 buffer_skip_whitespace(&buffer);
1373 if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
1380 *return_parse_end = (const char*)buffer_at_offset(&buffer);
1397 if (buffer.offset < buffer.length)
1399 local_error.position = buffer.offset;
1401 else if (buffer.length > 0)
1403 local_error.position = buffer.length - 1;
1433 printbuffer buffer[1];
1436 memset(buffer, 0, sizeof(buffer));
1438 /* create buffer */
1439 buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
1440 buffer->length = default_buffer_size;
1441 buffer->format = format;
1442 buffer->hooks = *hooks;
1443 if (buffer->buffer == NULL)
1449 if (!print_value(item, buffer))
1453 update_offset(buffer);
1458 printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
1462 buffer->buffer = NULL;
1464 else /* otherwise copy the JSON over to a new buffer */
1466 printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
1471 memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
1472 printed[buffer->offset] = '\0'; /* just to be sure */
1474 /* free the buffer */
1475 hooks->deallocate(buffer->buffer);
1481 if (buffer->buffer != NULL)
1483 hooks->deallocate(buffer->buffer);
1514 p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer);
1515 if (!p.buffer)
1528 global_hooks.deallocate(p.buffer);
1532 return (char*)p.buffer;
1535 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
1539 if ((length < 0) || (buffer == NULL))
1544 p.buffer = (unsigned char*)buffer;
1709 /* check if we skipped to the end of the buffer */
1867 /* check if we skipped to the end of the buffer */