Browse Source

implemented rollerMatch offset()

master
Pete McNeil 2 years ago
parent
commit
ec3e973066
1 changed files with 12 additions and 7 deletions
  1. 12
    7
      roller.hpp

+ 12
- 7
roller.hpp View File

} }


template <class D, class T> 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); unsigned char theByte = data.at(count);
matcher.add(roller::applyCaseSensitivity(theByte, caseSensitive)); matcher.add(roller::applyCaseSensitivity(theByte, caseSensitive));
masker.add(roller::appropriateBitMask(theByte, caseSensitive)); masker.add(roller::appropriateBitMask(theByte, caseSensitive));
private: private:
uint_fast32_t match; uint_fast32_t match;
uint_fast32_t mask; uint_fast32_t mask;
size_t matchLength;


public: public:
RollerMatch32(const std::vector<unsigned char> pattern, bool caseSensitive=true) { RollerMatch32(const std::vector<unsigned char> pattern, bool caseSensitive=true) {
Roller32 matcher, masker; Roller32 matcher, masker;
roller::compute(pattern, caseSensitive, matcher, masker);
roller::compute(pattern, caseSensitive, matcher, masker, matchLength);
match = matcher.value(); match = matcher.value();
mask = masker.value(); mask = masker.value();
} }


RollerMatch32(const std::string pattern, bool caseSensitive=true) { RollerMatch32(const std::string pattern, bool caseSensitive=true) {
Roller32 matcher, masker; Roller32 matcher, masker;
roller::compute(pattern, caseSensitive, matcher, masker);
roller::compute(pattern, caseSensitive, matcher, masker, matchLength);
match = matcher.value(); match = matcher.value();
mask = masker.value(); mask = masker.value();
} }
return (match == (roller.value() & mask)); return (match == (roller.value() & mask));
} }


size_t offset() { return matchLength; }
}; };


class RollerMatch64 { class RollerMatch64 {
private: private:
uint_fast64_t match; uint_fast64_t match;
uint_fast64_t mask; uint_fast64_t mask;
size_t matchLength;


public: public:
RollerMatch64(const std::vector<unsigned char> pattern, bool caseSensitive=true) { RollerMatch64(const std::vector<unsigned char> pattern, bool caseSensitive=true) {
Roller64 matcher, masker; Roller64 matcher, masker;
roller::compute(pattern, caseSensitive, matcher, masker);
roller::compute(pattern, caseSensitive, matcher, masker, matchLength);
match = matcher.value(); match = matcher.value();
mask = masker.value(); mask = masker.value();
} }


RollerMatch64(const std::string pattern, bool caseSensitive=true) { RollerMatch64(const std::string pattern, bool caseSensitive=true) {
Roller64 matcher, masker; Roller64 matcher, masker;
roller::compute(pattern, caseSensitive, matcher, masker);
roller::compute(pattern, caseSensitive, matcher, masker, matchLength);
match = matcher.value(); match = matcher.value();
mask = masker.value(); mask = masker.value();
} }
bool matches(const Roller64 roller) { bool matches(const Roller64 roller) {
return (match == (roller.value() & mask)); return (match == (roller.value() & mask));
} }

size_t offset() { return matchLength; }
}; };
} }



Loading…
Cancel
Save