mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
binpac: Reformat C++ code in Spicy style
This commit is contained in:
parent
716bf016a1
commit
3297de477b
89 changed files with 7887 additions and 9733 deletions
|
@ -5,13 +5,11 @@
|
|||
|
||||
#include "binpac.h"
|
||||
|
||||
namespace zeek
|
||||
{
|
||||
namespace zeek {
|
||||
class RE_Matcher;
|
||||
}
|
||||
}
|
||||
|
||||
namespace binpac
|
||||
{
|
||||
namespace binpac {
|
||||
|
||||
// Must be called before any binpac functionality is used.
|
||||
//
|
||||
|
@ -23,58 +21,52 @@ inline void init(FlowBuffer::Policy* fbp = 0);
|
|||
// Internal vector recording not yet compiled matchers.
|
||||
extern std::vector<zeek::RE_Matcher*>* uncompiled_re_matchers;
|
||||
|
||||
class RegExMatcher
|
||||
{
|
||||
class RegExMatcher {
|
||||
public:
|
||||
RegExMatcher(const char* pattern) : pattern_(pattern)
|
||||
{
|
||||
if ( ! uncompiled_re_matchers )
|
||||
uncompiled_re_matchers = new std::vector<zeek::RE_Matcher*>;
|
||||
RegExMatcher(const char* pattern) : pattern_(pattern) {
|
||||
if ( ! uncompiled_re_matchers )
|
||||
uncompiled_re_matchers = new std::vector<zeek::RE_Matcher*>;
|
||||
|
||||
re_matcher_ = new zeek::RE_Matcher(pattern_.c_str());
|
||||
uncompiled_re_matchers->push_back(re_matcher_);
|
||||
}
|
||||
re_matcher_ = new zeek::RE_Matcher(pattern_.c_str());
|
||||
uncompiled_re_matchers->push_back(re_matcher_);
|
||||
}
|
||||
|
||||
~RegExMatcher() { delete re_matcher_; }
|
||||
~RegExMatcher() { delete re_matcher_; }
|
||||
|
||||
// Returns the length of longest match, or -1 on mismatch.
|
||||
int MatchPrefix(const_byteptr data, int len) { return re_matcher_->MatchPrefix(data, len); }
|
||||
// Returns the length of longest match, or -1 on mismatch.
|
||||
int MatchPrefix(const_byteptr data, int len) { return re_matcher_->MatchPrefix(data, len); }
|
||||
|
||||
private:
|
||||
friend void ::binpac::init(FlowBuffer::Policy*);
|
||||
friend void ::binpac::init(FlowBuffer::Policy*);
|
||||
|
||||
// Function, and state, for compiling matchers.
|
||||
static void init();
|
||||
// Function, and state, for compiling matchers.
|
||||
static void init();
|
||||
|
||||
string pattern_;
|
||||
zeek::RE_Matcher* re_matcher_;
|
||||
};
|
||||
string pattern_;
|
||||
zeek::RE_Matcher* re_matcher_;
|
||||
};
|
||||
|
||||
inline void RegExMatcher::init()
|
||||
{
|
||||
if ( ! uncompiled_re_matchers )
|
||||
return;
|
||||
inline void RegExMatcher::init() {
|
||||
if ( ! uncompiled_re_matchers )
|
||||
return;
|
||||
|
||||
for ( size_t i = 0; i < uncompiled_re_matchers->size(); ++i )
|
||||
{
|
||||
if ( ! (*uncompiled_re_matchers)[i]->Compile() )
|
||||
{
|
||||
fprintf(stderr, "binpac: cannot compile regular expression\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
for ( size_t i = 0; i < uncompiled_re_matchers->size(); ++i ) {
|
||||
if ( ! (*uncompiled_re_matchers)[i]->Compile() ) {
|
||||
fprintf(stderr, "binpac: cannot compile regular expression\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
uncompiled_re_matchers->clear();
|
||||
}
|
||||
uncompiled_re_matchers->clear();
|
||||
}
|
||||
|
||||
inline void init(FlowBuffer::Policy* fbp)
|
||||
{
|
||||
RegExMatcher::init();
|
||||
inline void init(FlowBuffer::Policy* fbp) {
|
||||
RegExMatcher::init();
|
||||
|
||||
if ( fbp )
|
||||
FlowBuffer::init(*fbp);
|
||||
}
|
||||
if ( fbp )
|
||||
FlowBuffer::init(*fbp);
|
||||
}
|
||||
|
||||
} // namespace binpac
|
||||
} // namespace binpac
|
||||
|
||||
#endif // binpac_regex_h
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue