generic circular buffer implementation in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
circbuf/matcher/matcher.c

34 lines
605 B

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "matcher.h"
void matcher_reset(matcher_t *m)
{
m->cursor = 0;
}
/** Handle incoming char. Returns true if this char completed the match. */
bool matcher_test(matcher_t * m, uint8_t b)
{
// If mismatch, rewind (and check at 0)
if (m->pattern[m->cursor] != b) {
m->cursor = 0;
}
// Check for match
if (m->pattern[m->cursor] == b) {
// Good char
m->cursor++;
if (m->pattern[m->cursor] == 0) { // end of pattern
m->cursor = 0; // rewind
return true; // indicate success
}
}
return false;
}