Lines Matching refs:buffer
250 #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) argument
252 #define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (b… argument
253 #define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) argument
255 #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) argument
353 unsigned char *buffer; member
368 if ((p == NULL) || (p->buffer == NULL)) return NULL; in ensure()
381 if (needed <= p->length) return p->buffer + p->offset; in ensure()
399 newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); in ensure()
401 p->hooks.deallocate(p->buffer); in ensure()
403 p->buffer = NULL; in ensure()
411 p->hooks.deallocate(p->buffer); in ensure()
413 p->buffer = NULL; in ensure()
418 memcpy(newbuffer, p->buffer, p->offset + 1); in ensure()
419 p->hooks.deallocate(p->buffer); in ensure()
422 p->buffer = newbuffer; in ensure()
428 static void update_offset(printbuffer *const buffer) in update_offset() argument
431 if ((buffer == NULL) || (buffer->buffer == NULL)) return; in update_offset()
432 buffer_pointer = buffer->buffer + buffer->offset; in update_offset()
434 buffer->offset += strlen((const char *)buffer_pointer); in update_offset()
842 static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) in buffer_skip_whitespace() argument
844 if ((buffer == NULL) || (buffer->content == NULL)) return NULL; in buffer_skip_whitespace()
846 if (cannot_access_at_index(buffer, 0)) return buffer; in buffer_skip_whitespace()
848 while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) buffer->offset++; in buffer_skip_whitespace()
850 if (buffer->offset == buffer->length) buffer->offset--; in buffer_skip_whitespace()
852 return buffer; in buffer_skip_whitespace()
856 static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) in skip_utf8_bom() argument
858 if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) return NULL; in skip_utf8_bom()
860 …if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\x… in skip_utf8_bom()
862 return buffer; in skip_utf8_bom()
880 parse_buffer buffer = { in cJSON_ParseWithLengthOpts() local
891 buffer.content = (const unsigned char *)value; in cJSON_ParseWithLengthOpts()
892 buffer.length = buffer_length; in cJSON_ParseWithLengthOpts()
893 buffer.offset = 0; in cJSON_ParseWithLengthOpts()
894 buffer.hooks = global_hooks; in cJSON_ParseWithLengthOpts()
902 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { in cJSON_ParseWithLengthOpts()
909 buffer_skip_whitespace(&buffer); in cJSON_ParseWithLengthOpts()
910 if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') goto fail; in cJSON_ParseWithLengthOpts()
912 if (return_parse_end) *return_parse_end = (const char *)buffer_at_offset(&buffer); in cJSON_ParseWithLengthOpts()
924 if (buffer.offset < buffer.length) { in cJSON_ParseWithLengthOpts()
925 local_error.position = buffer.offset; in cJSON_ParseWithLengthOpts()
926 } else if (buffer.length > 0) { in cJSON_ParseWithLengthOpts()
927 local_error.position = buffer.length - 1; in cJSON_ParseWithLengthOpts()
954 printbuffer buffer[1]; in print() local
957 memset(buffer, 0, sizeof(buffer)); in print()
960 buffer->buffer = (unsigned char *)hooks->allocate(default_buffer_size); in print()
961 buffer->length = default_buffer_size; in print()
962 buffer->format = format; in print()
963 buffer->hooks = *hooks; in print()
964 if (buffer->buffer == NULL) goto fail; in print()
967 if (!print_value(item, buffer)) goto fail; in print()
968 update_offset(buffer); in print()
972 printed = (unsigned char *)hooks->reallocate(buffer->buffer, buffer->offset + 1); in print()
974 buffer->buffer = NULL; in print()
977 printed = (unsigned char *)hooks->allocate(buffer->offset + 1); in print()
979 memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); in print()
980 printed[buffer->offset] = '\0'; /* just to be sure */ in print()
983 hooks->deallocate(buffer->buffer); in print()
989 if (buffer->buffer != NULL) hooks->deallocate(buffer->buffer); in print()
1015 p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); in cJSON_PrintBuffered()
1016 if (!p.buffer) return NULL; in cJSON_PrintBuffered()
1025 global_hooks.deallocate(p.buffer); in cJSON_PrintBuffered()
1029 return (char *)p.buffer; in cJSON_PrintBuffered()
1032 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const… in cJSON_PrintPreallocated() argument
1038 if ((length < 0) || (buffer == NULL)) return false; in cJSON_PrintPreallocated()
1040 p.buffer = (unsigned char *)buffer; in cJSON_PrintPreallocated()