diff --git a/doc/mkapiref.py b/doc/mkapiref.py index b225e5a..29b6b55 100755 --- a/doc/mkapiref.py +++ b/doc/mkapiref.py @@ -36,7 +36,7 @@ def __init__(self, name, content, domain, filename): self.content = content self.domain = domain if self.domain == 'function': - self.funcname = re.search(r'(sf_[^ )]+)\(', self.name).group(1) + self.funcname = re.search(r'(sfparse_[^ )]+)\(', self.name).group(1) self.filename = filename def write(self, out): diff --git a/doc/source/.gitignore b/doc/source/.gitignore index 2344c64..4f70a3d 100644 --- a/doc/source/.gitignore +++ b/doc/source/.gitignore @@ -2,12 +2,13 @@ /conf.py /enums.rst /macros.rst -/sf_base64decode.rst -/sf_parser_dict.rst -/sf_parser_init.rst -/sf_parser_inner_list.rst -/sf_parser_item.rst -/sf_parser_list.rst -/sf_parser_param.rst -/sf_unescape.rst +/sfparse_base64decode.rst +/sfparse_parser_dict.rst +/sfparse_parser_init.rst +/sfparse_parser_inner_list.rst +/sfparse_parser_item.rst +/sfparse_parser_list.rst +/sfparse_parser_param.rst +/sfparse_pctdecode.rst +/sfparse_unescape.rst /types.rst diff --git a/examples.c b/examples.c index 1d8225c..b54e9bb 100644 --- a/examples.c +++ b/examples.c @@ -28,30 +28,30 @@ #include "sfparse.h" -static void print_key(const char *prefix, const sf_vec *key) { +static void print_key(const char *prefix, const sfparse_vec *key) { printf("%s: %.*s\n", prefix, (int)key->len, key->base); } -static void print_value(const char *prefix, const sf_value *val) { +static void print_value(const char *prefix, const sfparse_value *val) { uint8_t *buf; - sf_vec decoded; + sfparse_vec decoded; switch (val->type) { - case SF_TYPE_BOOLEAN: + case SFPARSE_TYPE_BOOLEAN: printf("%s: %s\n", prefix, val->boolean ? "true" : "false"); break; - case SF_TYPE_INTEGER: + case SFPARSE_TYPE_INTEGER: printf("%s: %" PRId64 "\n", prefix, val->integer); break; - case SF_TYPE_DECIMAL: + case SFPARSE_TYPE_DECIMAL: printf("%s: %.03f\n", prefix, (double)val->decimal.numer / (double)val->decimal.denom); break; - case SF_TYPE_STRING: - if (!(val->flags & SF_VALUE_FLAG_ESCAPED_STRING)) { + case SFPARSE_TYPE_STRING: + if (!(val->flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING)) { printf("%s: (string) %.*s\n", prefix, (int)val->vec.len, val->vec.base); break; @@ -59,39 +59,39 @@ static void print_value(const char *prefix, const sf_value *val) { buf = malloc(val->vec.len); decoded.base = buf; - sf_unescape(&decoded, &val->vec); + sfparse_unescape(&decoded, &val->vec); printf("%s: (string) %.*s\n", prefix, (int)decoded.len, decoded.base); free(buf); break; - case SF_TYPE_TOKEN: + case SFPARSE_TYPE_TOKEN: printf("%s: (token) %.*s\n", prefix, (int)val->vec.len, val->vec.base); break; - case SF_TYPE_BYTESEQ: + case SFPARSE_TYPE_BYTESEQ: buf = malloc(val->vec.len); decoded.base = buf; - sf_base64decode(&decoded, &val->vec); + sfparse_base64decode(&decoded, &val->vec); printf("%s: (byteseq) %.*s\n", prefix, (int)decoded.len, decoded.base); free(buf); break; - case SF_TYPE_INNER_LIST: + case SFPARSE_TYPE_INNER_LIST: printf("%s: (inner list)\n", prefix); break; - case SF_TYPE_DATE: + case SFPARSE_TYPE_DATE: printf("%s: (date) %" PRId64 "\n", prefix, val->integer); break; - case SF_TYPE_DISPSTRING: + case SFPARSE_TYPE_DISPSTRING: buf = malloc(val->vec.len); decoded.base = buf; - sf_pctdecode(&decoded, &val->vec); + sfparse_pctdecode(&decoded, &val->vec); printf("%s: (dispstring) %.*s\n", prefix, (int)decoded.len, decoded.base); @@ -105,9 +105,9 @@ static void print_value(const char *prefix, const sf_value *val) { static void example_dictionary(void) { static const uint8_t s[] = "a=(1 2 3;b=\"foo\");c;d=1, e=1.001"; - sf_parser sfp; - sf_vec key; - sf_value val; + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; int rv; printf("# example dictionary\n"); @@ -115,12 +115,12 @@ static void example_dictionary(void) { { printf("## Iterate dictionary keys\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_dict(&sfp, &key, NULL); + rv = sfparse_parser_dict(&sfp, &key, NULL); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -132,12 +132,12 @@ static void example_dictionary(void) { { printf("## Iterate dictionary values\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -150,21 +150,21 @@ static void example_dictionary(void) { { printf("## Read inner list\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } - if (val.type == SF_TYPE_INNER_LIST) { + if (val.type == SFPARSE_TYPE_INNER_LIST) { for (;;) { - rv = sf_parser_inner_list(&sfp, &val); + rv = sfparse_parser_inner_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -178,12 +178,12 @@ static void example_dictionary(void) { { printf("## Read parameters\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -192,9 +192,9 @@ static void example_dictionary(void) { print_value("value", &val); for (;;) { - rv = sf_parser_param(&sfp, &key, &val); + rv = sfparse_parser_param(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -208,29 +208,29 @@ static void example_dictionary(void) { { printf("## Read parameters of items in inner list\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } - if (val.type == SF_TYPE_INNER_LIST) { + if (val.type == SFPARSE_TYPE_INNER_LIST) { for (;;) { - rv = sf_parser_inner_list(&sfp, &val); + rv = sfparse_parser_inner_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } for (;;) { - rv = sf_parser_param(&sfp, &key, &val); + rv = sfparse_parser_param(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -246,9 +246,9 @@ static void example_dictionary(void) { static void example_list(void) { static const uint8_t s[] = "(1 2 3;b=\"foo\"), bar, baz;f=:aGVsbG8=:"; - sf_parser sfp; - sf_vec key; - sf_value val; + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; int rv; printf("# example list\n"); @@ -256,12 +256,12 @@ static void example_list(void) { { printf("## Iterate list values\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_list(&sfp, &val); + rv = sfparse_parser_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -273,21 +273,21 @@ static void example_list(void) { { printf("## Read inner list\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_list(&sfp, &val); + rv = sfparse_parser_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } - if (val.type == SF_TYPE_INNER_LIST) { + if (val.type == SFPARSE_TYPE_INNER_LIST) { for (;;) { - rv = sf_parser_inner_list(&sfp, &val); + rv = sfparse_parser_inner_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -301,12 +301,12 @@ static void example_list(void) { { printf("## Read parameters\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); for (;;) { - rv = sf_parser_list(&sfp, &val); + rv = sfparse_parser_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -314,9 +314,9 @@ static void example_list(void) { print_value("value", &val); for (;;) { - rv = sf_parser_param(&sfp, &key, &val); + rv = sfparse_parser_param(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -329,9 +329,9 @@ static void example_list(void) { } static void example_item(void) { - sf_parser sfp; - sf_vec key; - sf_value val; + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; int rv; printf("# example item\n"); @@ -341,17 +341,17 @@ static void example_item(void) { printf("## Read boolean\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -359,17 +359,17 @@ static void example_item(void) { printf("## Read integer\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -377,17 +377,17 @@ static void example_item(void) { printf("## Read decimal\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -395,17 +395,17 @@ static void example_item(void) { printf("## Read string\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -413,17 +413,17 @@ static void example_item(void) { printf("## Read token\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -431,17 +431,17 @@ static void example_item(void) { printf("## Read byteseq\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -449,17 +449,17 @@ static void example_item(void) { printf("## Read date\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -468,17 +468,17 @@ static void example_item(void) { printf("## Read dispstring\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -486,17 +486,17 @@ static void example_item(void) { printf("## Read inner list\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); print_value("value", &val); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -504,17 +504,17 @@ static void example_item(void) { printf("## Read each value in inner list\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); - assert(SF_TYPE_INNER_LIST == val.type); + assert(SFPARSE_TYPE_INNER_LIST == val.type); for (;;) { - rv = sf_parser_inner_list(&sfp, &val); + rv = sfparse_parser_inner_list(&sfp, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -522,9 +522,9 @@ static void example_item(void) { print_value("value", &val); } - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { @@ -532,16 +532,16 @@ static void example_item(void) { printf("## Read parameters\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); for (;;) { - rv = sf_parser_param(&sfp, &key, &val); + rv = sfparse_parser_param(&sfp, &key, &val); if (rv != 0) { - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); break; } @@ -550,24 +550,24 @@ static void example_item(void) { print_value("param-value", &val); } - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_EOF == rv); + assert(SFPARSE_ERR_EOF == rv); } { static const uint8_t s[] = "foo bar"; printf("## Trailing garbage causes parse error\n"); - sf_parser_init(&sfp, s, sizeof(s) - 1); + sfparse_parser_init(&sfp, s, sizeof(s) - 1); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); assert(0 == rv); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert(SF_ERR_PARSE_ERROR == rv); + assert(SFPARSE_ERR_PARSE_ERROR == rv); } } @@ -577,17 +577,17 @@ typedef struct rfc9218_priority { static int parse_rfc9218_priority(rfc9218_priority *pri, const uint8_t *data, size_t datalen) { - sf_parser sfp; - sf_vec key; - sf_value val; + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; int rv; - sf_parser_init(&sfp, data, datalen); + sfparse_parser_init(&sfp, data, datalen); for (;;) { - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (rv != 0) { - if (rv == SF_ERR_PARSE_ERROR) { + if (rv == SFPARSE_ERR_PARSE_ERROR) { return -1; } @@ -600,7 +600,7 @@ static int parse_rfc9218_priority(rfc9218_priority *pri, const uint8_t *data, switch (key.base[0]) { case 'u': - if (val.type != SF_TYPE_INTEGER) { + if (val.type != SFPARSE_TYPE_INTEGER) { return -1; } @@ -612,7 +612,7 @@ static int parse_rfc9218_priority(rfc9218_priority *pri, const uint8_t *data, break; case 'i': - if (val.type != SF_TYPE_BOOLEAN) { + if (val.type != SFPARSE_TYPE_BOOLEAN) { return -1; } diff --git a/sfparse.c b/sfparse.c index 737766a..8fb52ce 100644 --- a/sfparse.c +++ b/sfparse.c @@ -34,38 +34,42 @@ # include #endif /* __AVX2__ */ -#define SF_STATE_DICT 0x08u -#define SF_STATE_LIST 0x10u -#define SF_STATE_ITEM 0x18u +#define SFPARSE_STATE_DICT 0x08u +#define SFPARSE_STATE_LIST 0x10u +#define SFPARSE_STATE_ITEM 0x18u -#define SF_STATE_INNER_LIST 0x04u +#define SFPARSE_STATE_INNER_LIST 0x04u -#define SF_STATE_BEFORE 0x00u -#define SF_STATE_BEFORE_PARAMS 0x01u -#define SF_STATE_PARAMS 0x02u -#define SF_STATE_AFTER 0x03u +#define SFPARSE_STATE_BEFORE 0x00u +#define SFPARSE_STATE_BEFORE_PARAMS 0x01u +#define SFPARSE_STATE_PARAMS 0x02u +#define SFPARSE_STATE_AFTER 0x03u -#define SF_STATE_OP_MASK 0x03u +#define SFPARSE_STATE_OP_MASK 0x03u -#define SF_SET_STATE_AFTER(NAME) (SF_STATE_##NAME | SF_STATE_AFTER) -#define SF_SET_STATE_BEFORE_PARAMS(NAME) \ - (SF_STATE_##NAME | SF_STATE_BEFORE_PARAMS) -#define SF_SET_STATE_INNER_LIST_BEFORE(NAME) \ - (SF_STATE_##NAME | SF_STATE_INNER_LIST | SF_STATE_BEFORE) +#define SFPARSE_SET_STATE_AFTER(NAME) \ + (SFPARSE_STATE_##NAME | SFPARSE_STATE_AFTER) +#define SFPARSE_SET_STATE_BEFORE_PARAMS(NAME) \ + (SFPARSE_STATE_##NAME | SFPARSE_STATE_BEFORE_PARAMS) +#define SFPARSE_SET_STATE_INNER_LIST_BEFORE(NAME) \ + (SFPARSE_STATE_##NAME | SFPARSE_STATE_INNER_LIST | SFPARSE_STATE_BEFORE) -#define SF_STATE_DICT_AFTER SF_SET_STATE_AFTER(DICT) -#define SF_STATE_DICT_BEFORE_PARAMS SF_SET_STATE_BEFORE_PARAMS(DICT) -#define SF_STATE_DICT_INNER_LIST_BEFORE SF_SET_STATE_INNER_LIST_BEFORE(DICT) +#define SFPARSE_STATE_DICT_AFTER SFPARSE_SET_STATE_AFTER(DICT) +#define SFPARSE_STATE_DICT_BEFORE_PARAMS SFPARSE_SET_STATE_BEFORE_PARAMS(DICT) +#define SFPARSE_STATE_DICT_INNER_LIST_BEFORE \ + SFPARSE_SET_STATE_INNER_LIST_BEFORE(DICT) -#define SF_STATE_LIST_AFTER SF_SET_STATE_AFTER(LIST) -#define SF_STATE_LIST_BEFORE_PARAMS SF_SET_STATE_BEFORE_PARAMS(LIST) -#define SF_STATE_LIST_INNER_LIST_BEFORE SF_SET_STATE_INNER_LIST_BEFORE(LIST) +#define SFPARSE_STATE_LIST_AFTER SFPARSE_SET_STATE_AFTER(LIST) +#define SFPARSE_STATE_LIST_BEFORE_PARAMS SFPARSE_SET_STATE_BEFORE_PARAMS(LIST) +#define SFPARSE_STATE_LIST_INNER_LIST_BEFORE \ + SFPARSE_SET_STATE_INNER_LIST_BEFORE(LIST) -#define SF_STATE_ITEM_AFTER SF_SET_STATE_AFTER(ITEM) -#define SF_STATE_ITEM_BEFORE_PARAMS SF_SET_STATE_BEFORE_PARAMS(ITEM) -#define SF_STATE_ITEM_INNER_LIST_BEFORE SF_SET_STATE_INNER_LIST_BEFORE(ITEM) +#define SFPARSE_STATE_ITEM_AFTER SFPARSE_SET_STATE_AFTER(ITEM) +#define SFPARSE_STATE_ITEM_BEFORE_PARAMS SFPARSE_SET_STATE_BEFORE_PARAMS(ITEM) +#define SFPARSE_STATE_ITEM_INNER_LIST_BEFORE \ + SFPARSE_SET_STATE_INNER_LIST_BEFORE(ITEM) -#define SF_STATE_INITIAL 0x00u +#define SFPARSE_STATE_INITIAL 0x00u #define DIGIT_CASES \ case '0': \ @@ -401,25 +405,25 @@ static int ctz(unsigned int v) { # endif /* !_MSC_VER */ #endif /* __AVX2__ */ -static int parser_eof(sf_parser *sfp) { return sfp->pos == sfp->end; } +static int parser_eof(sfparse_parser *sfp) { return sfp->pos == sfp->end; } -static void parser_discard_ows(sf_parser *sfp) { +static void parser_discard_ows(sfparse_parser *sfp) { for (; !parser_eof(sfp) && is_ws(*sfp->pos); ++sfp->pos) ; } -static void parser_discard_sp(sf_parser *sfp) { +static void parser_discard_sp(sfparse_parser *sfp) { for (; !parser_eof(sfp) && *sfp->pos == ' '; ++sfp->pos) ; } -static void parser_set_op_state(sf_parser *sfp, uint32_t op) { - sfp->state &= ~SF_STATE_OP_MASK; +static void parser_set_op_state(sfparse_parser *sfp, uint32_t op) { + sfp->state &= ~SFPARSE_STATE_OP_MASK; sfp->state |= op; } -static void parser_unset_inner_list_state(sf_parser *sfp) { - sfp->state &= ~SF_STATE_INNER_LIST; +static void parser_unset_inner_list_state(sfparse_parser *sfp) { + sfp->state &= ~SFPARSE_STATE_INNER_LIST; } #ifdef __AVX2__ @@ -459,7 +463,7 @@ static const uint8_t *find_char_key(const uint8_t *first, const uint8_t *last) { } #endif /* __AVX2__ */ -static int parser_key(sf_parser *sfp, sf_vec *dest) { +static int parser_key(sfparse_parser *sfp, sfparse_vec *dest) { const uint8_t *base; #ifdef __AVX2__ const uint8_t *last; @@ -470,7 +474,7 @@ static int parser_key(sf_parser *sfp, sf_vec *dest) { LCALPHA_CASES: break; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } base = sfp->pos++; @@ -511,7 +515,7 @@ static int parser_key(sf_parser *sfp, sf_vec *dest) { return 0; } -static int parser_number(sf_parser *sfp, sf_value *dest) { +static int parser_number(sfparse_parser *sfp, sfparse_value *dest) { int sign = 1; int64_t value = 0; size_t len = 0; @@ -520,7 +524,7 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { if (*sfp->pos == '-') { ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } sign = -1; @@ -532,7 +536,7 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { switch (*sfp->pos) { DIGIT_CASES: if (++len > 15) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } value *= 10; @@ -545,13 +549,13 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { } if (len == 0) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (parser_eof(sfp) || *sfp->pos != '.') { if (dest) { - dest->type = SF_TYPE_INTEGER; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_INTEGER; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->integer = value * sign; } @@ -561,7 +565,7 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { /* decimal */ if (len > 12) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } fpos = len; @@ -572,7 +576,7 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { switch (*sfp->pos) { DIGIT_CASES: if (++len > 15) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } value *= 10; @@ -585,12 +589,12 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { } if (fpos == len || len - fpos > 3) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (dest) { - dest->type = SF_TYPE_DECIMAL; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_DECIMAL; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->decimal.numer = value * sign; switch (len - fpos) { @@ -612,9 +616,9 @@ static int parser_number(sf_parser *sfp, sf_value *dest) { return 0; } -static int parser_date(sf_parser *sfp, sf_value *dest) { +static int parser_date(sfparse_parser *sfp, sfparse_value *dest) { int rv; - sf_value val; + sfparse_value val; /* The first byte has already been validated by the caller. */ assert('@' == *sfp->pos); @@ -622,7 +626,7 @@ static int parser_date(sf_parser *sfp, sf_value *dest) { ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } rv = parser_number(sfp, &val); @@ -630,13 +634,13 @@ static int parser_date(sf_parser *sfp, sf_value *dest) { return rv; } - if (val.type != SF_TYPE_INTEGER) { - return SF_ERR_PARSE_ERROR; + if (val.type != SFPARSE_TYPE_INTEGER) { + return SFPARSE_ERR_PARSE_ERROR; } if (dest) { *dest = val; - dest->type = SF_TYPE_DATE; + dest->type = SFPARSE_TYPE_DATE; } return 0; @@ -670,12 +674,12 @@ static const uint8_t *find_char_string(const uint8_t *first, } #endif /* __AVX2__ */ -static int parser_string(sf_parser *sfp, sf_value *dest) { +static int parser_string(sfparse_parser *sfp, sfparse_value *dest) { const uint8_t *base; #ifdef __AVX2__ const uint8_t *last; #endif /* __AVX2__ */ - uint32_t flags = SF_VALUE_FLAG_NONE; + uint32_t flags = SFPARSE_VALUE_FLAG_NONE; /* The first byte has already been validated by the caller. */ assert('"' == *sfp->pos); @@ -695,24 +699,24 @@ static int parser_string(sf_parser *sfp, sf_value *dest) { case '\\': ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } switch (*sfp->pos) { case '"': case '\\': - flags = SF_VALUE_FLAG_ESCAPED_STRING; + flags = SFPARSE_VALUE_FLAG_ESCAPED_STRING; break; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; case '"': goto fin; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } } #endif /* __AVX2__ */ @@ -726,32 +730,32 @@ static int parser_string(sf_parser *sfp, sf_value *dest) { case '\\': ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } switch (*sfp->pos) { case '"': case '\\': - flags = SF_VALUE_FLAG_ESCAPED_STRING; + flags = SFPARSE_VALUE_FLAG_ESCAPED_STRING; break; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; case '"': goto fin; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } } - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; fin: if (dest) { - dest->type = SF_TYPE_STRING; + dest->type = SFPARSE_TYPE_STRING; dest->flags = flags; dest->vec.len = (size_t)(sfp->pos - base); dest->vec.base = dest->vec.len == 0 ? NULL : (uint8_t *)base; @@ -816,7 +820,7 @@ static const uint8_t *find_char_token(const uint8_t *first, } #endif /* __AVX2__ */ -static int parser_token(sf_parser *sfp, sf_value *dest) { +static int parser_token(sfparse_parser *sfp, sfparse_value *dest) { const uint8_t *base; #ifdef __AVX2__ const uint8_t *last; @@ -849,8 +853,8 @@ static int parser_token(sf_parser *sfp, sf_value *dest) { fin: #endif /* __AVX2__ */ if (dest) { - dest->type = SF_TYPE_TOKEN; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_TOKEN; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->vec.base = (uint8_t *)base; dest->vec.len = (size_t)(sfp->pos - base); } @@ -897,7 +901,7 @@ static const uint8_t *find_char_byteseq(const uint8_t *first, } #endif /* __AVX2__ */ -static int parser_byteseq(sf_parser *sfp, sf_value *dest) { +static int parser_byteseq(sfparse_parser *sfp, sfparse_value *dest) { const uint8_t *base; #ifdef __AVX2__ const uint8_t *last; @@ -926,12 +930,12 @@ static int parser_byteseq(sf_parser *sfp, sf_value *dest) { switch ((sfp->pos - base) & 0x3) { case 0: case 1: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; case 2: ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (*sfp->pos == '=') { @@ -946,27 +950,27 @@ static int parser_byteseq(sf_parser *sfp, sf_value *dest) { } if (parser_eof(sfp) || *sfp->pos != ':') { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } goto fin; case ':': if (((sfp->pos - base) & 0x3) == 1) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } goto fin; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } } - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; fin: if (dest) { - dest->type = SF_TYPE_BYTESEQ; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_BYTESEQ; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->vec.len = (size_t)(sfp->pos - base); dest->vec.base = dest->vec.len == 0 ? NULL : (uint8_t *)base; } @@ -976,7 +980,7 @@ static int parser_byteseq(sf_parser *sfp, sf_value *dest) { return 0; } -static int parser_boolean(sf_parser *sfp, sf_value *dest) { +static int parser_boolean(sfparse_parser *sfp, sfparse_value *dest) { int b; /* The first byte has already been validated by the caller. */ @@ -985,7 +989,7 @@ static int parser_boolean(sf_parser *sfp, sf_value *dest) { ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } switch (*sfp->pos) { @@ -998,14 +1002,14 @@ static int parser_boolean(sf_parser *sfp, sf_value *dest) { break; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } ++sfp->pos; if (dest) { - dest->type = SF_TYPE_BOOLEAN; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_BOOLEAN; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->boolean = b; } @@ -1111,7 +1115,7 @@ static void utf8_decode(uint32_t *state, uint8_t byte) { /* End of utf8 dfa */ -static int parser_dispstring(sf_parser *sfp, sf_value *dest) { +static int parser_dispstring(sfparse_parser *sfp, sfparse_value *dest) { const uint8_t *base; uint8_t c; uint32_t utf8state = UTF8_ACCEPT; @@ -1121,7 +1125,7 @@ static int parser_dispstring(sf_parser *sfp, sf_value *dest) { ++sfp->pos; if (parser_eof(sfp) || *sfp->pos != '"') { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } base = ++sfp->pos; @@ -1130,32 +1134,32 @@ static int parser_dispstring(sf_parser *sfp, sf_value *dest) { switch (*sfp->pos) { X00_1F_CASES: X7F_FF_CASES: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; case '%': ++sfp->pos; if (sfp->pos + 2 > sfp->end) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (pctdecode(&c, &sfp->pos) != 0) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } utf8_decode(&utf8state, c); if (utf8state == UTF8_REJECT) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; case '"': if (utf8state != UTF8_ACCEPT) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (dest) { - dest->type = SF_TYPE_DISPSTRING; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_DISPSTRING; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->vec.len = (size_t)(sfp->pos - base); dest->vec.base = dest->vec.len == 0 ? NULL : (uint8_t *)base; } @@ -1165,17 +1169,17 @@ static int parser_dispstring(sf_parser *sfp, sf_value *dest) { return 0; default: if (utf8state != UTF8_ACCEPT) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } ++sfp->pos; } } - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } -static int parser_bare_item(sf_parser *sfp, sf_value *dest) { +static int parser_bare_item(sfparse_parser *sfp, sfparse_value *dest) { switch (*sfp->pos) { case '"': return parser_string(sfp, dest); @@ -1194,28 +1198,29 @@ static int parser_bare_item(sf_parser *sfp, sf_value *dest) { case '%': return parser_dispstring(sfp, dest); default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } } -static int parser_skip_inner_list(sf_parser *sfp); +static int parser_skip_inner_list(sfparse_parser *sfp); -int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { +int sfparse_parser_param(sfparse_parser *sfp, sfparse_vec *dest_key, + sfparse_value *dest_value) { int rv; - switch (sfp->state & SF_STATE_OP_MASK) { - case SF_STATE_BEFORE: + switch (sfp->state & SFPARSE_STATE_OP_MASK) { + case SFPARSE_STATE_BEFORE: rv = parser_skip_inner_list(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_BEFORE_PARAMS: - parser_set_op_state(sfp, SF_STATE_PARAMS); + case SFPARSE_STATE_BEFORE_PARAMS: + parser_set_op_state(sfp, SFPARSE_STATE_PARAMS); break; - case SF_STATE_PARAMS: + case SFPARSE_STATE_PARAMS: break; default: assert(0); @@ -1223,16 +1228,16 @@ int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { } if (parser_eof(sfp) || *sfp->pos != ';') { - parser_set_op_state(sfp, SF_STATE_AFTER); + parser_set_op_state(sfp, SFPARSE_STATE_AFTER); - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; } ++sfp->pos; parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } rv = parser_key(sfp, dest_key); @@ -1242,8 +1247,8 @@ int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { if (parser_eof(sfp) || *sfp->pos != '=') { if (dest_value) { - dest_value->type = SF_TYPE_BOOLEAN; - dest_value->flags = SF_VALUE_FLAG_NONE; + dest_value->type = SFPARSE_TYPE_BOOLEAN; + dest_value->flags = SFPARSE_VALUE_FLAG_NONE; dest_value->boolean = 1; } @@ -1253,23 +1258,23 @@ int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } return parser_bare_item(sfp, dest_value); } -static int parser_skip_params(sf_parser *sfp) { +static int parser_skip_params(sfparse_parser *sfp) { int rv; for (;;) { - rv = sf_parser_param(sfp, NULL, NULL); + rv = sfparse_parser_param(sfp, NULL, NULL); switch (rv) { case 0: break; - case SF_ERR_EOF: + case SFPARSE_ERR_EOF: return 0; - case SF_ERR_PARSE_ERROR: + case SFPARSE_ERR_PARSE_ERROR: return rv; default: assert(0); @@ -1278,45 +1283,45 @@ static int parser_skip_params(sf_parser *sfp) { } } -int sf_parser_inner_list(sf_parser *sfp, sf_value *dest) { +int sfparse_parser_inner_list(sfparse_parser *sfp, sfparse_value *dest) { int rv; - switch (sfp->state & SF_STATE_OP_MASK) { - case SF_STATE_BEFORE: + switch (sfp->state & SFPARSE_STATE_OP_MASK) { + case SFPARSE_STATE_BEFORE: parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; - case SF_STATE_BEFORE_PARAMS: + case SFPARSE_STATE_BEFORE_PARAMS: rv = parser_skip_params(sfp); if (rv != 0) { return rv; } - /* Technically, we are entering SF_STATE_AFTER, but we will set + /* Technically, we are entering SFPARSE_STATE_AFTER, but we will set another state without reading the state. */ - /* parser_set_op_state(sfp, SF_STATE_AFTER); */ + /* parser_set_op_state(sfp, SFPARSE_STATE_AFTER); */ /* fall through */ - case SF_STATE_AFTER: + case SFPARSE_STATE_AFTER: if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } switch (*sfp->pos) { case ' ': parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; case ')': break; default: - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; @@ -1329,9 +1334,9 @@ int sf_parser_inner_list(sf_parser *sfp, sf_value *dest) { ++sfp->pos; parser_unset_inner_list_state(sfp); - parser_set_op_state(sfp, SF_STATE_BEFORE_PARAMS); + parser_set_op_state(sfp, SFPARSE_STATE_BEFORE_PARAMS); - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; } rv = parser_bare_item(sfp, dest); @@ -1339,22 +1344,22 @@ int sf_parser_inner_list(sf_parser *sfp, sf_value *dest) { return rv; } - parser_set_op_state(sfp, SF_STATE_BEFORE_PARAMS); + parser_set_op_state(sfp, SFPARSE_STATE_BEFORE_PARAMS); return 0; } -static int parser_skip_inner_list(sf_parser *sfp) { +static int parser_skip_inner_list(sfparse_parser *sfp) { int rv; for (;;) { - rv = sf_parser_inner_list(sfp, NULL); + rv = sfparse_parser_inner_list(sfp, NULL); switch (rv) { case 0: break; - case SF_ERR_EOF: + case SFPARSE_ERR_EOF: return 0; - case SF_ERR_PARSE_ERROR: + case SFPARSE_ERR_PARSE_ERROR: return rv; default: assert(0); @@ -1363,39 +1368,39 @@ static int parser_skip_inner_list(sf_parser *sfp) { } } -static int parser_next_key_or_item(sf_parser *sfp) { +static int parser_next_key_or_item(sfparse_parser *sfp) { parser_discard_ows(sfp); if (parser_eof(sfp)) { - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; } if (*sfp->pos != ',') { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } ++sfp->pos; parser_discard_ows(sfp); if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } return 0; } -static int parser_dict_value(sf_parser *sfp, sf_value *dest) { +static int parser_dict_value(sfparse_parser *sfp, sfparse_value *dest) { int rv; if (parser_eof(sfp) || *(sfp->pos) != '=') { /* Boolean true */ if (dest) { - dest->type = SF_TYPE_BOOLEAN; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_BOOLEAN; + dest->flags = SFPARSE_VALUE_FLAG_NONE; dest->boolean = 1; } - sfp->state = SF_STATE_DICT_BEFORE_PARAMS; + sfp->state = SFPARSE_STATE_DICT_BEFORE_PARAMS; return 0; } @@ -1403,18 +1408,18 @@ static int parser_dict_value(sf_parser *sfp, sf_value *dest) { ++sfp->pos; if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } if (*sfp->pos == '(') { if (dest) { - dest->type = SF_TYPE_INNER_LIST; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_INNER_LIST; + dest->flags = SFPARSE_VALUE_FLAG_NONE; } ++sfp->pos; - sfp->state = SF_STATE_DICT_INNER_LIST_BEFORE; + sfp->state = SFPARSE_STATE_DICT_INNER_LIST_BEFORE; return 0; } @@ -1424,41 +1429,42 @@ static int parser_dict_value(sf_parser *sfp, sf_value *dest) { return rv; } - sfp->state = SF_STATE_DICT_BEFORE_PARAMS; + sfp->state = SFPARSE_STATE_DICT_BEFORE_PARAMS; return 0; } -int sf_parser_dict(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { +int sfparse_parser_dict(sfparse_parser *sfp, sfparse_vec *dest_key, + sfparse_value *dest_value) { int rv; switch (sfp->state) { - case SF_STATE_DICT_INNER_LIST_BEFORE: + case SFPARSE_STATE_DICT_INNER_LIST_BEFORE: rv = parser_skip_inner_list(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_DICT_BEFORE_PARAMS: + case SFPARSE_STATE_DICT_BEFORE_PARAMS: rv = parser_skip_params(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_DICT_AFTER: + case SFPARSE_STATE_DICT_AFTER: rv = parser_next_key_or_item(sfp); if (rv != 0) { return rv; } break; - case SF_STATE_INITIAL: + case SFPARSE_STATE_INITIAL: parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; } break; @@ -1475,36 +1481,36 @@ int sf_parser_dict(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value) { return parser_dict_value(sfp, dest_value); } -int sf_parser_list(sf_parser *sfp, sf_value *dest) { +int sfparse_parser_list(sfparse_parser *sfp, sfparse_value *dest) { int rv; switch (sfp->state) { - case SF_STATE_LIST_INNER_LIST_BEFORE: + case SFPARSE_STATE_LIST_INNER_LIST_BEFORE: rv = parser_skip_inner_list(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_LIST_BEFORE_PARAMS: + case SFPARSE_STATE_LIST_BEFORE_PARAMS: rv = parser_skip_params(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_LIST_AFTER: + case SFPARSE_STATE_LIST_AFTER: rv = parser_next_key_or_item(sfp); if (rv != 0) { return rv; } break; - case SF_STATE_INITIAL: + case SFPARSE_STATE_INITIAL: parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; } break; @@ -1515,13 +1521,13 @@ int sf_parser_list(sf_parser *sfp, sf_value *dest) { if (*sfp->pos == '(') { if (dest) { - dest->type = SF_TYPE_INNER_LIST; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_INNER_LIST; + dest->flags = SFPARSE_VALUE_FLAG_NONE; } ++sfp->pos; - sfp->state = SF_STATE_LIST_INNER_LIST_BEFORE; + sfp->state = SFPARSE_STATE_LIST_INNER_LIST_BEFORE; return 0; } @@ -1531,45 +1537,45 @@ int sf_parser_list(sf_parser *sfp, sf_value *dest) { return rv; } - sfp->state = SF_STATE_LIST_BEFORE_PARAMS; + sfp->state = SFPARSE_STATE_LIST_BEFORE_PARAMS; return 0; } -int sf_parser_item(sf_parser *sfp, sf_value *dest) { +int sfparse_parser_item(sfparse_parser *sfp, sfparse_value *dest) { int rv; switch (sfp->state) { - case SF_STATE_INITIAL: + case SFPARSE_STATE_INITIAL: parser_discard_sp(sfp); if (parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } break; - case SF_STATE_ITEM_INNER_LIST_BEFORE: + case SFPARSE_STATE_ITEM_INNER_LIST_BEFORE: rv = parser_skip_inner_list(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_ITEM_BEFORE_PARAMS: + case SFPARSE_STATE_ITEM_BEFORE_PARAMS: rv = parser_skip_params(sfp); if (rv != 0) { return rv; } /* fall through */ - case SF_STATE_ITEM_AFTER: + case SFPARSE_STATE_ITEM_AFTER: parser_discard_sp(sfp); if (!parser_eof(sfp)) { - return SF_ERR_PARSE_ERROR; + return SFPARSE_ERR_PARSE_ERROR; } - return SF_ERR_EOF; + return SFPARSE_ERR_EOF; default: assert(0); abort(); @@ -1577,13 +1583,13 @@ int sf_parser_item(sf_parser *sfp, sf_value *dest) { if (*sfp->pos == '(') { if (dest) { - dest->type = SF_TYPE_INNER_LIST; - dest->flags = SF_VALUE_FLAG_NONE; + dest->type = SFPARSE_TYPE_INNER_LIST; + dest->flags = SFPARSE_VALUE_FLAG_NONE; } ++sfp->pos; - sfp->state = SF_STATE_ITEM_INNER_LIST_BEFORE; + sfp->state = SFPARSE_STATE_ITEM_INNER_LIST_BEFORE; return 0; } @@ -1593,12 +1599,13 @@ int sf_parser_item(sf_parser *sfp, sf_value *dest) { return rv; } - sfp->state = SF_STATE_ITEM_BEFORE_PARAMS; + sfp->state = SFPARSE_STATE_ITEM_BEFORE_PARAMS; return 0; } -void sf_parser_init(sf_parser *sfp, const uint8_t *data, size_t datalen) { +void sfparse_parser_init(sfparse_parser *sfp, const uint8_t *data, + size_t datalen) { if (datalen == 0) { sfp->pos = sfp->end = NULL; } else { @@ -1606,10 +1613,10 @@ void sf_parser_init(sf_parser *sfp, const uint8_t *data, size_t datalen) { sfp->end = data + datalen; } - sfp->state = SF_STATE_INITIAL; + sfp->state = SFPARSE_STATE_INITIAL; } -void sf_unescape(sf_vec *dest, const sf_vec *src) { +void sfparse_unescape(sfparse_vec *dest, const sfparse_vec *src) { const uint8_t *p, *q; uint8_t *o; size_t len, slen; @@ -1645,7 +1652,7 @@ void sf_unescape(sf_vec *dest, const sf_vec *src) { } } -void sf_base64decode(sf_vec *dest, const sf_vec *src) { +void sfparse_base64decode(sfparse_vec *dest, const sfparse_vec *src) { static const int index_tbl[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -1741,7 +1748,7 @@ void sf_base64decode(sf_vec *dest, const sf_vec *src) { dest->len = (size_t)(o - dest->base); } -void sf_pctdecode(sf_vec *dest, const sf_vec *src) { +void sfparse_pctdecode(sfparse_vec *dest, const sfparse_vec *src) { const uint8_t *p, *q; uint8_t *o; size_t len, slen; diff --git a/sfparse.h b/sfparse.h index 95bf958..bcf89a2 100644 --- a/sfparse.h +++ b/sfparse.h @@ -51,70 +51,70 @@ extern "C" { /** * @enum * - * :type:`sf_type` defines value type. + * :type:`sfparse_type` defines value type. */ -typedef enum sf_type { +typedef enum sfparse_type { /** - * :enum:`SF_TYPE_BOOLEAN` indicates boolean type. + * :enum:`SFPARSE_TYPE_BOOLEAN` indicates boolean type. */ - SF_TYPE_BOOLEAN, + SFPARSE_TYPE_BOOLEAN, /** - * :enum:`SF_TYPE_INTEGER` indicates integer type. + * :enum:`SFPARSE_TYPE_INTEGER` indicates integer type. */ - SF_TYPE_INTEGER, + SFPARSE_TYPE_INTEGER, /** - * :enum:`SF_TYPE_DECIMAL` indicates decimal type. + * :enum:`SFPARSE_TYPE_DECIMAL` indicates decimal type. */ - SF_TYPE_DECIMAL, + SFPARSE_TYPE_DECIMAL, /** - * :enum:`SF_TYPE_STRING` indicates string type. + * :enum:`SFPARSE_TYPE_STRING` indicates string type. */ - SF_TYPE_STRING, + SFPARSE_TYPE_STRING, /** - * :enum:`SF_TYPE_TOKEN` indicates token type. + * :enum:`SFPARSE_TYPE_TOKEN` indicates token type. */ - SF_TYPE_TOKEN, + SFPARSE_TYPE_TOKEN, /** - * :enum:`SF_TYPE_BYTESEQ` indicates byte sequence type. + * :enum:`SFPARSE_TYPE_BYTESEQ` indicates byte sequence type. */ - SF_TYPE_BYTESEQ, + SFPARSE_TYPE_BYTESEQ, /** - * :enum:`SF_TYPE_INNER_LIST` indicates inner list type. + * :enum:`SFPARSE_TYPE_INNER_LIST` indicates inner list type. */ - SF_TYPE_INNER_LIST, + SFPARSE_TYPE_INNER_LIST, /** - * :enum:`SF_TYPE_DATE` indicates date type. + * :enum:`SFPARSE_TYPE_DATE` indicates date type. */ - SF_TYPE_DATE, + SFPARSE_TYPE_DATE, /** - * :enum:`SF_TYPE_DISPSTRING` indicates display string type. + * :enum:`SFPARSE_TYPE_DISPSTRING` indicates display string type. */ - SF_TYPE_DISPSTRING -} sf_type; + SFPARSE_TYPE_DISPSTRING +} sfparse_type; /** * @macro * - * :macro:`SF_ERR_PARSE_ERROR` indicates fatal parse error has + * :macro:`SFPARSE_ERR_PARSE_ERROR` indicates fatal parse error has * occurred, and it is not possible to continue the processing. */ -#define SF_ERR_PARSE_ERROR -1 +#define SFPARSE_ERR_PARSE_ERROR -1 /** * @macro * - * :macro:`SF_ERR_EOF` indicates that there is nothing left to read. - * The context of this error varies depending on the function that - * returns this error code. + * :macro:`SFPARSE_ERR_EOF` indicates that there is nothing left to + * read. The context of this error varies depending on the function + * that returns this error code. */ -#define SF_ERR_EOF -2 +#define SFPARSE_ERR_EOF -2 /** * @struct * - * :type:`sf_vec` stores sequence of bytes. + * :type:`sfparse_vec` stores sequence of bytes. */ -typedef struct sf_vec { +typedef struct sfparse_vec { /** * :member:`base` points to the beginning of the sequence of bytes. */ @@ -123,29 +123,29 @@ typedef struct sf_vec { * :member:`len` is the number of bytes contained in this sequence. */ size_t len; -} sf_vec; +} sfparse_vec; /** * @macro * - * :macro:`SF_VALUE_FLAG_NONE` indicates no flag set. + * :macro:`SFPARSE_VALUE_FLAG_NONE` indicates no flag set. */ -#define SF_VALUE_FLAG_NONE 0x0u +#define SFPARSE_VALUE_FLAG_NONE 0x0u /** * @macro * - * :macro:`SF_VALUE_FLAG_ESCAPED_STRING` indicates that a string + * :macro:`SFPARSE_VALUE_FLAG_ESCAPED_STRING` indicates that a string * contains escaped character(s). */ -#define SF_VALUE_FLAG_ESCAPED_STRING 0x1u +#define SFPARSE_VALUE_FLAG_ESCAPED_STRING 0x1u /** * @struct * - * :type:`sf_decimal` contains decimal value. + * :type:`sfparse_decimal` contains decimal value. */ -typedef struct sf_decimal { +typedef struct sfparse_decimal { /** * :member:`numer` contains numerator of the decimal value. */ @@ -154,276 +154,286 @@ typedef struct sf_decimal { * :member:`denom` contains denominator of the decimal value. */ int64_t denom; -} sf_decimal; +} sfparse_decimal; /** * @struct * - * :type:`sf_value` stores a Structured Field item. For Inner List, - * only type is set to :enum:`sf_type.SF_TYPE_INNER_LIST`. In order - * to read the items contained in an inner list, call - * `sf_parser_inner_list`. + * :type:`sfparse_value` stores a Structured Field item. For Inner + * List, only type is set to + * :enum:`sfparse_type.SFPARSE_TYPE_INNER_LIST`. In order to read the + * items contained in an inner list, call `sfparse_parser_inner_list`. */ -typedef struct sf_value { +typedef struct sfparse_value { /** * :member:`type` is the type of the value contained in this * particular object. */ - sf_type type; + sfparse_type type; /** * :member:`flags` is bitwise OR of one or more of - * :macro:`SF_VALUE_FLAG_* `. + * :macro:`SFPARSE_VALUE_FLAG_* `. */ uint32_t flags; /** * @anonunion_start * - * @sf_value_value + * @sfparse_value_value */ union { /** * :member:`boolean` contains boolean value if :member:`type` == - * :enum:`sf_type.SF_TYPE_BOOLEAN`. 1 indicates true, and 0 - * indicates false. + * :enum:`sfparse_type.SFPARSE_TYPE_BOOLEAN`. 1 indicates true, + * and 0 indicates false. */ int boolean; /** * :member:`integer` contains integer value if :member:`type` is - * either :enum:`sf_type.SF_TYPE_INTEGER` or - * :enum:`sf_type.SF_TYPE_DATE`. + * either :enum:`sfparse_type.SFPARSE_TYPE_INTEGER` or + * :enum:`sfparse_type.SFPARSE_TYPE_DATE`. */ int64_t integer; /** * :member:`decimal` contains decimal value if :member:`type` == - * :enum:`sf_type.SF_TYPE_DECIMAL`. + * :enum:`sfparse_type.SFPARSE_TYPE_DECIMAL`. */ - sf_decimal decimal; + sfparse_decimal decimal; /** * :member:`vec` contains sequence of bytes if :member:`type` is - * either :enum:`sf_type.SF_TYPE_STRING`, - * :enum:`sf_type.SF_TYPE_TOKEN`, :enum:`sf_type.SF_TYPE_BYTESEQ`, - * or :enum:`sf_type.SF_TYPE_DISPSTRING`. + * either :enum:`sfparse_type.SFPARSE_TYPE_STRING`, + * :enum:`sfparse_type.SFPARSE_TYPE_TOKEN`, + * :enum:`sfparse_type.SFPARSE_TYPE_BYTESEQ`, or + * :enum:`sfparse_type.SFPARSE_TYPE_DISPSTRING`. * - * For :enum:`sf_type.SF_TYPE_STRING`, this field contains one or - * more escaped characters if :member:`flags` has - * :macro:`SF_VALUE_FLAG_ESCAPED_STRING` set. To unescape the - * string, use `sf_unescape`. + * For :enum:`sfparse_type.SFPARSE_TYPE_STRING`, this field + * contains one or more escaped characters if :member:`flags` has + * :macro:`SFPARSE_VALUE_FLAG_ESCAPED_STRING` set. To unescape + * the string, use `sfparse_unescape`. * - * For :enum:`sf_type.SF_TYPE_BYTESEQ`, this field contains base64 - * encoded string. To decode this byte string, use - * `sf_base64decode`. + * For :enum:`sfparse_type.SFPARSE_TYPE_BYTESEQ`, this field + * contains base64 encoded string. To decode this byte string, + * use `sfparse_base64decode`. * - * For :enum:`sf_type.SF_TYPE_DISPSTRING`, this field may contain - * percent-encoded UTF-8 byte sequences. To decode it, use - * `sf_pctdecode`. + * For :enum:`sfparse_type.SFPARSE_TYPE_DISPSTRING`, this field + * may contain percent-encoded UTF-8 byte sequences. To decode + * it, use `sfparse_pctdecode`. * - * If :member:`vec.len ` == 0, :member:`vec.base - * ` is guaranteed to be NULL. + * If :member:`vec.len ` == 0, :member:`vec.base + * ` is guaranteed to be NULL. */ - sf_vec vec; + sfparse_vec vec; /** * @anonunion_end */ }; -} sf_value; +} sfparse_value; /** * @struct * - * :type:`sf_parser` is the Structured Field Values parser. Use - * `sf_parser_init` to initialize it. + * :type:`sfparse_parser` is the Structured Field Values parser. Use + * `sfparse_parser_init` to initialize it. */ -typedef struct sf_parser { +typedef struct sfparse_parser { /* all fields are private */ const uint8_t *pos; const uint8_t *end; uint32_t state; -} sf_parser; +} sfparse_parser; /** * @function * - * `sf_parser_init` initializes |sfp| with the given data encoded in - * Structured Field Values pointed by |data| of length |datalen|. + * `sfparse_parser_init` initializes |sfp| with the given data encoded + * in Structured Field Values pointed by |data| of length |datalen|. */ -void sf_parser_init(sf_parser *sfp, const uint8_t *data, size_t datalen); +void sfparse_parser_init(sfparse_parser *sfp, const uint8_t *data, + size_t datalen); /** * @function * - * `sf_parser_param` reads a parameter. If this function returns 0, - * it stores parameter key and value in |dest_key| and |dest_value| + * `sfparse_parser_param` reads a parameter. If this function returns + * 0, it stores parameter key and value in |dest_key| and |dest_value| * respectively, if they are not NULL. * * This function does no effort to find duplicated keys. Same key may * be reported more than once. * * Caller should keep calling this function until it returns negative - * error code. If it returns :macro:`SF_ERR_EOF`, all parameters have - * read, and caller can continue to read rest of the values. If it - * returns :macro:`SF_ERR_PARSE_ERROR`, it encountered fatal error - * while parsing field value. + * error code. If it returns :macro:`SFPARSE_ERR_EOF`, all parameters + * have read, and caller can continue to read rest of the values. If + * it returns :macro:`SFPARSE_ERR_PARSE_ERROR`, it encountered fatal + * error while parsing field value. */ -int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value); +int sfparse_parser_param(sfparse_parser *sfp, sfparse_vec *dest_key, + sfparse_value *dest_value); /** * @function * - * `sf_parser_dict` reads the next dictionary key and value pair. If - * this function returns 0, it stores the key and value in |dest_key| - * and |dest_value| respectively, if they are not NULL. + * `sfparse_parser_dict` reads the next dictionary key and value pair. + * If this function returns 0, it stores the key and value in + * |dest_key| and |dest_value| respectively, if they are not NULL. * * Caller can optionally read parameters attached to the pair by - * calling `sf_parser_param`. + * calling `sfparse_parser_param`. * * This function does no effort to find duplicated keys. Same key may * be reported more than once. * * Caller should keep calling this function until it returns negative - * error code. If it returns :macro:`SF_ERR_EOF`, all key and value - * pairs have been read, and there is nothing left to read. + * error code. If it returns :macro:`SFPARSE_ERR_EOF`, all key and + * value pairs have been read, and there is nothing left to read. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :macro:`SF_ERR_EOF` + * :macro:`SFPARSE_ERR_EOF` * All values in the dictionary have read. - * :macro:`SF_ERR_PARSE_ERROR` + * :macro:`SFPARSE_ERR_PARSE_ERROR` * It encountered fatal error while parsing field value. */ -int sf_parser_dict(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value); +int sfparse_parser_dict(sfparse_parser *sfp, sfparse_vec *dest_key, + sfparse_value *dest_value); /** * @function * - * `sf_parser_list` reads the next list item. If this function + * `sfparse_parser_list` reads the next list item. If this function * returns 0, it stores the item in |dest| if it is not NULL. * * Caller can optionally read parameters attached to the item by - * calling `sf_parser_param`. + * calling `sfparse_parser_param`. * * Caller should keep calling this function until it returns negative - * error code. If it returns :macro:`SF_ERR_EOF`, all values in the - * list have been read, and there is nothing left to read. + * error code. If it returns :macro:`SFPARSE_ERR_EOF`, all values in + * the list have been read, and there is nothing left to read. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :macro:`SF_ERR_EOF` + * :macro:`SFPARSE_ERR_EOF` * All values in the list have read. - * :macro:`SF_ERR_PARSE_ERROR` + * :macro:`SFPARSE_ERR_PARSE_ERROR` * It encountered fatal error while parsing field value. */ -int sf_parser_list(sf_parser *sfp, sf_value *dest); +int sfparse_parser_list(sfparse_parser *sfp, sfparse_value *dest); /** * @function * - * `sf_parser_item` reads a single item. If this function returns 0, - * it stores the item in |dest| if it is not NULL. + * `sfparse_parser_item` reads a single item. If this function + * returns 0, it stores the item in |dest| if it is not NULL. * * This function is only used for the field value that consists of a * single item. * * Caller can optionally read parameters attached to the item by - * calling `sf_parser_param`. + * calling `sfparse_parser_param`. * * Caller should call this function again to make sure that there is * nothing left to read. If this 2nd function call returns - * :macro:`SF_ERR_EOF`, all data have been processed successfully. + * :macro:`SFPARSE_ERR_EOF`, all data have been processed + * successfully. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :macro:`SF_ERR_EOF` + * :macro:`SFPARSE_ERR_EOF` * There is nothing left to read. - * :macro:`SF_ERR_PARSE_ERROR` + * :macro:`SFPARSE_ERR_PARSE_ERROR` * It encountered fatal error while parsing field value. */ -int sf_parser_item(sf_parser *sfp, sf_value *dest); +int sfparse_parser_item(sfparse_parser *sfp, sfparse_value *dest); /** * @function * - * `sf_parser_inner_list` reads the next inner list item. If this - * function returns 0, it stores the item in |dest| if it is not NULL. + * `sfparse_parser_inner_list` reads the next inner list item. If + * this function returns 0, it stores the item in |dest| if it is not + * NULL. * * Caller can optionally read parameters attached to the item by - * calling `sf_parser_param`. + * calling `sfparse_parser_param`. * * Caller should keep calling this function until it returns negative - * error code. If it returns :macro:`SF_ERR_EOF`, all values in this - * inner list have been read, and caller can optionally read + * error code. If it returns :macro:`SFPARSE_ERR_EOF`, all values in + * this inner list have been read, and caller can optionally read * parameters attached to this inner list by calling - * `sf_parser_param`. Then caller can continue to read rest of the - * values. + * `sfparse_parser_param`. Then caller can continue to read rest of + * the values. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :macro:`SF_ERR_EOF` + * :macro:`SFPARSE_ERR_EOF` * All values in the inner list have read. - * :macro:`SF_ERR_PARSE_ERROR` + * :macro:`SFPARSE_ERR_PARSE_ERROR` * It encountered fatal error while parsing field value. */ -int sf_parser_inner_list(sf_parser *sfp, sf_value *dest); +int sfparse_parser_inner_list(sfparse_parser *sfp, sfparse_value *dest); /** * @function * - * `sf_unescape` copies |src| to |dest| by removing escapes (``\``). - * |src| should be the pointer to :member:`sf_value.vec` of type - * :enum:`sf_type.SF_TYPE_STRING` produced by either `sf_parser_dict`, - * `sf_parser_list`, `sf_parser_inner_list`, `sf_parser_item`, or - * `sf_parser_param`, otherwise the behavior is undefined. + * `sfparse_unescape` copies |src| to |dest| by removing escapes + * (``\``). |src| should be the pointer to + * :member:`sfparse_value.vec` of type + * :enum:`sfparse_type.SFPARSE_TYPE_STRING` produced by either + * `sfparse_parser_dict`, `sfparse_parser_list`, + * `sfparse_parser_inner_list`, `sfparse_parser_item`, or + * `sfparse_parser_param`, otherwise the behavior is undefined. * - * :member:`dest->base ` must point to the buffer that - * has sufficient space to store the unescaped string. The memory - * areas pointed by :member:`dest->base ` and - * :member:`src->base ` must not overlap. + * :member:`dest->base ` must point to the buffer + * that has sufficient space to store the unescaped string. The + * memory areas pointed by :member:`dest->base ` and + * :member:`src->base ` must not overlap. * * This function sets the length of unescaped string to - * :member:`dest->len `. + * :member:`dest->len `. */ -void sf_unescape(sf_vec *dest, const sf_vec *src); +void sfparse_unescape(sfparse_vec *dest, const sfparse_vec *src); /** * @function * - * `sf_base64decode` decodes Base64 encoded string |src| and writes - * the result into |dest|. |src| should be the pointer to - * :member:`sf_value.vec` of type :enum:`sf_type.SF_TYPE_BYTESEQ` - * produced by either `sf_parser_dict`, `sf_parser_list`, - * `sf_parser_inner_list`, `sf_parser_item`, or `sf_parser_param`, - * otherwise the behavior is undefined. + * `sfparse_base64decode` decodes Base64 encoded string |src| and + * writes the result into |dest|. |src| should be the pointer to + * :member:`sfparse_value.vec` of type + * :enum:`sfparse_type.SFPARSE_TYPE_BYTESEQ` produced by either + * `sfparse_parser_dict`, `sfparse_parser_list`, + * `sfparse_parser_inner_list`, `sfparse_parser_item`, or + * `sfparse_parser_param`, otherwise the behavior is undefined. * - * :member:`dest->base ` must point to the buffer that - * has sufficient space to store the decoded byte string. + * :member:`dest->base ` must point to the buffer + * that has sufficient space to store the decoded byte string. * * This function sets the length of decoded byte string to - * :member:`dest->len `. + * :member:`dest->len `. */ -void sf_base64decode(sf_vec *dest, const sf_vec *src); +void sfparse_base64decode(sfparse_vec *dest, const sfparse_vec *src); /** * @function * - * `sf_pctdecode` decodes percent-encoded string |src| and writes the - * result into |dest|. |src| should be the pointer to - * :member:`sf_value.vec` of type :enum:`sf_type.SF_TYPE_DISPSTRING` - * produced by either `sf_parser_dict`, `sf_parser_list`, - * `sf_parser_inner_list`, `sf_parser_item`, or `sf_parser_param`, - * otherwise the behavior is undefined. + * `sfparse_pctdecode` decodes percent-encoded string |src| and writes + * the result into |dest|. |src| should be the pointer to + * :member:`sfparse_value.vec` of type + * :enum:`sfparse_type.SFPARSE_TYPE_DISPSTRING` produced by either + * `sfparse_parser_dict`, `sfparse_parser_list`, + * `sfparse_parser_inner_list`, `sfparse_parser_item`, or + * `sfparse_parser_param`, otherwise the behavior is undefined. * - * :member:`dest->base ` must point to the buffer that - * has sufficient space to store the decoded byte string. The memory - * areas pointed by :member:`dest->base ` and - * :member:`src->base ` must not overlap. + * :member:`dest->base ` must point to the buffer + * that has sufficient space to store the decoded byte string. The + * memory areas pointed by :member:`dest->base ` and + * :member:`src->base ` must not overlap. * * This function sets the length of decoded byte string to - * :member:`dest->len `. + * :member:`dest->len `. */ -void sf_pctdecode(sf_vec *dest, const sf_vec *src); +void sfparse_pctdecode(sfparse_vec *dest, const sfparse_vec *src); #ifdef __cplusplus } diff --git a/sfparse_test.c b/sfparse_test.c index b4452a6..41a69fd 100644 --- a/sfparse_test.c +++ b/sfparse_test.c @@ -32,29 +32,29 @@ #include "sfparse.h" static const MunitTest tests[] = { - munit_void_test(test_sf_parser_item_skip), - munit_void_test(test_sf_parser_dict_skip), - munit_void_test(test_sf_parser_list_skip), - munit_void_test(test_sf_parser_byteseq), - munit_void_test(test_sf_parser_boolean), - munit_void_test(test_sf_parser_number), - munit_void_test(test_sf_parser_date), - munit_void_test(test_sf_parser_string), - munit_void_test(test_sf_parser_token), - munit_void_test(test_sf_parser_dispstring), - munit_void_test(test_sf_parser_dictionary), - munit_void_test(test_sf_parser_list), - munit_void_test(test_sf_parser_list_list), - munit_void_test(test_sf_parser_param_dict), - munit_void_test(test_sf_parser_param_list), - munit_void_test(test_sf_parser_param_list_list), - munit_void_test(test_sf_parser_number_generated), - munit_void_test(test_sf_parser_string_generated), - munit_void_test(test_sf_parser_token_generated), - munit_void_test(test_sf_parser_key_generated), - munit_void_test(test_sf_parser_byteseq_generated), - munit_void_test(test_sf_parser_large_generated), - munit_void_test(test_sf_parser_examples), + munit_void_test(test_sfparse_parser_item_skip), + munit_void_test(test_sfparse_parser_dict_skip), + munit_void_test(test_sfparse_parser_list_skip), + munit_void_test(test_sfparse_parser_byteseq), + munit_void_test(test_sfparse_parser_boolean), + munit_void_test(test_sfparse_parser_number), + munit_void_test(test_sfparse_parser_date), + munit_void_test(test_sfparse_parser_string), + munit_void_test(test_sfparse_parser_token), + munit_void_test(test_sfparse_parser_dispstring), + munit_void_test(test_sfparse_parser_dictionary), + munit_void_test(test_sfparse_parser_list), + munit_void_test(test_sfparse_parser_list_list), + munit_void_test(test_sfparse_parser_param_dict), + munit_void_test(test_sfparse_parser_param_list), + munit_void_test(test_sfparse_parser_param_list_list), + munit_void_test(test_sfparse_parser_number_generated), + munit_void_test(test_sfparse_parser_string_generated), + munit_void_test(test_sfparse_parser_token_generated), + munit_void_test(test_sfparse_parser_key_generated), + munit_void_test(test_sfparse_parser_byteseq_generated), + munit_void_test(test_sfparse_parser_large_generated), + munit_void_test(test_sfparse_parser_examples), munit_test_end(), }; @@ -62,28 +62,28 @@ const MunitSuite sfparse_suite = { "/sfparse", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, }; -#define sf_parser_bytes_init(SFP, S) \ +#define sfparse_parser_bytes_init(SFP, S) \ { \ uint8_t *input_buffer = malloc(sizeof(S) - 1); \ memcpy(input_buffer, (S), sizeof(S) - 1); \ - sf_parser_init((SFP), input_buffer, sizeof(S) - 1); + sfparse_parser_init((SFP), input_buffer, sizeof(S) - 1); -#define sf_parser_bytes_len_init(SFP, DATA, DATALEN) \ +#define sfparse_parser_bytes_len_init(SFP, DATA, DATALEN) \ { \ uint8_t *input_buffer = malloc((DATALEN)); \ memcpy(input_buffer, (DATA), (DATALEN)); \ - sf_parser_init((SFP), input_buffer, (DATALEN)); + sfparse_parser_init((SFP), input_buffer, (DATALEN)); -#define sf_parser_bytes_free() \ +#define sfparse_parser_bytes_free() \ free(input_buffer); \ } -static int str_sf_vec_eq(const char *s, const sf_vec *v) { +static int str_sfparse_vec_eq(const char *s, const sfparse_vec *v) { return strlen(s) == v->len && (v->len == 0 || 0 == memcmp(s, v->base, v->len)); } -#define assert_str_sf_vec_eq(S, V) \ +#define assert_str_sfparse_vec_eq(S, V) \ do { \ assert_size(strlen(S), ==, (V)->len); \ if ((V)->len) { \ @@ -112,1509 +112,1509 @@ static int is_key_char(const uint8_t c) { c == '-' || c == '.' || c == '*'; } -void test_sf_parser_item_skip(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_item_skip(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; { /* skip empty parameter */ - sf_parser_bytes_init(&sfp, "a"); + sfparse_parser_bytes_init(&sfp, "a"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip non-empty parameter */ - sf_parser_bytes_init(&sfp, "a;f=1000000009;g=1000000007"); + sfparse_parser_bytes_init(&sfp, "a;f=1000000009;g=1000000007"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip boolean parameter */ - sf_parser_bytes_init(&sfp, "a;f"); + sfparse_parser_bytes_init(&sfp, "a;f"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with empty parameter */ - sf_parser_bytes_init(&sfp, "(a)"); + sfparse_parser_bytes_init(&sfp, "(a)"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with non-empty parameter */ - sf_parser_bytes_init(&sfp, "(a);f=1000000009;g=1000000007"); + sfparse_parser_bytes_init(&sfp, "(a);f=1000000009;g=1000000007"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with boolean parameter */ - sf_parser_bytes_init(&sfp, "(a);f"); + sfparse_parser_bytes_init(&sfp, "(a);f"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list but read parameter */ - sf_parser_bytes_init(&sfp, "(a);f"); + sfparse_parser_bytes_init(&sfp, "(a);f"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("f", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("f", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list item parameter */ - sf_parser_bytes_init(&sfp, "(1;foo=100 2;bar)"); + sfparse_parser_bytes_init(&sfp, "(1;foo=100 2;bar)"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); + sfparse_parser_bytes_free(); } } -void test_sf_parser_dict_skip(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_dict_skip(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; { /* skip empty parameter */ - sf_parser_bytes_init(&sfp, "a=3"); + sfparse_parser_bytes_init(&sfp, "a=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip non-empty parameter */ - sf_parser_bytes_init(&sfp, "a=3;f=999;g=1.23"); + sfparse_parser_bytes_init(&sfp, "a=3;f=999;g=1.23"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip boolean parameter */ - sf_parser_bytes_init(&sfp, "a=3;f"); + sfparse_parser_bytes_init(&sfp, "a=3;f"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list */ - sf_parser_bytes_init(&sfp, "a=(1 2 3) , b=3"); + sfparse_parser_bytes_init(&sfp, "a=(1 2 3) , b=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with parameter */ - sf_parser_bytes_init(&sfp, "a=(1 2 3);f=a;g=b , b=3"); + sfparse_parser_bytes_init(&sfp, "a=(1 2 3);f=a;g=b , b=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with boolean parameter */ - sf_parser_bytes_init(&sfp, "a=(1 2 3);f;g , b=3"); + sfparse_parser_bytes_init(&sfp, "a=(1 2 3);f;g , b=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list but read parameter */ - sf_parser_bytes_init(&sfp, "a=(1 2 3);f;g , b=3"); + sfparse_parser_bytes_init(&sfp, "a=(1 2 3);f;g , b=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("f", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("f", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("g", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("g", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list item parameter */ - sf_parser_bytes_init(&sfp, "a=(1;foo=100 2;bar)"); + sfparse_parser_bytes_init(&sfp, "a=(1;foo=100 2;bar)"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_list_skip(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_list_skip(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; { /* skip empty parameter */ - sf_parser_bytes_init(&sfp, "a"); + sfparse_parser_bytes_init(&sfp, "a"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip non-empty parameter */ - sf_parser_bytes_init(&sfp, "a;fff=1;ggg=9"); + sfparse_parser_bytes_init(&sfp, "a;fff=1;ggg=9"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list */ - sf_parser_bytes_init(&sfp, "(1 2 3) , 333"); + sfparse_parser_bytes_init(&sfp, "(1 2 3) , 333"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(333, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with parameter */ - sf_parser_bytes_init(&sfp, "(1 2 3);f=a;g=b , 333"); + sfparse_parser_bytes_init(&sfp, "(1 2 3);f=a;g=b , 333"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(333, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list with boolean parameter */ - sf_parser_bytes_init(&sfp, "(1 2 3);f;g , 333"); + sfparse_parser_bytes_init(&sfp, "(1 2 3);f;g , 333"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(333, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list but read parameter */ - sf_parser_bytes_init(&sfp, "(1 2 3);f;g , 333"); + sfparse_parser_bytes_init(&sfp, "(1 2 3);f;g , 333"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("f", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("f", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("g", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("g", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(333, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* skip inner list item parameter */ - sf_parser_bytes_init(&sfp, "(1;foo=100 2;bar)"); + sfparse_parser_bytes_init(&sfp, "(1;foo=100 2;bar)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_byteseq(void) { - sf_parser sfp; - sf_value val; - sf_vec decoded; +void test_sfparse_parser_byteseq(void) { + sfparse_parser sfp; + sfparse_value val; + sfparse_vec decoded; uint8_t buf[64]; /* https://github.com/httpwg/structured-field-tests/blob/main/binary.json */ { /* basic binary */ - sf_parser_bytes_init(&sfp, ":aGVsbG8=:"); + sfparse_parser_bytes_init(&sfp, ":aGVsbG8=:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("aGVsbG8=", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("aGVsbG8=", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("hello", &decoded); + assert_str_sfparse_vec_eq("hello", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty binary */ - sf_parser_bytes_init(&sfp, "::"); + sfparse_parser_bytes_init(&sfp, "::"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("", &decoded); + assert_str_sfparse_vec_eq("", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad paddding */ - sf_parser_bytes_init(&sfp, ":aGVsbG8:"); + sfparse_parser_bytes_init(&sfp, ":aGVsbG8:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("aGVsbG8", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("aGVsbG8", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("hello", &decoded); + assert_str_sfparse_vec_eq("hello", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad end delimiter */ - sf_parser_bytes_init(&sfp, ":aGVsbG8="); + sfparse_parser_bytes_init(&sfp, ":aGVsbG8="); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace */ - sf_parser_bytes_init(&sfp, ":aGVsb G8=:"); + sfparse_parser_bytes_init(&sfp, ":aGVsb G8=:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra chars */ - sf_parser_bytes_init(&sfp, ":aGVsbG!8=:"); + sfparse_parser_bytes_init(&sfp, ":aGVsbG!8=:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* suffix chars */ - sf_parser_bytes_init(&sfp, ":aGVsbG8=!:"); + sfparse_parser_bytes_init(&sfp, ":aGVsbG8=!:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* non-zero pad bits */ - sf_parser_bytes_init(&sfp, ":iZ==:"); + sfparse_parser_bytes_init(&sfp, ":iZ==:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("iZ==", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("iZ==", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\x89", &decoded); + assert_str_sfparse_vec_eq("\x89", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* non-ASCII binary */ - sf_parser_bytes_init(&sfp, ":/+Ah:"); + sfparse_parser_bytes_init(&sfp, ":/+Ah:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("/+Ah", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("/+Ah", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\xff\xe0!", &decoded); + assert_str_sfparse_vec_eq("\xff\xe0!", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* base64url binary */ - sf_parser_bytes_init(&sfp, ":_-Ah:"); + sfparse_parser_bytes_init(&sfp, ":_-Ah:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* missing closing DQUOTE */ - sf_parser_bytes_init(&sfp, "z,:1jk="); + sfparse_parser_bytes_init(&sfp, "z,:1jk="); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("z", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("z", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Just ':' */ - sf_parser_bytes_init(&sfp, ":"); + sfparse_parser_bytes_init(&sfp, ":"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Just single '=' */ - sf_parser_bytes_init(&sfp, ":=:"); + sfparse_parser_bytes_init(&sfp, ":=:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Two '=' */ - sf_parser_bytes_init(&sfp, ":==:"); + sfparse_parser_bytes_init(&sfp, ":==:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Three '=' */ - sf_parser_bytes_init(&sfp, ":===:"); + sfparse_parser_bytes_init(&sfp, ":===:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Four '=' */ - sf_parser_bytes_init(&sfp, ":====:"); + sfparse_parser_bytes_init(&sfp, ":====:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Single letter never be a base64 encoded string */ - sf_parser_bytes_init(&sfp, ":K:"); + sfparse_parser_bytes_init(&sfp, ":K:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Omitting all padding and non-zero pad bits */ - sf_parser_bytes_init(&sfp, ":K7:"); + sfparse_parser_bytes_init(&sfp, ":K7:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("K7", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("K7", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\x2b", &decoded); + assert_str_sfparse_vec_eq("\x2b", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Omitting a single padding and non-zero pad bits */ - sf_parser_bytes_init(&sfp, ":K7=:"); + sfparse_parser_bytes_init(&sfp, ":K7=:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("K7=", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("K7=", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\x2b", &decoded); + assert_str_sfparse_vec_eq("\x2b", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Omitting a padding and non-zero pad bits */ - sf_parser_bytes_init(&sfp, ":K73:"); + sfparse_parser_bytes_init(&sfp, ":K73:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("K73", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("K73", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\x2b\xbd", &decoded); + assert_str_sfparse_vec_eq("\x2b\xbd", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Not omitting a padding but non-zero pad bits */ - sf_parser_bytes_init(&sfp, ":K73=:"); + sfparse_parser_bytes_init(&sfp, ":K73=:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("K73=", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("K73=", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\x2b\xbd", &decoded); + assert_str_sfparse_vec_eq("\x2b\xbd", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Padding in the middle of encoded string */ - sf_parser_bytes_init(&sfp, ":ab=a:"); + sfparse_parser_bytes_init(&sfp, ":ab=a:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* long binary with extra chars */ - sf_parser_bytes_init(&sfp, - ":cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg!==:"); + sfparse_parser_bytes_init( + &sfp, ":cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg!==:"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_boolean(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_boolean(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/boolean.json */ { /* basic true boolean */ - sf_parser_bytes_init(&sfp, "?1"); + sfparse_parser_bytes_init(&sfp, "?1"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* basic false boolean */ - sf_parser_bytes_init(&sfp, "?0"); + sfparse_parser_bytes_init(&sfp, "?0"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_false(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* unknown boolean */ - sf_parser_bytes_init(&sfp, "?Q"); + sfparse_parser_bytes_init(&sfp, "?Q"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace boolean */ - sf_parser_bytes_init(&sfp, "? 1"); + sfparse_parser_bytes_init(&sfp, "? 1"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative zero boolean */ - sf_parser_bytes_init(&sfp, "?-0"); + sfparse_parser_bytes_init(&sfp, "?-0"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* T boolean */ - sf_parser_bytes_init(&sfp, "?T"); + sfparse_parser_bytes_init(&sfp, "?T"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* F boolean */ - sf_parser_bytes_init(&sfp, "?F"); + sfparse_parser_bytes_init(&sfp, "?F"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* t boolean */ - sf_parser_bytes_init(&sfp, "?t"); + sfparse_parser_bytes_init(&sfp, "?t"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* f boolean */ - sf_parser_bytes_init(&sfp, "?f"); + sfparse_parser_bytes_init(&sfp, "?f"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* spelled-out True boolean */ - sf_parser_bytes_init(&sfp, "?True"); + sfparse_parser_bytes_init(&sfp, "?True"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* spelled-out False boolean */ - sf_parser_bytes_init(&sfp, "?False"); + sfparse_parser_bytes_init(&sfp, "?False"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* Just '?' */ - sf_parser_bytes_init(&sfp, "?"); + sfparse_parser_bytes_init(&sfp, "?"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_number(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_number(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/number.json */ { /* basic integer */ - sf_parser_bytes_init(&sfp, "42"); + sfparse_parser_bytes_init(&sfp, "42"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* zero integer */ - sf_parser_bytes_init(&sfp, "0"); + sfparse_parser_bytes_init(&sfp, "0"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(0, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative zero */ - sf_parser_bytes_init(&sfp, "-0"); + sfparse_parser_bytes_init(&sfp, "-0"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(0, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* double negative zero */ - sf_parser_bytes_init(&sfp, "--0"); + sfparse_parser_bytes_init(&sfp, "--0"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative integer */ - sf_parser_bytes_init(&sfp, "-42"); + sfparse_parser_bytes_init(&sfp, "-42"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(-42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* leading 0 integer" */ - sf_parser_bytes_init(&sfp, "042"); + sfparse_parser_bytes_init(&sfp, "042"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* leading 0 negative integer */ - sf_parser_bytes_init(&sfp, "-042"); + sfparse_parser_bytes_init(&sfp, "-042"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(-42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* leading 0 zero */ - sf_parser_bytes_init(&sfp, "00"); + sfparse_parser_bytes_init(&sfp, "00"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(0, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* comma */ - sf_parser_bytes_init(&sfp, "2,3"); + sfparse_parser_bytes_init(&sfp, "2,3"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative non-DIGIT first character */ - sf_parser_bytes_init(&sfp, "-a23"); + sfparse_parser_bytes_init(&sfp, "-a23"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* sign out of place */ - sf_parser_bytes_init(&sfp, "4-2"); + sfparse_parser_bytes_init(&sfp, "4-2"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(4, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after sign */ - sf_parser_bytes_init(&sfp, "- 42"); + sfparse_parser_bytes_init(&sfp, "- 42"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* long integer */ - sf_parser_bytes_init(&sfp, "123456789012345"); + sfparse_parser_bytes_init(&sfp, "123456789012345"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(123456789012345, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* long negative integer */ - sf_parser_bytes_init(&sfp, "-123456789012345"); + sfparse_parser_bytes_init(&sfp, "-123456789012345"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(-123456789012345, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* too long integer */ - sf_parser_bytes_init(&sfp, "1234567890123456"); + sfparse_parser_bytes_init(&sfp, "1234567890123456"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative too long integer */ - sf_parser_bytes_init(&sfp, "-1234567890123456"); + sfparse_parser_bytes_init(&sfp, "-1234567890123456"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* simple decimal */ - sf_parser_bytes_init(&sfp, "1.23"); + sfparse_parser_bytes_init(&sfp, "1.23"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(123, ==, val.decimal.numer); assert_int64(100, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative decimal */ - sf_parser_bytes_init(&sfp, "-1.23"); + sfparse_parser_bytes_init(&sfp, "-1.23"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(-123, ==, val.decimal.numer); assert_int64(100, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* decimal, whitespace after decimal */ - sf_parser_bytes_init(&sfp, "1. 23"); + sfparse_parser_bytes_init(&sfp, "1. 23"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* decimal, whitespace before decimal" */ - sf_parser_bytes_init(&sfp, "1 .23"); + sfparse_parser_bytes_init(&sfp, "1 .23"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative decimal, whitespace after sign */ - sf_parser_bytes_init(&sfp, "- 1.23"); + sfparse_parser_bytes_init(&sfp, "- 1.23"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* tricky precision decimal */ - sf_parser_bytes_init(&sfp, "123456789012.1"); + sfparse_parser_bytes_init(&sfp, "123456789012.1"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(1234567890121, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* double decimal decimal */ - sf_parser_bytes_init(&sfp, "1.5.4"); + sfparse_parser_bytes_init(&sfp, "1.5.4"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(15, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* adjacent double decimal decimal */ - sf_parser_bytes_init(&sfp, "1..4"); + sfparse_parser_bytes_init(&sfp, "1..4"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* decimal with three fractional digits */ - sf_parser_bytes_init(&sfp, "1.123"); + sfparse_parser_bytes_init(&sfp, "1.123"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(1123, ==, val.decimal.numer); assert_int64(1000, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative decimal with three fractional digits */ - sf_parser_bytes_init(&sfp, "-1.123"); + sfparse_parser_bytes_init(&sfp, "-1.123"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(-1123, ==, val.decimal.numer); assert_int64(1000, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* decimal with four fractional digits */ - sf_parser_bytes_init(&sfp, "1.1234"); + sfparse_parser_bytes_init(&sfp, "1.1234"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative decimal with four fractional digits */ - sf_parser_bytes_init(&sfp, "-1.1234"); + sfparse_parser_bytes_init(&sfp, "-1.1234"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* decimal with thirteen integer digits */ - sf_parser_bytes_init(&sfp, "1234567890123.0"); + sfparse_parser_bytes_init(&sfp, "1234567890123.0"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* negative decimal with thirteen integer digits */ - sf_parser_bytes_init(&sfp, "-1234567890123.0"); + sfparse_parser_bytes_init(&sfp, "-1234567890123.0"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* No digits */ - sf_parser_bytes_init(&sfp, "-a"); + sfparse_parser_bytes_init(&sfp, "-a"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* No digits before '.' */ - sf_parser_bytes_init(&sfp, "-.1"); + sfparse_parser_bytes_init(&sfp, "-.1"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_date(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_date(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/date.json */ { /* date - 1970-01-01 00:00:00 */ - sf_parser_bytes_init(&sfp, "@0"); + sfparse_parser_bytes_init(&sfp, "@0"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DATE, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DATE, ==, val.type); assert_int64(0, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* date - 2022-08-04 01:57:13 */ - sf_parser_bytes_init(&sfp, "@1659578233"); + sfparse_parser_bytes_init(&sfp, "@1659578233"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DATE, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DATE, ==, val.type); assert_int64(1659578233, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* date - 1917-05-30 22:02:47 */ - sf_parser_bytes_init(&sfp, "@-1659578233"); + sfparse_parser_bytes_init(&sfp, "@-1659578233"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DATE, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DATE, ==, val.type); assert_int64(-1659578233, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* date - 2^31 */ - sf_parser_bytes_init(&sfp, "@2147483648"); + sfparse_parser_bytes_init(&sfp, "@2147483648"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DATE, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DATE, ==, val.type); assert_int64(2147483648, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* date - 2^32 */ - sf_parser_bytes_init(&sfp, "@4294967296"); + sfparse_parser_bytes_init(&sfp, "@4294967296"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DATE, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DATE, ==, val.type); assert_int64(4294967296, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* date - decimal */ - sf_parser_bytes_init(&sfp, "@1659578233.12"); + sfparse_parser_bytes_init(&sfp, "@1659578233.12"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* Just '@' */ - sf_parser_bytes_init(&sfp, "@"); + sfparse_parser_bytes_init(&sfp, "@"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_string(void) { - sf_parser sfp; - sf_value val; - sf_vec unescaped; +void test_sfparse_parser_string(void) { + sfparse_parser sfp; + sfparse_value val; + sfparse_vec unescaped; uint8_t buf[256]; /* https://github.com/httpwg/structured-field-tests/blob/main/string.json */ { /* basic string */ - sf_parser_bytes_init(&sfp, "\"foo bar\""); + sfparse_parser_bytes_init(&sfp, "\"foo bar\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("foo bar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("foo bar", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty string */ - sf_parser_bytes_init(&sfp, "\"\""); + sfparse_parser_bytes_init(&sfp, "\"\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* long string */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "\"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo \""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq( "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo ", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace string */ - sf_parser_bytes_init(&sfp, "\" \""); + sfparse_parser_bytes_init(&sfp, "\" \""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq(" ", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq(" ", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* non-ascii string */ - sf_parser_bytes_init(&sfp, "\"füü\""); + sfparse_parser_bytes_init(&sfp, "\"füü\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* tab in string" */ - sf_parser_bytes_init(&sfp, "\"\\t\""); + sfparse_parser_bytes_init(&sfp, "\"\\t\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* newline in string */ - sf_parser_bytes_init(&sfp, "\" \\n \""); + sfparse_parser_bytes_init(&sfp, "\" \\n \""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single quoted string */ - sf_parser_bytes_init(&sfp, "'foo'"); + sfparse_parser_bytes_init(&sfp, "'foo'"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* unbalanced string */ - sf_parser_bytes_init(&sfp, "\"foo"); + sfparse_parser_bytes_init(&sfp, "\"foo"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* string quoting */ - sf_parser_bytes_init(&sfp, "\"foo \\\"bar\\\" \\\\ baz\""); + sfparse_parser_bytes_init(&sfp, "\"foo \\\"bar\\\" \\\\ baz\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("foo \\\"bar\\\" \\\\ baz", &val.vec); - assert_true(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("foo \\\"bar\\\" \\\\ baz", &val.vec); + assert_true(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); unescaped.base = buf; - sf_unescape(&unescaped, &val.vec); + sfparse_unescape(&unescaped, &val.vec); - assert_str_sf_vec_eq("foo \"bar\" \\ baz", &unescaped); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_str_sfparse_vec_eq("foo \"bar\" \\ baz", &unescaped); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad string quoting */ - sf_parser_bytes_init(&sfp, "\"foo \\,\""); + sfparse_parser_bytes_init(&sfp, "\"foo \\,\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* ending string quote */ - sf_parser_bytes_init(&sfp, "\"foo \\\""); + sfparse_parser_bytes_init(&sfp, "\"foo \\\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* abruptly ending string quote */ - sf_parser_bytes_init(&sfp, "\"foo \\"); + sfparse_parser_bytes_init(&sfp, "\"foo \\"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* Just '"' */ - sf_parser_bytes_init(&sfp, "\""); + sfparse_parser_bytes_init(&sfp, "\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* long string with invalid char */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "\"foo foo foo foo foo foo foo foo \x7f foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo " "foo foo foo foo foo foo foo foo foo foo foo foo foo foo \""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_token(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_token(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/token.json */ { /* basic token - item */ - sf_parser_bytes_init(&sfp, "a_b-c.d3:f%00/*"); + sfparse_parser_bytes_init(&sfp, "a_b-c.d3:f%00/*"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a_b-c.d3:f%00/*", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a_b-c.d3:f%00/*", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* token with capitals - item */ - sf_parser_bytes_init(&sfp, "fooBar"); + sfparse_parser_bytes_init(&sfp, "fooBar"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("fooBar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("fooBar", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* token starting with capitals - item */ - sf_parser_bytes_init(&sfp, "FooBar"); + sfparse_parser_bytes_init(&sfp, "FooBar"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("FooBar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("FooBar", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* basic token - list */ - sf_parser_bytes_init(&sfp, "a_b-c3/*"); + sfparse_parser_bytes_init(&sfp, "a_b-c3/*"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a_b-c3/*", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a_b-c3/*", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* token with capitals - list */ - sf_parser_bytes_init(&sfp, "fooBar"); + sfparse_parser_bytes_init(&sfp, "fooBar"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("fooBar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("fooBar", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* token starting with capitals - list */ - sf_parser_bytes_init(&sfp, "FooBar"); + sfparse_parser_bytes_init(&sfp, "FooBar"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("FooBar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("FooBar", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_dispstring(void) { - sf_parser sfp; - sf_value val; - sf_vec decoded; +void test_sfparse_parser_dispstring(void) { + sfparse_parser sfp; + sfparse_value val; + sfparse_vec decoded; uint8_t buf[128]; /* https://github.com/httpwg/structured-field-tests/blob/main/display-string.json @@ -1622,417 +1622,418 @@ void test_sf_parser_dispstring(void) { { /* basic display string (ascii content) */ - sf_parser_bytes_init(&sfp, "%\"foo bar\""); + sfparse_parser_bytes_init(&sfp, "%\"foo bar\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("foo bar", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("foo bar", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("foo bar", &decoded); + assert_str_sfparse_vec_eq("foo bar", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* all printable ascii */ - sf_parser_bytes_init(&sfp, "%\" " - "!%22#$%25&'()*+,-./" - "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]" - "^_`abcdefghijklmnopqrstuvwxyz{|}~\""); - - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq(" !%22#$%25&'()*+,-./" - "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]" - "^_`abcdefghijklmnopqrstuvwxyz{|}~", - &val.vec); + sfparse_parser_bytes_init(&sfp, + "%\" " + "!%22#$%25&'()*+,-./" + "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]" + "^_`abcdefghijklmnopqrstuvwxyz{|}~\""); + + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq(" !%22#$%25&'()*+,-./" + "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]" + "^_`abcdefghijklmnopqrstuvwxyz{|}~", + &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); assert_true( - str_sf_vec_eq(" !\"#$%&'()*+,-./" - "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" - "abcdefghijklmnopqrstuvwxyz{|}~", - &decoded)); + str_sfparse_vec_eq(" !\"#$%&'()*+,-./" + "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~", + &decoded)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* non-ascii display string (uppercase escaping) */ - sf_parser_bytes_init(&sfp, "%\"f%C3%BC%C3%BC\""); + sfparse_parser_bytes_init(&sfp, "%\"f%C3%BC%C3%BC\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* non-ascii display string (lowercase escaping) */ - sf_parser_bytes_init(&sfp, "%\"f%c3%bc%c3%bc\""); + sfparse_parser_bytes_init(&sfp, "%\"f%c3%bc%c3%bc\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("f%c3%bc%c3%bc", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("f%c3%bc%c3%bc", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("füü", &decoded); + assert_str_sfparse_vec_eq("füü", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* tab in display string */ - sf_parser_bytes_init(&sfp, "%\"\t\""); + sfparse_parser_bytes_init(&sfp, "%\"\t\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* newline in display string */ - sf_parser_bytes_init(&sfp, "%\"\n\""); + sfparse_parser_bytes_init(&sfp, "%\"\n\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single quoted display string */ - sf_parser_bytes_init(&sfp, "%'foo'"); + sfparse_parser_bytes_init(&sfp, "%'foo'"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* unquoted display string */ - sf_parser_bytes_init(&sfp, "%foo"); + sfparse_parser_bytes_init(&sfp, "%foo"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* display string missing initial quote */ - sf_parser_bytes_init(&sfp, "%foo\""); + sfparse_parser_bytes_init(&sfp, "%foo\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* unbalanced display string */ - sf_parser_bytes_init(&sfp, "%\"foo"); + sfparse_parser_bytes_init(&sfp, "%\"foo"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* display string quoting */ - sf_parser_bytes_init(&sfp, "%\"foo %22bar%22 \\ baz\""); + sfparse_parser_bytes_init(&sfp, "%\"foo %22bar%22 \\ baz\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("foo %22bar%22 \\ baz", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("foo %22bar%22 \\ baz", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("foo \"bar\" \\ baz", &decoded); + assert_str_sfparse_vec_eq("foo \"bar\" \\ baz", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string escaping */ - sf_parser_bytes_init(&sfp, "%\"foo %a"); + sfparse_parser_bytes_init(&sfp, "%\"foo %a"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string utf-8 (invalid 2-byte seq) */ - sf_parser_bytes_init(&sfp, "%\"%c3%28\""); + sfparse_parser_bytes_init(&sfp, "%\"%c3%28\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string utf-8 (invalid sequence id) */ - sf_parser_bytes_init(&sfp, "%\"%a0%a1\""); + sfparse_parser_bytes_init(&sfp, "%\"%a0%a1\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string utf-8 (invalid hex) */ - sf_parser_bytes_init(&sfp, "%\"%g0%1w\""); + sfparse_parser_bytes_init(&sfp, "%\"%g0%1w\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string utf-8 (invalid 3-byte seq) */ - sf_parser_bytes_init(&sfp, "%\"%e2%28%a1\""); + sfparse_parser_bytes_init(&sfp, "%\"%e2%28%a1\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad display string utf-8 (invalid 4-byte seq) */ - sf_parser_bytes_init(&sfp, "%\"%f0%28%8c%28\""); + sfparse_parser_bytes_init(&sfp, "%\"%f0%28%8c%28\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* BOM in display string */ - sf_parser_bytes_init(&sfp, "%\"BOM: %ef%bb%bf\""); + sfparse_parser_bytes_init(&sfp, "%\"BOM: %ef%bb%bf\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("BOM: %ef%bb%bf", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("BOM: %ef%bb%bf", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("BOM: \xef\xbb\xbf", &decoded); + assert_str_sfparse_vec_eq("BOM: \xef\xbb\xbf", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* base UTF-8 string */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "%\"%e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%81%af%e4%b8%96%e7%95%8c\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq( "%e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%81%af%e4%b8%96%e7%95%8c", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1" - "\xe3\x81\xaf\xe4\xb8\x96\xe7\x95\x8c", - &decoded); + assert_str_sfparse_vec_eq("\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1" + "\xe3\x81\xaf\xe4\xb8\x96\xe7\x95\x8c", + &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* truncated UTF-8 string */ - sf_parser_bytes_init(&sfp, "%\"%e3%81%93%e3%82%93%e3%81%ab%e3%81" - "%a1%e3%81%af%e4%b8%96%e7%95\""); + sfparse_parser_bytes_init(&sfp, "%\"%e3%81%93%e3%82%93%e3%81%ab%e3%81" + "%a1%e3%81%af%e4%b8%96%e7%95\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Just '%' */ - sf_parser_bytes_init(&sfp, "%"); + sfparse_parser_bytes_init(&sfp, "%"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* just '%"' */ - sf_parser_bytes_init(&sfp, "%\""); + sfparse_parser_bytes_init(&sfp, "%\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty dispstring */ - sf_parser_bytes_init(&sfp, "%\"\""); + sfparse_parser_bytes_init(&sfp, "%\"\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("", &decoded); + assert_str_sfparse_vec_eq("", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* base UTF-8 string without closing DQUOTE */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "%\"%e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%81%af%e4%b8%96%e7%95%8c"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* illegal character */ - sf_parser_bytes_init(&sfp, "%\"" - "\x00" - "\""); + sfparse_parser_bytes_init(&sfp, "%\"" + "\x00" + "\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad percent encoding (first half) */ - sf_parser_bytes_init(&sfp, "%\"%qa\""); + sfparse_parser_bytes_init(&sfp, "%\"%qa\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad percent encoding (second half) */ - sf_parser_bytes_init(&sfp, "%\"%aq\""); + sfparse_parser_bytes_init(&sfp, "%\"%aq\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad percent encoding (missing 2 bytes) */ - sf_parser_bytes_init(&sfp, "%\"%\""); + sfparse_parser_bytes_init(&sfp, "%\"%\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad percent encoding (missing 2nd byte) */ - sf_parser_bytes_init(&sfp, "%\"%a\""); + sfparse_parser_bytes_init(&sfp, "%\"%a\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* ASCII string */ - sf_parser_bytes_init(&sfp, "%\"hello world\""); + sfparse_parser_bytes_init(&sfp, "%\"hello world\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_str_sf_vec_eq("hello world", &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_str_sfparse_vec_eq("hello world", &val.vec); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("hello world", &decoded); + assert_str_sfparse_vec_eq("hello world", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* ASCII + percent-encoded UTF-8 byte sequence */ - sf_parser_bytes_init(&sfp, - "%\"This is intended for display to %c3%bcsers.\""); + sfparse_parser_bytes_init( + &sfp, "%\"This is intended for display to %c3%bcsers.\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DISPSTRING, ==, val.type); - assert_true( - str_sf_vec_eq("This is intended for display to %c3%bcsers.", &val.vec)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DISPSTRING, ==, val.type); + assert_true(str_sfparse_vec_eq( + "This is intended for display to %c3%bcsers.", &val.vec)); decoded.base = buf; - sf_pctdecode(&decoded, &val.vec); + sfparse_pctdecode(&decoded, &val.vec); - assert_str_sf_vec_eq("This is intended for display to " - "\xc3\xbc" - "sers.", - &decoded); + assert_str_sfparse_vec_eq("This is intended for display to " + "\xc3\xbc" + "sers.", + &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* overlong 2 byte sequence */ - sf_parser_bytes_init(&sfp, "%\"%c0%af\""); + sfparse_parser_bytes_init(&sfp, "%\"%c0%af\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Uppercase percent-encoded string is invalid */ - sf_parser_bytes_init(&sfp, - "%\"This is intended for display to %C3%BCsers.\""); + sfparse_parser_bytes_init( + &sfp, "%\"This is intended for display to %C3%BCsers.\""); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_dictionary(void) { - sf_parser sfp; - sf_vec key; - sf_value val; - sf_vec decoded; +void test_sfparse_parser_dictionary(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; + sfparse_vec decoded; uint8_t buf[64]; /* https://github.com/httpwg/structured-field-tests/blob/main/dictionary.json @@ -2040,1697 +2041,1720 @@ void test_sf_parser_dictionary(void) { { /* basic dictionary */ - sf_parser_bytes_init(&sfp, "en=\"Applepie\", da=:w4ZibGV0w6ZydGUK:"); + sfparse_parser_bytes_init(&sfp, "en=\"Applepie\", da=:w4ZibGV0w6ZydGUK:"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("en", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("Applepie", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("en", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("Applepie", &val.vec); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("da", &key); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("w4ZibGV0w6ZydGUK", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("da", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("w4ZibGV0w6ZydGUK", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\xc3\x86" - "blet\xc3\xa6" - "rte\n", - &decoded); + assert_str_sfparse_vec_eq("\xc3\x86" + "blet\xc3\xa6" + "rte\n", + &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty dictionary */ - sf_parser_init(&sfp, (const uint8_t *)"", 0); + sfparse_parser_init(&sfp, (const uint8_t *)"", 0); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); } { /* single item dictionary */ - sf_parser_bytes_init(&sfp, "a=1"); + sfparse_parser_bytes_init(&sfp, "a=1"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* list item dictionary */ - sf_parser_bytes_init(&sfp, "a=(1 2)"); + sfparse_parser_bytes_init(&sfp, "a=(1 2)"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single list item dictionary */ - sf_parser_bytes_init(&sfp, "a=(1)"); + sfparse_parser_bytes_init(&sfp, "a=(1)"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty list item dictionary */ - sf_parser_bytes_init(&sfp, "a=()"); + sfparse_parser_bytes_init(&sfp, "a=()"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no whitespace dictionary */ - sf_parser_bytes_init(&sfp, "a=1,b=2"); + sfparse_parser_bytes_init(&sfp, "a=1,b=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace dictionary */ - sf_parser_bytes_init(&sfp, "a=1 , b=2"); + sfparse_parser_bytes_init(&sfp, "a=1 , b=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* tab separated dictionary */ - sf_parser_bytes_init(&sfp, "a=1\t,\tb=2"); + sfparse_parser_bytes_init(&sfp, "a=1\t,\tb=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* leading whitespace dictionary */ - sf_parser_bytes_init(&sfp, " a=1 , b=2"); + sfparse_parser_bytes_init(&sfp, " a=1 , b=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace before = dictionary */ - sf_parser_bytes_init(&sfp, "a =1, b=2"); + sfparse_parser_bytes_init(&sfp, "a =1, b=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after = dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b= 2"); + sfparse_parser_bytes_init(&sfp, "a=1, b= 2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* two lines dictionary */ - /* sf_parser does not support merging 2 lines */ + /* sfparse_parser does not support merging 2 lines */ { /* missing value dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b, c=3"); + sfparse_parser_bytes_init(&sfp, "a=1, b, c=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* all missing value dictionary */ - sf_parser_bytes_init(&sfp, "a, b, c"); + sfparse_parser_bytes_init(&sfp, "a, b, c"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* start missing value dictionary */ - sf_parser_bytes_init(&sfp, "a, b=2"); + sfparse_parser_bytes_init(&sfp, "a, b=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* end missing value dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b"); + sfparse_parser_bytes_init(&sfp, "a=1, b"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* missing value with params dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b;foo=9, c=3"); + sfparse_parser_bytes_init(&sfp, "a=1, b;foo=9, c=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("foo", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foo", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(9, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* explicit true value with params dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b=?1;foo=9, c=3"); + sfparse_parser_bytes_init(&sfp, "a=1, b=?1;foo=9, c=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("foo", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foo", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(9, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* trailing comma dictionary */ - sf_parser_bytes_init(&sfp, "a=1, b=2,"); + sfparse_parser_bytes_init(&sfp, "a=1, b=2,"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty item dictionary */ - sf_parser_bytes_init(&sfp, "a=1,,b=2,"); + sfparse_parser_bytes_init(&sfp, "a=1,,b=2,"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* duplicate key dictionary */ - /* sf_parser does no effort to find duplicates. */ - sf_parser_bytes_init(&sfp, "a=1,b=2,a=3"); + /* sfparse_parser does no effort to find duplicates. */ + sfparse_parser_bytes_init(&sfp, "a=1,b=2,a=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* numeric key dictionary */ - sf_parser_bytes_init(&sfp, "a=1,1b=2,a=1"); + sfparse_parser_bytes_init(&sfp, "a=1,1b=2,a=1"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* uppercase key dictionary */ - sf_parser_bytes_init(&sfp, "a=1,B=2,a=1"); + sfparse_parser_bytes_init(&sfp, "a=1,B=2,a=1"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* bad key dictionary */ - sf_parser_bytes_init(&sfp, "a=1,b!=2,a=1"); + sfparse_parser_bytes_init(&sfp, "a=1,b!=2,a=1"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* Empty value */ - sf_parser_bytes_init(&sfp, "a="); + sfparse_parser_bytes_init(&sfp, "a="); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_list(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_list(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/list.json */ { /* basic list */ - sf_parser_bytes_init(&sfp, "1, 42"); + sfparse_parser_bytes_init(&sfp, "1, 42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty list" */ - sf_parser_init(&sfp, (const uint8_t *)"", 0); + sfparse_parser_init(&sfp, (const uint8_t *)"", 0); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); } { /* leading SP list */ - sf_parser_bytes_init(&sfp, " 42, 43"); + sfparse_parser_bytes_init(&sfp, " 42, 43"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(43, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single item list */ - sf_parser_bytes_init(&sfp, "42"); + sfparse_parser_bytes_init(&sfp, "42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no whitespace list */ - sf_parser_bytes_init(&sfp, "1,42"); + sfparse_parser_bytes_init(&sfp, "1,42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace list */ - sf_parser_bytes_init(&sfp, "1 , 42"); + sfparse_parser_bytes_init(&sfp, "1 , 42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* tab separated list */ - sf_parser_bytes_init(&sfp, "1\t,\t42"); + sfparse_parser_bytes_init(&sfp, "1\t,\t42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* two line list */ - /* sf_parser does not support merging 2 lines */ + /* sfparse_parser does not support merging 2 lines */ { /* trailing comma list */ - sf_parser_bytes_init(&sfp, "1, 42,"); + sfparse_parser_bytes_init(&sfp, "1, 42,"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty item list */ - sf_parser_bytes_init(&sfp, "1,,42"); + sfparse_parser_bytes_init(&sfp, "1,,42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* empty item list (multiple field lines) */ - /* sf_parser does not support merging 2 lines */ + /* sfparse_parser does not support merging 2 lines */ } -void test_sf_parser_list_list(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_list_list(void) { + sfparse_parser sfp; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/listlist.json */ { /* basic list of lists */ - sf_parser_bytes_init(&sfp, "(1 2), (42 43)"); + sfparse_parser_bytes_init(&sfp, "(1 2), (42 43)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(43, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single item list of lists */ - sf_parser_bytes_init(&sfp, "(42)"); + sfparse_parser_bytes_init(&sfp, "(42)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty item list of lists" */ - sf_parser_bytes_init(&sfp, "()"); + sfparse_parser_bytes_init(&sfp, "()"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty middle item list of lists */ - sf_parser_bytes_init(&sfp, "(1),(),(42)"); + sfparse_parser_bytes_init(&sfp, "(1),(),(42)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace list of lists */ - sf_parser_bytes_init(&sfp, "( 1 42 )"); + sfparse_parser_bytes_init(&sfp, "( 1 42 )"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* wrong whitespace list of lists */ - sf_parser_bytes_init(&sfp, "(1\t 42)"); + sfparse_parser_bytes_init(&sfp, "(1\t 42)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no trailing parenthesis list of lists */ - sf_parser_bytes_init(&sfp, "(1 42"); + sfparse_parser_bytes_init(&sfp, "(1 42"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no trailing parenthesis middle list of lists */ - sf_parser_bytes_init(&sfp, "(1 2, (42 43)"); + sfparse_parser_bytes_init(&sfp, "(1 2, (42 43)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no spaces in inner-list */ - sf_parser_bytes_init(&sfp, "(abc\"def\"?0123*dXZ3*xyz)"); + sfparse_parser_bytes_init(&sfp, "(abc\"def\"?0123*dXZ3*xyz)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no closing parenthesis */ - sf_parser_bytes_init(&sfp, "("); + sfparse_parser_bytes_init(&sfp, "("); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* Just ')' */ - sf_parser_bytes_init(&sfp, ")"); + sfparse_parser_bytes_init(&sfp, ")"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_param_dict(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_param_dict(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/param-dict.json */ { /* basic parameterised dict */ - sf_parser_bytes_init(&sfp, - "abc=123;a=1;b=2, def=456, ghi=789;q=9;r=\"+w\""); + sfparse_parser_bytes_init(&sfp, + "abc=123;a=1;b=2, def=456, ghi=789;q=9;r=\"+w\""); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("abc", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("abc", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(123, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("def", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("def", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(456, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("ghi", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("ghi", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(789, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(9, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("r", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("+w", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("r", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("+w", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single item parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b; q=1.0"); + sfparse_parser_bytes_init(&sfp, "a=b; q=1.0"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* list item parameterised dictionary */ - sf_parser_bytes_init(&sfp, "a=(1 2); q=1.0"); + sfparse_parser_bytes_init(&sfp, "a=(1 2); q=1.0"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* missing parameter value parameterised dict */ - sf_parser_bytes_init(&sfp, "a=3;c;d=5"); + sfparse_parser_bytes_init(&sfp, "a=3;c;d=5"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("d", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("d", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* terminal missing parameter value parameterised dict */ - sf_parser_bytes_init(&sfp, "a=3;c=5;d"); + sfparse_parser_bytes_init(&sfp, "a=3;c=5;d"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("d", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("d", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no whitespace parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b;c=1,d=e;f=2"); + sfparse_parser_bytes_init(&sfp, "a=b;c=1,d=e;f=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("d", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("e", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("d", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("e", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("f", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("f", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace before = parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b;q =0.5"); + sfparse_parser_bytes_init(&sfp, "a=b;q =0.5"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after = parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b;q= 0.5"); + sfparse_parser_bytes_init(&sfp, "a=b;q= 0.5"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_param(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace before ; parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b ;q=0.5"); + sfparse_parser_bytes_init(&sfp, "a=b ;q=0.5"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after ; parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b; q=0.5"); + sfparse_parser_bytes_init(&sfp, "a=b; q=0.5"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(5, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace parameterised dict */ - sf_parser_bytes_init(&sfp, "a=b; c=1 , d=e; f=2; g=3"); + sfparse_parser_bytes_init(&sfp, "a=b; c=1 , d=e; f=2; g=3"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("d", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("e", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("d", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("e", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("f", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("f", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("g", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("g", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* two lines parameterised list */ - /* sf_parser does not support merging 2 lines */ + /* sfparse_parser does not support merging 2 lines */ { /* trailing comma parameterised list */ - sf_parser_bytes_init(&sfp, "a=b; q=1.0,"); + sfparse_parser_bytes_init(&sfp, "a=b; q=1.0,"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty item parameterised list */ - sf_parser_bytes_init(&sfp, "a=b; q=1.0,,c=d"); + sfparse_parser_bytes_init(&sfp, "a=b; q=1.0,,c=d"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* empty parameter value */ - sf_parser_bytes_init(&sfp, "a=b;c="); + sfparse_parser_bytes_init(&sfp, "a=b;c="); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("b", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("b", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_param(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_param_list(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_param_list(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/param-list.json */ { /* basic parameterised list */ - sf_parser_bytes_init(&sfp, "abc_123;a=1;b=2; cdef_456, ghi;q=9;r=\"+w\""); + sfparse_parser_bytes_init(&sfp, + "abc_123;a=1;b=2; cdef_456, ghi;q=9;r=\"+w\""); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc_123", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc_123", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("cdef_456", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("cdef_456", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("ghi", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("ghi", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(9, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("r", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("+w", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("r", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("+w", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* single item parameterised list */ - sf_parser_bytes_init(&sfp, "text/html;q=1.0"); + sfparse_parser_bytes_init(&sfp, "text/html;q=1.0"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* missing parameter value parameterised list */ - sf_parser_bytes_init(&sfp, "text/html;a;q=1.0"); + sfparse_parser_bytes_init(&sfp, "text/html;a;q=1.0"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* missing terminal parameter value parameterised list */ - sf_parser_bytes_init(&sfp, "text/html;q=1.0;a"); + sfparse_parser_bytes_init(&sfp, "text/html;q=1.0;a"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(10, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* no whitespace parameterised list */ - sf_parser_bytes_init(&sfp, "text/html,text/plain;q=0.5"); + sfparse_parser_bytes_init(&sfp, "text/html,text/plain;q=0.5"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(5, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace before = parameterised list */ - sf_parser_bytes_init(&sfp, "text/html, text/plain;q =0.5"); + sfparse_parser_bytes_init(&sfp, "text/html, text/plain;q =0.5"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after = parameterised list */ - sf_parser_bytes_init(&sfp, "text/html, text/plain;q= 0.5"); + sfparse_parser_bytes_init(&sfp, "text/html, text/plain;q= 0.5"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_param(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace before ; parameterised list */ - sf_parser_bytes_init(&sfp, "text/html, text/plain ;q=0.5"); + sfparse_parser_bytes_init(&sfp, "text/html, text/plain ;q=0.5"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* whitespace after ; parameterised list */ - sf_parser_bytes_init(&sfp, "text/html, text/plain; q=0.5"); + sfparse_parser_bytes_init(&sfp, "text/html, text/plain; q=0.5"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(5, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* extra whitespace parameterised list */ - sf_parser_bytes_init(&sfp, - "text/html , text/plain; q=0.5; charset=utf-8"); + sfparse_parser_bytes_init( + &sfp, "text/html , text/plain; q=0.5; charset=utf-8"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(5, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("charset", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("utf-8", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("charset", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("utf-8", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* two lines parameterised list */ - /* sf_parser does not support merging 2 lines */ + /* sfparse_parser does not support merging 2 lines */ { /* trailing comma parameterised list */ - sf_parser_bytes_init(&sfp, "text/html,text/plain;q=0.5,"); + sfparse_parser_bytes_init(&sfp, "text/html,text/plain;q=0.5,"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/plain", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/plain", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(5, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* empty item parameterised list */ - sf_parser_bytes_init(&sfp, "text/html,,text/plain;q=0.5,"); + sfparse_parser_bytes_init(&sfp, "text/html,,text/plain;q=0.5,"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("text/html", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("text/html", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* empty parameter value */ - sf_parser_bytes_init(&sfp, "a;b="); + sfparse_parser_bytes_init(&sfp, "a;b="); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_param(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_param_list_list(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_param_list_list(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; /* https://github.com/httpwg/structured-field-tests/blob/main/param-listlist.json */ { /* parameterised inner list */ - sf_parser_bytes_init(&sfp, "(abc_123);a=1;b=2, cdef_456"); + sfparse_parser_bytes_init(&sfp, "(abc_123);a=1;b=2, cdef_456"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc_123", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc_123", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("cdef_456", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("cdef_456", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* parameterised inner list item */ - sf_parser_bytes_init(&sfp, "(abc_123;a=1;b=2;cdef_456)"); + sfparse_parser_bytes_init(&sfp, "(abc_123;a=1;b=2;cdef_456)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc_123", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc_123", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("cdef_456", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("cdef_456", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* parameterised inner list with parameterised item */ - sf_parser_bytes_init(&sfp, "(abc_123;a=1;b=2);cdef_456"); + sfparse_parser_bytes_init(&sfp, "(abc_123;a=1;b=2);cdef_456"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc_123", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc_123", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("cdef_456", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("cdef_456", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Additional tests */ { /* empty parameter value */ - sf_parser_bytes_init(&sfp, "(a;b= 1)"); + sfparse_parser_bytes_init(&sfp, "(a;b= 1)"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_param(&sfp, &key, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_number_generated(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_number_generated(void) { + sfparse_parser sfp; + sfparse_value val; size_t len, i, j; size_t flen; const char digits[] = {'0', '1', '9'}; @@ -3747,13 +3771,13 @@ void test_sf_parser_number_generated(void) { integer = strtoll((char *)buf, NULL, 10); - sf_parser_bytes_len_init(&sfp, buf, len); + sfparse_parser_bytes_len_init(&sfp, buf, len); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(integer, ==, val.integer); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } @@ -3775,59 +3799,59 @@ void test_sf_parser_number_generated(void) { denom *= 10; } - sf_parser_bytes_len_init(&sfp, buf, len + 1 + flen); + sfparse_parser_bytes_len_init(&sfp, buf, len + 1 + flen); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(integer, ==, val.decimal.numer); assert_int64(denom, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } } { /* too many digit 0 decimal */ - sf_parser_bytes_init(&sfp, "000000000000000.0"); + sfparse_parser_bytes_init(&sfp, "000000000000000.0"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* too many fractional digits 0 decimal */ - sf_parser_bytes_init(&sfp, "000000000000.0000"); + sfparse_parser_bytes_init(&sfp, "000000000000.0000"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* too many digit 9 decimal */ - sf_parser_bytes_init(&sfp, "999999999999999.9"); + sfparse_parser_bytes_init(&sfp, "999999999999999.9"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* too many fractional digits 9 decimal */ - sf_parser_bytes_init(&sfp, "999999999999.9999"); + sfparse_parser_bytes_init(&sfp, "999999999999.9999"); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, &val)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_string_generated(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_string_generated(void) { + sfparse_parser sfp; + sfparse_value val; size_t i; uint8_t buf[64]; int rv; @@ -3842,26 +3866,26 @@ void test_sf_parser_string_generated(void) { buf[3] = ' '; buf[4] = '"'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); if (i == 0x20 || i == 0x21 || (0x23 <= i && i <= 0x5b) || (0x5d <= i && i <= 0x7e) || i == 0x22) { assert_int(0, ==, rv); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); if (i == 0x22) { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } else { - assert_int(SF_ERR_EOF, ==, rv); + assert_int(SFPARSE_ERR_EOF, ==, rv); } } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* Escaped 0x?? in string */ @@ -3873,25 +3897,25 @@ void test_sf_parser_string_generated(void) { buf[2] = (uint8_t)i; buf[3] = '"'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); if (i == '\\' || i == '"') { assert_int(0, ==, rv); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_token_generated(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_token_generated(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; size_t i; uint8_t buf[64]; int rv; @@ -3904,32 +3928,33 @@ void test_sf_parser_token_generated(void) { buf[1] = (uint8_t)i; buf[2] = 'a'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - assert_int(0, ==, sf_parser_item(&sfp, &val)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); if (is_token_char((uint8_t)i)) { - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); assert_size(3, ==, val.vec.len); assert_memory_equal(3, buf, val.vec.base); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); } else { - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); if (i == ';') { - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, &key, &val)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, &val)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_item(&sfp, NULL)); } } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* 0x?? starting a token */ @@ -3939,45 +3964,46 @@ void test_sf_parser_token_generated(void) { buf[0] = (uint8_t)i; buf[1] = 'a'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); if (is_first_token_char((uint8_t)i)) { assert_int(0, ==, rv); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); assert_size(2, ==, val.vec.len); assert_memory_equal(2, buf, val.vec.base); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); } else if (i == ' ') { assert_int(0, ==, rv); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); } else if ('0' <= i && i <= '9') { assert_int(0, ==, rv); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64((int64_t)(i - '0'), ==, val.integer); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_item(&sfp, NULL)); } else if (i == '(') { assert_int(0, ==, rv); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_inner_list(&sfp, NULL)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_inner_list(&sfp, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_key_generated(void) { - sf_parser sfp; - sf_vec key; - sf_value val; +void test_sfparse_parser_key_generated(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; size_t i; uint8_t buf[64]; int rv; @@ -3991,22 +4017,22 @@ void test_sf_parser_key_generated(void) { buf[1] = '='; buf[2] = '1'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (('a' <= i && i <= 'z') || i == '*') { assert_int(0, ==, rv); assert_size(1, ==, key.len); assert_uint8((uint8_t)i, ==, key.base[0]); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* 0x?? in dictionary key */ @@ -4019,48 +4045,50 @@ void test_sf_parser_key_generated(void) { buf[3] = '='; buf[4] = '1'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (is_key_char((uint8_t)i)) { assert_int(0, ==, rv); assert_size(3, ==, key.len); assert_memory_equal(3, buf, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else if (i == '=') { assert_int(0, ==, rv); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, NULL, NULL)); } else { assert_int(0, ==, rv); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); if (i == ',') { - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else if (i == ';') { - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_dict(&sfp, NULL, NULL)); } } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* 0x?? starting a dictionary key */ @@ -4072,28 +4100,28 @@ void test_sf_parser_key_generated(void) { buf[2] = '='; buf[3] = '1'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_dict(&sfp, &key, &val); + rv = sfparse_parser_dict(&sfp, &key, &val); if (is_first_key_char((uint8_t)i)) { assert_int(0, ==, rv); assert_size(2, ==, key.len); assert_memory_equal(2, buf, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else if (i == ' ') { assert_int(0, ==, rv); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* 0x?? in parameterised list key */ @@ -4103,56 +4131,57 @@ void test_sf_parser_key_generated(void) { len = snprintf((char *)buf, sizeof(buf), "foo; a%ca=1", (char)i); buf[len] = ' '; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); if (is_key_char((uint8_t)i)) { assert_size(3, ==, key.len); assert_memory_equal(3, buf + 5, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); } else if (i == '=') { - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, NULL)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, sfparse_parser_list(&sfp, NULL)); } else { - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); if (i == ';') { - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); } else { - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - rv = sf_parser_list(&sfp, &val); + rv = sfparse_parser_list(&sfp, &val); if (i == ',') { assert_int(0, ==, rv); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("a", &val.vec); - assert_int(SF_ERR_PARSE_ERROR, ==, sf_parser_list(&sfp, NULL)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("a", &val.vec); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, + sfparse_parser_list(&sfp, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } } } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } /* 0x?? starting a parameterised list key */ @@ -4162,40 +4191,40 @@ void test_sf_parser_key_generated(void) { len = snprintf((char *)buf, sizeof(buf), "foo; %ca=1", (char)i); buf[len] = ' '; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); - rv = sf_parser_param(&sfp, &key, &val); + rv = sfparse_parser_param(&sfp, &key, &val); if (is_first_key_char((uint8_t)i)) { assert_int(0, ==, rv); assert_size(2, ==, key.len); assert_memory_equal(2, buf + 5, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); } else if (i == ' ') { assert_int(0, ==, rv); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_byteseq_generated(void) { - sf_parser sfp; - sf_value val; +void test_sfparse_parser_byteseq_generated(void) { + sfparse_parser sfp; + sfparse_value val; size_t i; uint8_t buf[64]; int rv; @@ -4211,30 +4240,30 @@ void test_sf_parser_byteseq_generated(void) { buf[4] = 'h'; buf[5] = ':'; - sf_parser_bytes_len_init(&sfp, buf, sizeof(buf)); + sfparse_parser_bytes_len_init(&sfp, buf, sizeof(buf)); - rv = sf_parser_item(&sfp, &val); + rv = sfparse_parser_item(&sfp, &val); if (i == '+' || i == '/' || ('0' <= i && i <= '9') || ('A' <= i && i <= 'Z') || ('a' <= i && i <= 'z')) { assert_int(0, ==, rv); - rv = sf_parser_item(&sfp, NULL); + rv = sfparse_parser_item(&sfp, NULL); - assert_int(SF_ERR_EOF, ==, rv); + assert_int(SFPARSE_ERR_EOF, ==, rv); } else { - assert_int(SF_ERR_PARSE_ERROR, ==, rv); + assert_int(SFPARSE_ERR_PARSE_ERROR, ==, rv); } - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_large_generated(void) { - sf_parser sfp; - sf_vec key; - sf_value val; - sf_vec unescaped; +void test_sfparse_parser_large_generated(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; + sfparse_vec unescaped; uint8_t buf[16384], sbuf[16]; uint8_t *p; size_t i; @@ -4252,38 +4281,38 @@ void test_sf_parser_large_generated(void) { len = (int)(p - buf - 2); - sf_parser_bytes_len_init(&sfp, buf, (size_t)len); + sfparse_parser_bytes_len_init(&sfp, buf, (size_t)len); for (i = 0; i < 1024; ++i) { - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); len = snprintf((char *)sbuf, sizeof(sbuf), "a%d", (int)i); assert_size((size_t)len, ==, key.len); assert_memory_equal((size_t)len, sbuf, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); } - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* large dictionary key */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=1"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { @@ -4298,21 +4327,21 @@ void test_sf_parser_large_generated(void) { len = (int)(p - buf - 2); - sf_parser_bytes_len_init(&sfp, buf, (size_t)len); + sfparse_parser_bytes_len_init(&sfp, buf, (size_t)len); for (i = 0; i < 1024; ++i) { - assert_int(0, ==, sf_parser_list(&sfp, &val)); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); len = snprintf((char *)sbuf, sizeof(sbuf), "a%d", (int)i); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); assert_size((size_t)len, ==, val.vec.len); assert_memory_equal((size_t)len, sbuf, val.vec.base); } - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { @@ -4327,26 +4356,26 @@ void test_sf_parser_large_generated(void) { len = (int)(p - buf - 2); - sf_parser_bytes_len_init(&sfp, buf, (size_t)len); + sfparse_parser_bytes_len_init(&sfp, buf, (size_t)len); for (i = 0; i < 1024; ++i) { - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); len = snprintf((char *)sbuf, sizeof(sbuf), "a%d", (int)i); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); assert_size((size_t)len, ==, key.len); assert_memory_equal((size_t)len, sbuf, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); } - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { @@ -4365,56 +4394,56 @@ void test_sf_parser_large_generated(void) { len = (int)(p - buf); - sf_parser_bytes_len_init(&sfp, buf, (size_t)len); + sfparse_parser_bytes_len_init(&sfp, buf, (size_t)len); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); for (i = 0; i < 1024; ++i) { len = snprintf((char *)sbuf, sizeof(sbuf), "a%d", (int)i); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); assert_size((size_t)len, ==, key.len); assert_memory_equal((size_t)len, sbuf, key.base); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); } - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* large param key */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "foo;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=" "1"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* large string */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "\"====================================================================" "======================================================================" @@ -4432,9 +4461,9 @@ void test_sf_parser_large_generated(void) { "======================================================================" "==============================================\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq( "======================================================================" "======================================================================" "======================================================================" @@ -4451,14 +4480,14 @@ void test_sf_parser_large_generated(void) { "======================================================================" "============================================", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* large escaped string */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"" "\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\" @@ -4520,14 +4549,14 @@ void test_sf_parser_large_generated(void) { "\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\" "\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\\\"\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_true(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_true(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); unescaped.base = buf; - sf_unescape(&unescaped, &val.vec); + sfparse_unescape(&unescaped, &val.vec); - assert_str_sf_vec_eq( + assert_str_sfparse_vec_eq( "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" @@ -4559,14 +4588,14 @@ void test_sf_parser_large_generated(void) { "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" "\"\"\"\"\"\"\"\"\"", &unescaped); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* large token */ - sf_parser_bytes_init( + sfparse_parser_bytes_init( &sfp, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -4577,9 +4606,9 @@ void test_sf_parser_large_generated(void) { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaa"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq( + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -4589,520 +4618,520 @@ void test_sf_parser_large_generated(void) { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaa", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } -void test_sf_parser_examples(void) { - sf_parser sfp; - sf_vec key; - sf_value val; - sf_vec decoded; +void test_sfparse_parser_examples(void) { + sfparse_parser sfp; + sfparse_vec key; + sfparse_value val; + sfparse_vec decoded; uint8_t buf[64]; /* https://github.com/httpwg/structured-field-tests/blob/main/examples.json */ { /* Foo-Example */ - sf_parser_bytes_init(&sfp, "2; foourl=\"https://foo.example.com/\""); + sfparse_parser_bytes_init(&sfp, "2; foourl=\"https://foo.example.com/\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("foourl", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_false(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); - assert_str_sf_vec_eq("https://foo.example.com/", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foourl", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_false(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); + assert_str_sfparse_vec_eq("https://foo.example.com/", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-StrListHeader */ - sf_parser_bytes_init(&sfp, - "\"foo\", \"bar\", \"It was the best of times.\""); + sfparse_parser_bytes_init( + &sfp, "\"foo\", \"bar\", \"It was the best of times.\""); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_false(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_false(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); + assert_str_sfparse_vec_eq("foo", &val.vec); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_false(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); - assert_str_sf_vec_eq("bar", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_false(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); + assert_str_sfparse_vec_eq("bar", &val.vec); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_false(val.flags & SF_VALUE_FLAG_ESCAPED_STRING); - assert_str_sf_vec_eq("It was the best of times.", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_false(val.flags & SFPARSE_VALUE_FLAG_ESCAPED_STRING); + assert_str_sfparse_vec_eq("It was the best of times.", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-StrListListHeader */ - sf_parser_bytes_init(&sfp, - "(\"foo\" \"bar\"), (\"baz\"), (\"bat\" \"one\"), ()"); + sfparse_parser_bytes_init( + &sfp, "(\"foo\" \"bar\"), (\"baz\"), (\"bat\" \"one\"), ()"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("bar", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("bar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("baz", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("baz", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("bat", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("bat", &val.vec); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("one", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("one", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-ListListParam */ - sf_parser_bytes_init(&sfp, - "(\"foo\"; a=1;b=2);lvl=5, (\"bar\" \"baz\");lvl=1"); + sfparse_parser_bytes_init( + &sfp, "(\"foo\"; a=1;b=2);lvl=5, (\"bar\" \"baz\");lvl=1"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("foo", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("foo", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("lvl", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("lvl", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("bar", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("bar", &val.vec); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("baz", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("baz", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, &val)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, &val)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("lvl", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("lvl", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-ParamListHeader */ - sf_parser_bytes_init(&sfp, - "abc;a=1;b=2; cde_456, (ghi;jk=4 l);q=\"9\";r=w"); + sfparse_parser_bytes_init(&sfp, + "abc;a=1;b=2; cde_456, (ghi;jk=4 l);q=\"9\";r=w"); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("abc", &val.vec); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("abc", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("cde_456", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("cde_456", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(0, ==, sf_parser_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("ghi", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("ghi", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("jk", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("jk", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(4, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("l", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("l", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("q", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("9", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("q", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("9", &val.vec); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("r", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("w", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("r", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("w", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_list(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-IntHeader */ - sf_parser_bytes_init(&sfp, "1; a; b=?0"); + sfparse_parser_bytes_init(&sfp, "1; a; b=?0"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_false(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-DictHeader */ - sf_parser_bytes_init(&sfp, "en=\"Applepie\", da=:w4ZibGV0w6ZydGU=:"); + sfparse_parser_bytes_init(&sfp, "en=\"Applepie\", da=:w4ZibGV0w6ZydGU=:"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("en", &key); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("Applepie", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("en", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("Applepie", &val.vec); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("da", &key); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("w4ZibGV0w6ZydGU=", &val.vec); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("da", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("w4ZibGV0w6ZydGU=", &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("\xc3\x86" - "blet\xc3\xa6" - "rte", - &decoded); + assert_str_sfparse_vec_eq("\xc3\x86" + "blet\xc3\xa6" + "rte", + &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-DictHeader (boolean values) */ - sf_parser_bytes_init(&sfp, "a=?0, b, c; foo=bar"); + sfparse_parser_bytes_init(&sfp, "a=?0, b, c; foo=bar"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_false(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("foo", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("bar", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foo", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("bar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-DictListHeader */ - sf_parser_bytes_init(&sfp, "rating=1.5, feelings=(joy sadness)"); + sfparse_parser_bytes_init(&sfp, "rating=1.5, feelings=(joy sadness)"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("rating", &key); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("rating", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(15, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("feelings", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("feelings", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("joy", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("joy", &val.vec); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("sadness", &val.vec); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("sadness", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-MixDict */ - sf_parser_bytes_init(&sfp, "a=(1 2), b=3, c=4;aa=bb, d=(5 6);valid"); + sfparse_parser_bytes_init(&sfp, "a=(1 2), b=3, c=4;aa=bb, d=(5 6);valid"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("a", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("a", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("b", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("b", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(3, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("c", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("c", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(4, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("aa", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("bb", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("aa", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("bb", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("d", &key); - assert_enum(sf_type, SF_TYPE_INNER_LIST, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("d", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INNER_LIST, ==, val.type); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(0, ==, sf_parser_inner_list(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_inner_list(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(6, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_inner_list(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_inner_list(&sfp, NULL)); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("valid", &key); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("valid", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-Hdr (dictionary on one line) */ - sf_parser_bytes_init(&sfp, "foo=1, bar=2"); + sfparse_parser_bytes_init(&sfp, "foo=1, bar=2"); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("foo", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foo", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(1, ==, val.integer); - assert_int(0, ==, sf_parser_dict(&sfp, &key, &val)); - assert_str_sf_vec_eq("bar", &key); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_dict(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("bar", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(2, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_dict(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_dict(&sfp, NULL, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-IntItemHeader */ - sf_parser_bytes_init(&sfp, "5"); + sfparse_parser_bytes_init(&sfp, "5"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-IntItemHeader (params) */ - sf_parser_bytes_init(&sfp, "5; foo=bar"); + sfparse_parser_bytes_init(&sfp, "5; foo=bar"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(5, ==, val.integer); - assert_int(0, ==, sf_parser_param(&sfp, &key, &val)); - assert_str_sf_vec_eq("foo", &key); - assert_enum(sf_type, SF_TYPE_TOKEN, ==, val.type); - assert_str_sf_vec_eq("bar", &val.vec); + assert_int(0, ==, sfparse_parser_param(&sfp, &key, &val)); + assert_str_sfparse_vec_eq("foo", &key); + assert_enum(sfparse_type, SFPARSE_TYPE_TOKEN, ==, val.type); + assert_str_sfparse_vec_eq("bar", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_param(&sfp, NULL, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_param(&sfp, NULL, NULL)); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-IntegerHeader */ - sf_parser_bytes_init(&sfp, "42"); + sfparse_parser_bytes_init(&sfp, "42"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_INTEGER, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_INTEGER, ==, val.type); assert_int64(42, ==, val.integer); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-FloatHeader */ - sf_parser_bytes_init(&sfp, "4.5"); + sfparse_parser_bytes_init(&sfp, "4.5"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_DECIMAL, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_DECIMAL, ==, val.type); assert_int64(45, ==, val.decimal.numer); assert_int64(10, ==, val.decimal.denom); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-StringHeader */ - sf_parser_bytes_init(&sfp, "\"hello world\""); + sfparse_parser_bytes_init(&sfp, "\"hello world\""); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_STRING, ==, val.type); - assert_str_sf_vec_eq("hello world", &val.vec); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_STRING, ==, val.type); + assert_str_sfparse_vec_eq("hello world", &val.vec); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-BinaryHdr */ - sf_parser_bytes_init(&sfp, - ":cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:"); + sfparse_parser_bytes_init(&sfp, + ":cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BYTESEQ, ==, val.type); - assert_str_sf_vec_eq("cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==", - &val.vec); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BYTESEQ, ==, val.type); + assert_str_sfparse_vec_eq("cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==", + &val.vec); decoded.base = buf; - sf_base64decode(&decoded, &val.vec); + sfparse_base64decode(&decoded, &val.vec); - assert_str_sf_vec_eq("pretend this is binary content.", &decoded); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_str_sfparse_vec_eq("pretend this is binary content.", &decoded); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } { /* Example-BoolHdr */ - sf_parser_bytes_init(&sfp, "?1"); + sfparse_parser_bytes_init(&sfp, "?1"); - assert_int(0, ==, sf_parser_item(&sfp, &val)); - assert_enum(sf_type, SF_TYPE_BOOLEAN, ==, val.type); + assert_int(0, ==, sfparse_parser_item(&sfp, &val)); + assert_enum(sfparse_type, SFPARSE_TYPE_BOOLEAN, ==, val.type); assert_true(val.boolean); - assert_int(SF_ERR_EOF, ==, sf_parser_item(&sfp, NULL)); + assert_int(SFPARSE_ERR_EOF, ==, sfparse_parser_item(&sfp, NULL)); - sf_parser_bytes_free(); + sfparse_parser_bytes_free(); } } diff --git a/sfparse_test.h b/sfparse_test.h index e41bab0..2ebd7ba 100644 --- a/sfparse_test.h +++ b/sfparse_test.h @@ -31,28 +31,28 @@ extern const MunitSuite sfparse_suite; -munit_void_test_decl(test_sf_parser_item_skip) -munit_void_test_decl(test_sf_parser_dict_skip) -munit_void_test_decl(test_sf_parser_list_skip) -munit_void_test_decl(test_sf_parser_byteseq) -munit_void_test_decl(test_sf_parser_boolean) -munit_void_test_decl(test_sf_parser_number) -munit_void_test_decl(test_sf_parser_date) -munit_void_test_decl(test_sf_parser_string) -munit_void_test_decl(test_sf_parser_token) -munit_void_test_decl(test_sf_parser_dispstring) -munit_void_test_decl(test_sf_parser_dictionary) -munit_void_test_decl(test_sf_parser_list) -munit_void_test_decl(test_sf_parser_list_list) -munit_void_test_decl(test_sf_parser_param_dict) -munit_void_test_decl(test_sf_parser_param_list) -munit_void_test_decl(test_sf_parser_param_list_list) -munit_void_test_decl(test_sf_parser_number_generated) -munit_void_test_decl(test_sf_parser_string_generated) -munit_void_test_decl(test_sf_parser_token_generated) -munit_void_test_decl(test_sf_parser_key_generated) -munit_void_test_decl(test_sf_parser_byteseq_generated) -munit_void_test_decl(test_sf_parser_large_generated) -munit_void_test_decl(test_sf_parser_examples) +munit_void_test_decl(test_sfparse_parser_item_skip) +munit_void_test_decl(test_sfparse_parser_dict_skip) +munit_void_test_decl(test_sfparse_parser_list_skip) +munit_void_test_decl(test_sfparse_parser_byteseq) +munit_void_test_decl(test_sfparse_parser_boolean) +munit_void_test_decl(test_sfparse_parser_number) +munit_void_test_decl(test_sfparse_parser_date) +munit_void_test_decl(test_sfparse_parser_string) +munit_void_test_decl(test_sfparse_parser_token) +munit_void_test_decl(test_sfparse_parser_dispstring) +munit_void_test_decl(test_sfparse_parser_dictionary) +munit_void_test_decl(test_sfparse_parser_list) +munit_void_test_decl(test_sfparse_parser_list_list) +munit_void_test_decl(test_sfparse_parser_param_dict) +munit_void_test_decl(test_sfparse_parser_param_list) +munit_void_test_decl(test_sfparse_parser_param_list_list) +munit_void_test_decl(test_sfparse_parser_number_generated) +munit_void_test_decl(test_sfparse_parser_string_generated) +munit_void_test_decl(test_sfparse_parser_token_generated) +munit_void_test_decl(test_sfparse_parser_key_generated) +munit_void_test_decl(test_sfparse_parser_byteseq_generated) +munit_void_test_decl(test_sfparse_parser_large_generated) +munit_void_test_decl(test_sfparse_parser_examples) #endif /* !defined(SFPARSE_TEST_H) */