-
Notifications
You must be signed in to change notification settings - Fork 0
/
re2_regex.H
65 lines (45 loc) · 952 Bytes
/
re2_regex.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef RE2_REGEX_H
#define RE2_REGEX_H
#include <string>
#include <list>
#include <memory>
namespace re2 {
class RE2;
}
class String;
class Match {
public:
/// Ctor
Match() = default;
/// Dtor
~Match() = default;
inline size_t position() const
{
return _position;
}
inline size_t length() const
{
return _length;
}
inline void set_pos_and_len(size_t pos, size_t len)
{
_position = pos;
_length = len;
}
private:
size_t _position = 0;
size_t _length = 0;
};
class Regex {
public:
using Ptr = std::unique_ptr<Regex>;
using PtrList = std::list<Ptr>;
explicit Regex(String const & r, std::string const & grammar);
~Regex();
inline bool valid() const { return _valid; }
bool match(std::string const & s, Match * pmatch = nullptr) const;
private:
bool _valid = false;
std::unique_ptr<re2::RE2> _rx;
};
#endif