|
a/src/utils/strmatcher.h |
|
b/src/utils/strmatcher.h |
|
... |
|
... |
16 |
*/
|
16 |
*/
|
17 |
#ifndef _STRMATCHER_H_INCLUDED_
|
17 |
#ifndef _STRMATCHER_H_INCLUDED_
|
18 |
#define _STRMATCHER_H_INCLUDED_
|
18 |
#define _STRMATCHER_H_INCLUDED_
|
19 |
|
19 |
|
20 |
#include <string>
|
20 |
#include <string>
|
|
|
21 |
#include "smallut.h"
|
21 |
|
22 |
|
22 |
// Encapsulating simple wildcard/regexp string matching.
|
23 |
// Encapsulating simple wildcard/regexp string matching.
|
23 |
|
24 |
|
24 |
// Matcher class. Interface to either wildcard or regexp yes/no matcher
|
25 |
// Matcher class. Interface to either wildcard or regexp yes/no matcher
|
25 |
class StrMatcher {
|
26 |
class StrMatcher {
|
26 |
public:
|
27 |
public:
|
27 |
StrMatcher(const std::string& exp)
|
28 |
StrMatcher(const std::string& exp)
|
28 |
: m_sexp(exp)
|
29 |
: m_sexp(exp) {}
|
29 |
{
|
|
|
30 |
}
|
|
|
31 |
virtual ~StrMatcher() {};
|
30 |
virtual ~StrMatcher() {};
|
32 |
virtual bool match(const std::string &val) const = 0;
|
31 |
virtual bool match(const std::string &val) const = 0;
|
33 |
virtual std::string::size_type baseprefixlen() const = 0;
|
32 |
virtual std::string::size_type baseprefixlen() const = 0;
|
34 |
virtual bool setExp(const std::string& newexp)
|
33 |
virtual bool setExp(const std::string& newexp) {
|
35 |
{
|
|
|
36 |
m_sexp = newexp;
|
34 |
m_sexp = newexp;
|
37 |
return true;
|
35 |
return true;
|
38 |
}
|
36 |
}
|
39 |
virtual bool ok() const
|
37 |
virtual bool ok() const {
|
40 |
{
|
|
|
41 |
return true;
|
38 |
return true;
|
42 |
}
|
39 |
}
|
43 |
virtual const std::string& exp()
|
40 |
virtual const std::string& exp() const {
|
44 |
{
|
|
|
45 |
return m_sexp;
|
41 |
return m_sexp;
|
46 |
}
|
42 |
}
|
47 |
virtual StrMatcher *clone() = 0;
|
43 |
virtual StrMatcher *clone() const = 0;
|
48 |
const string& getreason()
|
44 |
const std::string& getreason() const {
|
49 |
{
|
|
|
50 |
return m_reason;
|
45 |
return m_reason;
|
51 |
}
|
46 |
}
|
52 |
protected:
|
47 |
protected:
|
53 |
std::string m_sexp;
|
48 |
std::string m_sexp;
|
54 |
std::string m_reason;
|
49 |
std::string m_reason;
|
55 |
};
|
50 |
};
|
56 |
|
51 |
|
57 |
class StrWildMatcher : public StrMatcher {
|
52 |
class StrWildMatcher : public StrMatcher {
|
58 |
public:
|
53 |
public:
|
59 |
StrWildMatcher(const std::string& exp)
|
54 |
StrWildMatcher(const std::string& exp)
|
60 |
: StrMatcher(exp)
|
55 |
: StrMatcher(exp) {}
|
61 |
{
|
|
|
62 |
}
|
|
|
63 |
virtual ~StrWildMatcher()
|
56 |
virtual ~StrWildMatcher() {}
|
64 |
{
|
|
|
65 |
}
|
|
|
66 |
virtual bool match(const std::string& val) const;
|
57 |
virtual bool match(const std::string& val) const;
|
67 |
virtual std::string::size_type baseprefixlen() const;
|
58 |
virtual std::string::size_type baseprefixlen() const;
|
68 |
virtual StrWildMatcher *clone()
|
59 |
virtual StrWildMatcher *clone() const {
|
69 |
{
|
|
|
70 |
return new StrWildMatcher(m_sexp);
|
60 |
return new StrWildMatcher(m_sexp);
|
71 |
}
|
61 |
}
|
72 |
};
|
62 |
};
|
73 |
|
63 |
|
74 |
class StrRegexpMatcher : public StrMatcher {
|
64 |
class StrRegexpMatcher : public StrMatcher {
|
75 |
public:
|
65 |
public:
|
76 |
StrRegexpMatcher(const std::string& exp);
|
66 |
StrRegexpMatcher(const std::string& exp);
|
77 |
virtual bool setExp(const std::string& newexp);
|
67 |
virtual bool setExp(const std::string& newexp) override;
|
78 |
virtual ~StrRegexpMatcher();
|
68 |
virtual ~StrRegexpMatcher() {};
|
79 |
virtual bool match(const std::string& val) const;
|
69 |
virtual bool match(const std::string& val) const;
|
80 |
virtual std::string::size_type baseprefixlen() const;
|
70 |
virtual std::string::size_type baseprefixlen() const;
|
81 |
virtual bool ok() const;
|
71 |
virtual bool ok() const override;
|
82 |
virtual StrRegexpMatcher *clone()
|
72 |
virtual StrRegexpMatcher *clone() const {
|
83 |
{
|
|
|
84 |
return new StrRegexpMatcher(m_sexp);
|
73 |
return new StrRegexpMatcher(m_sexp);
|
85 |
}
|
74 |
}
|
86 |
const string& getreason()
|
|
|
87 |
{
|
|
|
88 |
return m_reason;
|
|
|
89 |
}
|
|
|
90 |
private:
|
75 |
private:
|
91 |
void *m_compiled;
|
76 |
SimpleRegexp m_re;
|
92 |
bool m_errcode;
|
|
|
93 |
};
|
77 |
};
|
94 |
|
78 |
|
95 |
#endif /* _STRMATCHER_H_INCLUDED_ */
|
79 |
#endif /* _STRMATCHER_H_INCLUDED_ */
|