|
|
@@ -63,9 +63,9 @@ namespace codedweller { |
|
|
|
} |
|
|
|
|
|
|
|
template <class D, class T> |
|
|
|
void compute(D data, bool caseSensitive, T& matcher, T& masker) { |
|
|
|
size_t ingest = std::min(sizeof(matcher.value()), data.size()); |
|
|
|
for(size_t count = 0; count < ingest; count++) { |
|
|
|
void compute(D data, bool caseSensitive, T& matcher, T& masker, size_t& matchLength) { |
|
|
|
matchLength = std::min(sizeof(matcher.value()), data.size()); |
|
|
|
for(size_t count = 0; count < matchLength; count++) { |
|
|
|
unsigned char theByte = data.at(count); |
|
|
|
matcher.add(roller::applyCaseSensitivity(theByte, caseSensitive)); |
|
|
|
masker.add(roller::appropriateBitMask(theByte, caseSensitive)); |
|
|
@@ -77,18 +77,19 @@ namespace codedweller { |
|
|
|
private: |
|
|
|
uint_fast32_t match; |
|
|
|
uint_fast32_t mask; |
|
|
|
size_t matchLength; |
|
|
|
|
|
|
|
public: |
|
|
|
RollerMatch32(const std::vector<unsigned char> pattern, bool caseSensitive=true) { |
|
|
|
Roller32 matcher, masker; |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker); |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker, matchLength); |
|
|
|
match = matcher.value(); |
|
|
|
mask = masker.value(); |
|
|
|
} |
|
|
|
|
|
|
|
RollerMatch32(const std::string pattern, bool caseSensitive=true) { |
|
|
|
Roller32 matcher, masker; |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker); |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker, matchLength); |
|
|
|
match = matcher.value(); |
|
|
|
mask = masker.value(); |
|
|
|
} |
|
|
@@ -97,24 +98,26 @@ namespace codedweller { |
|
|
|
return (match == (roller.value() & mask)); |
|
|
|
} |
|
|
|
|
|
|
|
size_t offset() { return matchLength; } |
|
|
|
}; |
|
|
|
|
|
|
|
class RollerMatch64 { |
|
|
|
private: |
|
|
|
uint_fast64_t match; |
|
|
|
uint_fast64_t mask; |
|
|
|
size_t matchLength; |
|
|
|
|
|
|
|
public: |
|
|
|
RollerMatch64(const std::vector<unsigned char> pattern, bool caseSensitive=true) { |
|
|
|
Roller64 matcher, masker; |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker); |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker, matchLength); |
|
|
|
match = matcher.value(); |
|
|
|
mask = masker.value(); |
|
|
|
} |
|
|
|
|
|
|
|
RollerMatch64(const std::string pattern, bool caseSensitive=true) { |
|
|
|
Roller64 matcher, masker; |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker); |
|
|
|
roller::compute(pattern, caseSensitive, matcher, masker, matchLength); |
|
|
|
match = matcher.value(); |
|
|
|
mask = masker.value(); |
|
|
|
} |
|
|
@@ -122,6 +125,8 @@ namespace codedweller { |
|
|
|
bool matches(const Roller64 roller) { |
|
|
|
return (match == (roller.value() & mask)); |
|
|
|
} |
|
|
|
|
|
|
|
size_t offset() { return matchLength; } |
|
|
|
}; |
|
|
|
} |
|
|
|
|