From bc486aa8401a0e5b23c0c3cd1c253ca6a3480e3b Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Tue, 8 Jan 2013 00:19:23 +0100 Subject: [PATCH 1/3] fix base64 example to parse more than the 2- and 1-byte special cases --- examples/base64.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/base64.c b/examples/base64.c index beb2484..8ebe77b 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -19,9 +19,13 @@ void init_parser(void) h_ch('Y'), h_ch('c'), h_ch('g'), h_ch('k'), h_ch('o'), h_ch('s'), h_ch('w'), h_ch('0'), h_ch('4'), h_ch('8'), NULL); const HParser *bsfdig_2bit = h_choice(h_ch('A'), h_ch('Q'), h_ch('g'), h_ch('w'), NULL); + const HParser *base64_3 = h_repeat_n(bsfdig, 4); const HParser *base64_2 = h_sequence(bsfdig, bsfdig, bsfdig_4bit, equals, NULL); const HParser *base64_1 = h_sequence(bsfdig, bsfdig_2bit, equals, equals, NULL); - const HParser *base64 = h_choice(base64_2, base64_1, NULL); + const HParser *base64 = h_sequence(h_many(base64_3), + h_optional(h_choice(base64_2, + base64_1, NULL)), + NULL); // why does this parse "A=="?! // why does this parse "aaA=" but not "aA=="?! From 87b5e668c327d55781b8960df59a0c5a177b56ee Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Tue, 8 Jan 2013 00:20:34 +0100 Subject: [PATCH 2/3] remove comments about bugs that no longer exist --- examples/base64.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/base64.c b/examples/base64.c index 8ebe77b..7692532 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -26,8 +26,6 @@ void init_parser(void) h_optional(h_choice(base64_2, base64_1, NULL)), NULL); - // why does this parse "A=="?! - // why does this parse "aaA=" but not "aA=="?! document = base64; } From 177281289c45c8021fd256190f1be009feabd2b9 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Tue, 8 Jan 2013 00:24:13 +0100 Subject: [PATCH 3/3] use h_in for restricted base64 digit cases --- examples/base64.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/base64.c b/examples/base64.c index 7692532..6c4db9e 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -14,11 +14,8 @@ void init_parser(void) const HParser *equals = h_ch('='); const HParser *bsfdig = h_choice(alpha, digit, plus, slash, NULL); - const HParser *bsfdig_4bit = h_choice( - h_ch('A'), h_ch('E'), h_ch('I'), h_ch('M'), h_ch('Q'), h_ch('U'), - h_ch('Y'), h_ch('c'), h_ch('g'), h_ch('k'), h_ch('o'), h_ch('s'), - h_ch('w'), h_ch('0'), h_ch('4'), h_ch('8'), NULL); - const HParser *bsfdig_2bit = h_choice(h_ch('A'), h_ch('Q'), h_ch('g'), h_ch('w'), NULL); + const HParser *bsfdig_4bit = h_in((uint8_t *)"AEIMQUYcgkosw048", 16); + const HParser *bsfdig_2bit = h_in((uint8_t *)"AQgw", 4); const HParser *base64_3 = h_repeat_n(bsfdig, 4); const HParser *base64_2 = h_sequence(bsfdig, bsfdig, bsfdig_4bit, equals, NULL); const HParser *base64_1 = h_sequence(bsfdig, bsfdig_2bit, equals, equals, NULL);