forked from RPGillespie6/posix-regex-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOSIXRegex.h
99 lines (77 loc) · 1.83 KB
/
POSIXRegex.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef ECPP_REGEX_H
#define ECPP_REGEX_H
#include <sys/types.h>
#include <stdlib.h>
#include <regex.h>
#include <vector>
#include <string>
namespace POSIX
{
struct Group
{
int start;
int end;
};
class Match
{
private:
std::string match;
std::vector<Group> pgroups;
void addGroup(int start, int end);
public:
Match();
Match(std::string match);
/*
Returns the starting index of the group
*/
int start(unsigned int group);
/*
Returns the ending index of the group
*/
int end(unsigned int group);
/*
Returns a string representing the provided groups
*/
std::string group(unsigned int group);
/*
Returns a list of strings representing all capture groups
*/
std::vector<std::string> groups();
/*
Returns the number of groups in the match
*/
int numGroups();
friend class Regex;
};
class Regex
{
private:
std::string pattern;
regex_t regex;
bool compiled;
public:
Regex();
~Regex();
/*
Compiles the provided pattern and returns whether the compilation was successful or not
*/
bool compile(std::string pattern, bool case_sensitive=true);
/*
Returns whether the provided string matches the compiled pattern
*/
bool matches(std::string str);
/*
Returns the first Match in str
*/
Match match(std::string str);
/*
Returns the current compiled pattern in string form
*/
std::string getPattern();
/*
Returns whether there is a current compiled regex in memory
*/
bool isCompiled();
};
}
#endif