allow h_whitespace(p) to succeed on end of input if p succeeds

This commit is contained in:
Sven M. Hallberg 2013-01-09 14:48:02 +01:00
parent ad4aa74b85
commit 2bc03e4e9f
2 changed files with 6 additions and 1 deletions

View file

@ -8,7 +8,7 @@ static HParseResult* parse_whitespace(void* env, HParseState *state) {
bak = state->input_stream;
c = h_read_bits(&state->input_stream, 8, false);
if (state->input_stream.overrun)
return NULL;
break;
} while (isspace(c));
state->input_stream = bak;
return h_do_parse((HParser*)env, state);

View file

@ -110,12 +110,17 @@ static void test_float32(void) {
static void test_whitespace(void) {
const HParser *whitespace_ = h_whitespace(h_ch('a'));
const HParser *whitespace_end = h_whitespace(h_end_p());
g_check_parse_ok(whitespace_, "a", 1, "u0x61");
g_check_parse_ok(whitespace_, " a", 2, "u0x61");
g_check_parse_ok(whitespace_, " a", 3, "u0x61");
g_check_parse_ok(whitespace_, "\ta", 2, "u0x61");
g_check_parse_failed(whitespace_, "_a", 2);
g_check_parse_ok(whitespace_end, "", 0, "NULL");
g_check_parse_ok(whitespace_end, " ", 2, "NULL");
g_check_parse_failed(whitespace_end, " x", 3);
}
static void test_left(void) {