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

@@ -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; }
};
}


Loading…
Cancel
Save