Implement an accept function accepts if next character doesn't match some provided character
This makes it easy to do something like "accept until".
This commit is contained in:
parent
d782d21108
commit
e8fd813a2e
|
@ -59,6 +59,7 @@ typedef bool hb_proc_pred(hb_rune);
|
|||
hb_rune hb_proc_accept(hb_proc* proc);
|
||||
void hb_proc_accept_count(hb_proc* proc, size_t count);
|
||||
bool hb_proc_accept_if(hb_proc* proc, hb_rune c);
|
||||
bool hb_proc_accept_if_not(hb_proc* proc, hb_rune c);
|
||||
size_t hb_proc_accept_if_matches(hb_proc* proc, char const* match);
|
||||
size_t hb_proc_accept_if_matches_line_terminator(hb_proc* proc);
|
||||
bool hb_proc_accept_if_predicate(hb_proc* proc, hb_proc_pred* pred);
|
||||
|
|
|
@ -63,6 +63,28 @@ bool hb_proc_accept_if(hb_proc* proc, hb_rune c) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the following character if it is not `c`.
|
||||
* Won't match or cause an error if there are no characters remaining.
|
||||
* Undefined behaviour if `c == HB_EOF`.
|
||||
*
|
||||
* @param proc proc
|
||||
* @param c character to not match
|
||||
* @return false if nothing was accepted, true otherwise
|
||||
*/
|
||||
bool hb_proc_accept_if_not(hb_proc* proc, hb_rune c) {
|
||||
hb_eof_rune n = hb_proc_peek_eof(proc);
|
||||
|
||||
// n == c takes care of n != HB_EOF
|
||||
if (n == c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hb_proc_accept(proc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the following characters if they match `match`.
|
||||
* Won't match or cause an error if there are not enough characters remaining.
|
||||
|
|
Loading…
Reference in New Issue