-
Notifications
You must be signed in to change notification settings - Fork 1
/
matchObj.h
74 lines (55 loc) · 2.14 KB
/
matchObj.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
66
67
68
69
70
71
72
73
#ifndef _MATCH_OBJ_H_
#define _MATCH_OBJ_H_
#include <string>
#include <memory>
#include <vector>
#include <map>
namespace rgx {
class _captureStartEdge;
class _captureEndEdge;
class _referenceEdge;
class _thread;
class _nfa_pattern;
class _dfa_pattern;
class matchObj {
friend _captureStartEdge;
friend _captureEndEdge;
friend _referenceEdge;
friend _thread;
friend _nfa_pattern;
friend _dfa_pattern;
public:
matchObj(unsigned int maxCaptureSlot)
: _pos(0), _endpos(0), _lastindex(0), _lastCaptureIndex(0), _capVector(maxCaptureSlot, std::pair<unsigned int, unsigned int>(0, 0)) {}
matchObj(const matchObj& matchobj)
: _pos(matchobj._pos), _endpos(matchobj._endpos), _lastindex(matchobj._lastCaptureIndex), _nameMap(nullptr), _capVector(matchobj._capVector) {
//拷贝时将re,input,_nameMap 默认初始化,这几个字段的初始化仅仅由addReAndInput函数提供
}
std::u16string group(unsigned int index);
//返回编号为index的group,index为0时,表示匹配到的字符串
std::vector<std::u16string> groups();
//返回所有的group
std::pair<unsigned int, unsigned int> span(unsigned int index);
//返回匹配到得字符串在正文中的位置
std::u16string group(const std::string& name);
//返回别名为name的捕获列表
std::u16string string() const; //input
std::u16string re() const; //正则
unsigned int pos() const; //起点
unsigned int endpos() const; // 终点
int lastindex() const;
int lastgroup() const;
void justToTest(const std::u16string&);
private:
std::u16string _re;
std::u16string _input;
unsigned int _pos;
unsigned int _endpos;
unsigned int _lastindex;
unsigned _lastCaptureIndex;
std::unique_ptr<std::map<std::u16string, unsigned int>> _nameMap; //具名捕获-->捕获index的转换
std::vector<std::pair<unsigned int, unsigned int>> _capVector;
void addReAndInput(const std::u16string&re, const std::u16string&input, const std::unique_ptr<std::map<std::u16string, unsigned int>>&);
};
}
#endif