mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 05:58:20 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
98
src/RE.h
98
src/RE.h
|
@ -2,27 +2,29 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h> // for u_char
|
||||
#include <ctype.h>
|
||||
#include <set>
|
||||
#include <sys/types.h> // for u_char
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "zeek/List.h"
|
||||
#include "zeek/CCL.h"
|
||||
#include "zeek/EquivClass.h"
|
||||
#include "zeek/List.h"
|
||||
|
||||
typedef int (*cce_func)(int);
|
||||
|
||||
// This method is automatically generated by flex and shouldn't be namespaced
|
||||
extern int re_lex(void);
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
class String;
|
||||
class RE_Matcher;
|
||||
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class NFA_Machine;
|
||||
class DFA_Machine;
|
||||
|
@ -45,21 +47,26 @@ using MatchPos = uint64_t;
|
|||
using AcceptingMatchSet = std::map<AcceptIdx, MatchPos>;
|
||||
using string_list = name_list;
|
||||
|
||||
enum match_type { MATCH_ANYWHERE, MATCH_EXACTLY };
|
||||
enum match_type
|
||||
{
|
||||
MATCH_ANYWHERE,
|
||||
MATCH_EXACTLY
|
||||
};
|
||||
|
||||
// A "specific" RE matcher will match one type of pattern: either
|
||||
// MATCH_ANYWHERE or MATCH_EXACTLY.
|
||||
|
||||
class Specific_RE_Matcher {
|
||||
class Specific_RE_Matcher
|
||||
{
|
||||
public:
|
||||
explicit Specific_RE_Matcher(match_type mt, int multiline=0);
|
||||
explicit Specific_RE_Matcher(match_type mt, int multiline = 0);
|
||||
~Specific_RE_Matcher();
|
||||
|
||||
void AddPat(const char* pat);
|
||||
|
||||
void MakeCaseInsensitive();
|
||||
|
||||
void SetPat(const char* pat) { pattern_text = util::copy_string(pat); }
|
||||
void SetPat(const char* pat) { pattern_text = util::copy_string(pat); }
|
||||
|
||||
bool Compile(bool lazy = false);
|
||||
|
||||
|
@ -82,7 +89,7 @@ public:
|
|||
|
||||
return nullptr;
|
||||
}
|
||||
CCL* LookupCCL(int index) { return ccl_list[index]; }
|
||||
CCL* LookupCCL(int index) { return ccl_list[index]; }
|
||||
CCL* AnyCCL();
|
||||
|
||||
void ConvertCCLs();
|
||||
|
@ -107,16 +114,17 @@ public:
|
|||
int LongestMatch(const String* s);
|
||||
int LongestMatch(const u_char* bv, int n);
|
||||
|
||||
EquivClass* EC() { return &equiv_class; }
|
||||
EquivClass* EC() { return &equiv_class; }
|
||||
|
||||
const char* PatternText() const { return pattern_text; }
|
||||
const char* PatternText() const { return pattern_text; }
|
||||
|
||||
DFA_Machine* DFA() const { return dfa; }
|
||||
DFA_Machine* DFA() const { return dfa; }
|
||||
|
||||
void Dump(FILE* f);
|
||||
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
|
||||
unsigned int MemoryAllocation() const;
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] unsigned int
|
||||
MemoryAllocation() const;
|
||||
|
||||
protected:
|
||||
void AddAnywherePat(const char* pat);
|
||||
|
@ -142,9 +150,10 @@ protected:
|
|||
DFA_Machine* dfa;
|
||||
CCL* any_ccl;
|
||||
AcceptingSet* accepted;
|
||||
};
|
||||
};
|
||||
|
||||
class RE_Match_State {
|
||||
class RE_Match_State
|
||||
{
|
||||
public:
|
||||
explicit RE_Match_State(Specific_RE_Matcher* matcher)
|
||||
{
|
||||
|
@ -154,11 +163,10 @@ public:
|
|||
current_state = nullptr;
|
||||
}
|
||||
|
||||
const AcceptingMatchSet& AcceptedMatches() const
|
||||
{ return accepted_matches; }
|
||||
const AcceptingMatchSet& AcceptedMatches() const { return accepted_matches; }
|
||||
|
||||
// Returns the number of bytes feeded into the matcher so far
|
||||
int Length() { return current_pos; }
|
||||
int Length() { return current_pos; }
|
||||
|
||||
// Returns true if this inputs leads to at least one new match.
|
||||
// If clear is true, starts matching over.
|
||||
|
@ -180,14 +188,15 @@ protected:
|
|||
AcceptingMatchSet accepted_matches;
|
||||
DFA_State* current_state;
|
||||
int current_pos;
|
||||
};
|
||||
};
|
||||
|
||||
extern RE_Matcher* RE_Matcher_conjunction(const RE_Matcher* re1, const RE_Matcher* re2);
|
||||
extern RE_Matcher* RE_Matcher_disjunction(const RE_Matcher* re1, const RE_Matcher* re2);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
class RE_Matcher final {
|
||||
class RE_Matcher final
|
||||
{
|
||||
public:
|
||||
RE_Matcher();
|
||||
explicit RE_Matcher(const char* pat);
|
||||
|
@ -198,49 +207,42 @@ public:
|
|||
|
||||
// Makes the matcher as specified to date case-insensitive.
|
||||
void MakeCaseInsensitive();
|
||||
bool IsCaseInsensitive() const { return is_case_insensitive; }
|
||||
bool IsCaseInsensitive() const { return is_case_insensitive; }
|
||||
|
||||
bool Compile(bool lazy = false);
|
||||
|
||||
// Returns true if s exactly matches the pattern, false otherwise.
|
||||
bool MatchExactly(const char* s)
|
||||
{ return re_exact->MatchAll(s); }
|
||||
bool MatchExactly(const String* s)
|
||||
{ return re_exact->MatchAll(s); }
|
||||
bool MatchExactly(const char* s) { return re_exact->MatchAll(s); }
|
||||
bool MatchExactly(const String* s) { return re_exact->MatchAll(s); }
|
||||
|
||||
// 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 MatchAnywhere(const char* s)
|
||||
{ return re_anywhere->Match(s); }
|
||||
int MatchAnywhere(const String* s)
|
||||
{ return re_anywhere->Match(s); }
|
||||
int MatchAnywhere(const char* s) { return re_anywhere->Match(s); }
|
||||
int MatchAnywhere(const String* s) { return re_anywhere->Match(s); }
|
||||
|
||||
// Note: it matches the *longest* prefix and returns the
|
||||
// length of matched prefix. It returns -1 on mismatch.
|
||||
int MatchPrefix(const char* s)
|
||||
{ return re_exact->LongestMatch(s); }
|
||||
int MatchPrefix(const String* s)
|
||||
{ return re_exact->LongestMatch(s); }
|
||||
int MatchPrefix(const u_char* s, int n)
|
||||
{ return re_exact->LongestMatch(s, n); }
|
||||
int MatchPrefix(const char* s) { return re_exact->LongestMatch(s); }
|
||||
int MatchPrefix(const String* s) { return re_exact->LongestMatch(s); }
|
||||
int MatchPrefix(const u_char* s, int n) { return re_exact->LongestMatch(s, n); }
|
||||
|
||||
const char* PatternText() const { return re_exact->PatternText(); }
|
||||
const char* AnywherePatternText() const { return re_anywhere->PatternText(); }
|
||||
const char* PatternText() const { return re_exact->PatternText(); }
|
||||
const char* AnywherePatternText() const { return re_anywhere->PatternText(); }
|
||||
|
||||
// Original text used to construct this matcher. Empty unless
|
||||
// the main ("explicit") constructor was used.
|
||||
const char* OrigText() const { return orig_text.c_str(); }
|
||||
const char* OrigText() const { return orig_text.c_str(); }
|
||||
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
|
||||
unsigned int MemoryAllocation() const
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] unsigned int
|
||||
MemoryAllocation() const
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return padded_sizeof(*this)
|
||||
+ (re_anywhere ? re_anywhere->MemoryAllocation() : 0)
|
||||
+ (re_exact ? re_exact->MemoryAllocation() : 0);
|
||||
return padded_sizeof(*this) + (re_anywhere ? re_anywhere->MemoryAllocation() : 0) +
|
||||
(re_exact ? re_exact->MemoryAllocation() : 0);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
|
@ -251,6 +253,6 @@ protected:
|
|||
detail::Specific_RE_Matcher* re_exact;
|
||||
|
||||
bool is_case_insensitive = false;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue