-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchobject.cc
65 lines (55 loc) · 1.24 KB
/
matchobject.cc
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
#include <string>
#include "matchobject.h"
using namespace std;
namespace re2
{
MatchObject::MatchObject(re2::RE2 *re, re2::StringPiece text, re2::StringPiece *groups, size_t ngroups) :
_matched(true),
_re(re),
_string(text)
{
for (size_t i = 0; i < ngroups; ++i)
{
_groups.push_back(groups[i]);
}
}
const re2::StringPiece MatchObject::group(std::string group_name)
{
int group_index = _re->NamedCapturingGroups().at(group_name);
return group(group_index);
}
size_t MatchObject::start(int group_index)
{
re2::StringPiece sp = group(group_index);
if (sp.empty())
{
return string::npos;
}
else
{
return (sp.begin() - _string.begin());
}
}
size_t MatchObject::start(std::string group_name)
{
int group_index = _re->NamedCapturingGroups().at(group_name);
return start(group_index);
}
size_t MatchObject::end(int group_index)
{
re2::StringPiece sp = group(group_index);
if (sp.empty())
{
return string::npos;
}
else
{
return (sp.end() - _string.begin());
}
}
size_t MatchObject::end(std::string group_name)
{
int group_index = _re->NamedCapturingGroups().at(group_name);
return end(group_index);
}
} // namespace re2