parsebuffer: type and macros

This commit is contained in:
Max Bruckner 2017-03-14 10:08:33 +01:00
parent 06a2326e3b
commit 0f98214e71
1 changed files with 16 additions and 0 deletions

16
cJSON.c
View File

@ -185,6 +185,22 @@ static unsigned char get_decimal_point(void)
return (unsigned char) lconv->decimal_point[0];
}
typedef struct
{
const unsigned char *content;
size_t length;
size_t offset;
} parse_buffer;
/* check if the given size is left to read in a given parse buffer (starting with 1) */
#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
#define cannot_read(buffer, size) (!can_read(buffer, size))
/* check if the buffer can be accessed at the given index (starting with 0) */
#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
/* get a pointer to the buffer at the position */
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
/* Parse the input text to generate a number, and populate the result into item. */
static const unsigned char *parse_number(cJSON * const item, const unsigned char * const input)
{