wrap all allocs of HParser in helper h_new_parser

This commit is contained in:
Sven M. Hallberg 2013-04-27 04:17:47 +02:00
parent 3dfc313118
commit 88091b602f
23 changed files with 44 additions and 113 deletions

View file

@ -33,27 +33,21 @@ const HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {
return h_ch_range__m(&system_allocator, lower, upper);
}
const HParser* h_ch_range__m(HAllocator* mm__, const uint8_t lower, const uint8_t upper) {
HParser *ret = h_new(HParser, 1);
HCharset cs = new_charset(mm__);
for (int i = 0; i < 256; i++)
charset_set(cs, i, (lower <= i) && (i <= upper));
ret->vtable = &charset_vt;
ret->env = (void*)cs;
return (const HParser*)ret;
return h_new_parser(mm__, &charset_vt, cs);
}
static const HParser* h_in_or_not__m(HAllocator* mm__, const uint8_t *options, size_t count, int val) {
HParser *ret = h_new(HParser, 1);
HCharset cs = new_charset(mm__);
for (size_t i = 0; i < 256; i++)
charset_set(cs, i, 1-val);
for (size_t i = 0; i < count; i++)
charset_set(cs, options[i], val);
ret->vtable = &charset_vt;
ret->env = (void*)cs;
return (const HParser*)ret;
return h_new_parser(mm__, &charset_vt, cs);
}
const HParser* h_in(const uint8_t *options, size_t count) {