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.
28 lines
551 B
28 lines
551 B
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "matcher.h"
|
|
|
|
|
|
/** 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;
|
|
}
|
|
|