mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
RE: Add MatchAll() and MatchSet() for std::string_view
This commit is contained in:
parent
5c6a6d9427
commit
dce51b99e5
3 changed files with 28 additions and 8 deletions
29
src/RE.cc
29
src/RE.cc
|
@ -189,24 +189,37 @@ std::string Specific_RE_Matcher::LookupDef(const std::string& def) {
|
|||
return {};
|
||||
}
|
||||
|
||||
bool Specific_RE_Matcher::MatchAll(const char* s) { return MatchAll((const u_char*)(s), strlen(s)); }
|
||||
bool Specific_RE_Matcher::MatchAll(const char* s) { return MatchAll(std::string_view{s}); }
|
||||
|
||||
bool Specific_RE_Matcher::MatchAll(const String* s) {
|
||||
// s->Len() does not include '\0'.
|
||||
return MatchAll(s->Bytes(), s->Len());
|
||||
bool Specific_RE_Matcher::MatchAll(const String* s) { return MatchAll(s->ToStdStringView()); }
|
||||
|
||||
bool Specific_RE_Matcher::MatchAll(std::string_view sv) {
|
||||
return MatchAll(reinterpret_cast<const u_char*>(sv.data()), sv.size());
|
||||
}
|
||||
|
||||
bool Specific_RE_Matcher::MatchSet(const String* s, std::vector<AcceptIdx>& matches) {
|
||||
return MatchAll(s->Bytes(), s->Len(), &matches);
|
||||
}
|
||||
|
||||
int Specific_RE_Matcher::Match(const char* s) { return Match((const u_char*)(s), strlen(s)); }
|
||||
bool Specific_RE_Matcher::MatchSet(std::string_view sv, std::vector<AcceptIdx>& matches) {
|
||||
return MatchAll(reinterpret_cast<const u_char*>(sv.data()), sv.size(), &matches);
|
||||
}
|
||||
|
||||
int Specific_RE_Matcher::Match(const String* s) { return Match(s->Bytes(), s->Len()); }
|
||||
int Specific_RE_Matcher::Match(const char* s) { return Match(std::string_view{s}); }
|
||||
|
||||
int Specific_RE_Matcher::LongestMatch(const char* s) { return LongestMatch((const u_char*)(s), strlen(s)); }
|
||||
int Specific_RE_Matcher::Match(const String* s) { return Match(s->ToStdStringView()); }
|
||||
|
||||
int Specific_RE_Matcher::LongestMatch(const String* s) { return LongestMatch(s->Bytes(), s->Len()); }
|
||||
int Specific_RE_Matcher::Match(std::string_view sv) {
|
||||
return Match(reinterpret_cast<const u_char*>(sv.data()), sv.size());
|
||||
}
|
||||
|
||||
int Specific_RE_Matcher::LongestMatch(const char* s) { return LongestMatch(std::string_view{s}); }
|
||||
|
||||
int Specific_RE_Matcher::LongestMatch(const String* s) { return LongestMatch(s->ToStdStringView()); }
|
||||
|
||||
int Specific_RE_Matcher::LongestMatch(std::string_view sv) {
|
||||
return LongestMatch(reinterpret_cast<const u_char*>(sv.data()), sv.size());
|
||||
}
|
||||
|
||||
bool Specific_RE_Matcher::MatchAll(const u_char* bv, int n, std::vector<AcceptIdx>* matches) {
|
||||
if ( ! dfa )
|
||||
|
|
7
src/RE.h
7
src/RE.h
|
@ -7,6 +7,7 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "zeek/CCL.h"
|
||||
#include "zeek/EquivClass.h"
|
||||
|
@ -89,6 +90,7 @@ public:
|
|||
|
||||
bool MatchAll(const char* s);
|
||||
bool MatchAll(const String* s);
|
||||
bool MatchAll(std::string_view sv);
|
||||
|
||||
// Compiles a set of regular expressions simultaneously.
|
||||
// 'idx' contains indices associated with the expressions.
|
||||
|
@ -104,16 +106,21 @@ public:
|
|||
// Behaves as MatchAll(), consuming the complete input string.
|
||||
bool MatchSet(const String* s, std::vector<AcceptIdx>& matches);
|
||||
|
||||
// As MatchSet() above, but taking a std::string_view.
|
||||
bool MatchSet(std::string_view sv, std::vector<AcceptIdx>& matches);
|
||||
|
||||
// Returns the position in s just beyond where the first match
|
||||
// occurs, or 0 if there is no such position in s. Note that
|
||||
// if the pattern matches empty strings, matching continues
|
||||
// in an attempt to match at least one character.
|
||||
int Match(const char* s);
|
||||
int Match(const String* s);
|
||||
int Match(std::string_view sv);
|
||||
int Match(const u_char* bv, int n);
|
||||
|
||||
int LongestMatch(const char* s);
|
||||
int LongestMatch(const String* s);
|
||||
int LongestMatch(std::string_view sv);
|
||||
int LongestMatch(const u_char* bv, int n, bool bol = true, bool eol = true);
|
||||
|
||||
EquivClass* EC() { return &equiv_class; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue