mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-10-01 03:57:43 +03:00
chimera: hybrid of Hyperscan and PCRE
This commit is contained in:
@@ -35,25 +35,36 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Type for capturing groups: a vector of (from, to) offsets, with both set to
|
||||
// -1 for inactive groups (like pcre's ovector). Used by hybrid modes.
|
||||
typedef std::vector<std::pair<int, int> > CaptureVec;
|
||||
|
||||
// Class representing a single match, encapsulating to/from offsets.
|
||||
class MatchResult {
|
||||
public:
|
||||
MatchResult(unsigned long long start, unsigned long long end)
|
||||
: from(start), to(end) {}
|
||||
MatchResult(unsigned long long start, unsigned long long end,
|
||||
const CaptureVec &cap)
|
||||
: from(start), to(end), captured(cap) {}
|
||||
|
||||
bool operator<(const MatchResult &a) const {
|
||||
if (from != a.from) {
|
||||
return from < a.from;
|
||||
}
|
||||
return to < a.to;
|
||||
if (to != a.to) {
|
||||
return to < a.to;
|
||||
}
|
||||
return captured < a.captured;
|
||||
}
|
||||
|
||||
bool operator==(const MatchResult &a) const {
|
||||
return from == a.from && to == a.to;
|
||||
return from == a.from && to == a.to && captured == a.captured;
|
||||
}
|
||||
|
||||
unsigned long long from;
|
||||
unsigned long long to;
|
||||
CaptureVec captured;
|
||||
};
|
||||
|
||||
enum ResultSource {
|
||||
@@ -114,6 +125,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Add a match (with capturing vector)
|
||||
void addMatch(unsigned long long from, unsigned long long to,
|
||||
const CaptureVec &cap, int block = 0) {
|
||||
MatchResult m(from, to, cap);
|
||||
matches.insert(m);
|
||||
|
||||
if (matches_by_block[block].find(m) != matches_by_block[block].end()) {
|
||||
dupe_matches.insert(m);
|
||||
} else {
|
||||
matches_by_block[block].insert(m);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all matches.
|
||||
void clear() {
|
||||
matches.clear();
|
||||
|
Reference in New Issue
Block a user