add fuzzy search

This commit is contained in:
yihaoDeng 2022-03-31 14:45:26 +08:00
parent 9da56a412a
commit aae1ba31ac
2 changed files with 28 additions and 0 deletions

View File

@ -63,6 +63,10 @@ typedef struct {
FstRegex *regexCreate(const char *str);
uint32_t regexAutomStart(FstRegex *regex);
bool regexAutomIsMatch(FstRegex *regex, uint32_t state);
bool regexAutomCanMatch(FstRegex *regex, uint32_t state, bool null);
bool regexAutomAccept(FstRegex *regex, uint32_t state, uint8_t byte, uint32_t *result);
// void regexSetup(FstRegex *regex, uint32_t size, const char *str);
// uint32_t regexStart()

View File

@ -35,3 +35,27 @@ FstRegex *regexCreate(const char *str) {
regex->dfa = dfaBuilderBuild(builder);
return regex;
}
uint32_t regexAutomStart(FstRegex *regex) {
///// no nothing
return 0;
}
bool regexAutomIsMatch(FstRegex *regex, uint32_t state) {
if (regex->dfa != NULL && dfaIsMatch(regex->dfa, state)) {
return true;
} else {
return false;
}
}
bool regexAutomCanMatch(FstRegex *regex, uint32_t state, bool null) {
// make frame happy
return null;
}
bool regexAutomAccept(FstRegex *regex, uint32_t state, uint8_t byte, uint32_t *result) {
if (regex->dfa == NULL) {
return false;
}
return dfaAccept(regex->dfa, state, byte, result);
}