From 0f98214e71604c685312e7afc2d5e01921326edf Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 14 Mar 2017 10:08:33 +0100 Subject: [PATCH] parsebuffer: type and macros --- cJSON.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cJSON.c b/cJSON.c index a64f835..b57efe9 100644 --- a/cJSON.c +++ b/cJSON.c @@ -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) {