forked from filgy/watcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregexApi.cpp
58 lines (44 loc) · 1.48 KB
/
regexApi.cpp
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
#include "regexApi.h"
/* - - - - - - - - - - - - - - - - - - - - - -
Class: regexApiMatch
------------------------------------------- */
regexApiMatch::regexApiMatch(){
this->matches.clear();
}
regexApiMatch::regexApiMatch(vector<string> matches){
this->matches = matches;
}
int regexApiMatch::size(){
return this->matches.size();
}
void regexApiMatch::clear(){
this->matches.clear();
}
string regexApiMatch::operator[](unsigned int position){
if(position >= this->matches.size())
return "";
else
return this->matches.at(position);
}
void regexApiMatch::insert(string match){
this->matches.push_back(match);
}
/* - - - - - - - - - - - - - - - - - - - - - -
Class: regexApi
------------------------------------------- */
bool regexApi::preg_match(string pattern, string subject){
boost::xpressive::sregex bpattern = boost::xpressive::sregex::compile(pattern);
boost::xpressive::smatch match;
return boost::xpressive::regex_match(subject, match, bpattern);
}
bool regexApi::preg_match(string pattern, string subject, regexApiMatch& matches){
boost::xpressive::sregex bpattern = boost::xpressive::sregex::compile(pattern);
boost::xpressive::smatch match;
matches.clear();
if(boost::xpressive::regex_match(subject, match, bpattern)){
for(boost::xpressive::smatch::iterator p = match.begin(); p != match.end(); p++)
matches.insert((*p));
return true;
}
return false;
}