Fix bug in detecting text in MenuSearch

A bug sneaked into my implementation of Boyer-Moore-Horspool. This lead
to not finding certain patterns. Given the text 'abcdde' and the pattern
'dd', the faulty implementation would not find 'dd':

1. 'ab' does not match, skip 2 (length of pattern)
2. 'cd' does not match, skip 2 (length of pattern) <- the bug.
3. 'de' does not match, end of string

The bug in step 2 is to not use 'd' to detect how far to skip but to
use 'c' (which is not in the skip-table) and thus 2 bytes are skipped).
This commit is contained in:
Mathias Gumz 2015-05-02 14:04:50 +02:00
parent e117f5acd6
commit 533c9a2aa5

View file

@ -75,7 +75,7 @@ size_t search_str_bmh(const std::string& text, const std::string& pattern) {
return t+p;
}
}
t += skip[std::tolower(text[t+p])];
t += skip[std::tolower(text[t+plast])];
}
return std::string::npos;