38
38
namespace re2 {
39
39
40
40
// Returns a vector of the egrep regexp operators.
41
- const std::vector<string>& RegexpGenerator::EgrepOps () {
41
+ const std::vector<std:: string>& RegexpGenerator::EgrepOps () {
42
42
static const char *ops[] = {
43
43
" %s%s" ,
44
44
" %s|%s" ,
@@ -47,13 +47,13 @@ const std::vector<string>& RegexpGenerator::EgrepOps() {
47
47
" %s?" ,
48
48
" %s\\ C*" ,
49
49
};
50
- static std::vector<string> v (ops, ops + arraysize (ops));
50
+ static std::vector<std:: string> v (ops, ops + arraysize (ops));
51
51
return v;
52
52
}
53
53
54
54
RegexpGenerator::RegexpGenerator (int maxatoms, int maxops,
55
- const std::vector<string>& atoms,
56
- const std::vector<string>& ops)
55
+ const std::vector<std:: string>& atoms,
56
+ const std::vector<std:: string>& ops)
57
57
: maxatoms_(maxatoms), maxops_(maxops), atoms_(atoms), ops_(ops) {
58
58
// Degenerate case.
59
59
if (atoms_.empty ())
@@ -65,7 +65,7 @@ RegexpGenerator::RegexpGenerator(int maxatoms, int maxops,
65
65
// Generates all possible regular expressions (within the parameters),
66
66
// calling HandleRegexp for each one.
67
67
void RegexpGenerator::Generate () {
68
- std::vector<string> postfix;
68
+ std::vector<std:: string> postfix;
69
69
GeneratePostfix (&postfix, 0 , 0 , 0 );
70
70
}
71
71
@@ -74,13 +74,13 @@ void RegexpGenerator::GenerateRandom(int32_t seed, int n) {
74
74
rng_.seed (seed);
75
75
76
76
for (int i = 0 ; i < n; i++) {
77
- std::vector<string> postfix;
77
+ std::vector<std:: string> postfix;
78
78
GenerateRandomPostfix (&postfix, 0 , 0 , 0 );
79
79
}
80
80
}
81
81
82
82
// Counts and returns the number of occurrences of "%s" in s.
83
- static int CountArgs (const string& s) {
83
+ static int CountArgs (const std:: string& s) {
84
84
const char *p = s.c_str ();
85
85
int n = 0 ;
86
86
while ((p = strstr (p, " %s" )) != NULL ) {
@@ -103,8 +103,8 @@ static int CountArgs(const string& s) {
103
103
//
104
104
// The initial call should be GeneratePostfix([empty vector], 0, 0, 0).
105
105
//
106
- void RegexpGenerator::GeneratePostfix (std::vector<string>* post, int nstk ,
107
- int ops, int atoms) {
106
+ void RegexpGenerator::GeneratePostfix (std::vector<std:: string>* post,
107
+ int nstk, int ops, int atoms) {
108
108
if (nstk == 1 )
109
109
RunPostfix (*post);
110
110
@@ -126,7 +126,7 @@ void RegexpGenerator::GeneratePostfix(std::vector<string>* post, int nstk,
126
126
// Add operators if there are enough arguments.
127
127
if (ops < maxops_) {
128
128
for (size_t i = 0 ; i < ops_.size (); i++) {
129
- const string& fmt = ops_[i];
129
+ const std:: string& fmt = ops_[i];
130
130
int nargs = CountArgs (fmt);
131
131
if (nargs <= nstk) {
132
132
post->push_back (fmt);
@@ -139,8 +139,8 @@ void RegexpGenerator::GeneratePostfix(std::vector<string>* post, int nstk,
139
139
140
140
// Generates a random postfix command sequence.
141
141
// Stops and returns true once a single sequence has been generated.
142
- bool RegexpGenerator::GenerateRandomPostfix (std::vector<string>* post, int nstk ,
143
- int ops, int atoms) {
142
+ bool RegexpGenerator::GenerateRandomPostfix (std::vector<std:: string>* post,
143
+ int nstk, int ops, int atoms) {
144
144
std::uniform_int_distribution<int > random_stop (0 , maxatoms_ - atoms);
145
145
std::uniform_int_distribution<int > random_bit (0 , 1 );
146
146
std::uniform_int_distribution<int > random_ops_index (
@@ -163,7 +163,7 @@ bool RegexpGenerator::GenerateRandomPostfix(std::vector<string>* post, int nstk,
163
163
164
164
// Add operators if there are enough arguments.
165
165
if (ops < maxops_ && random_bit (rng_) == 0 ) {
166
- const string& fmt = ops_[random_ops_index (rng_)];
166
+ const std:: string& fmt = ops_[random_ops_index (rng_)];
167
167
int nargs = CountArgs (fmt);
168
168
if (nargs <= nstk) {
169
169
post->push_back (fmt);
@@ -189,8 +189,8 @@ bool RegexpGenerator::GenerateRandomPostfix(std::vector<string>* post, int nstk,
189
189
// Interprets the postfix command sequence to create a regular expression
190
190
// passed to HandleRegexp. The results of operators like %s|%s are wrapped
191
191
// in (?: ) to avoid needing to maintain a precedence table.
192
- void RegexpGenerator::RunPostfix (const std::vector<string>& post) {
193
- std::stack<string> regexps;
192
+ void RegexpGenerator::RunPostfix (const std::vector<std:: string>& post) {
193
+ std::stack<std:: string> regexps;
194
194
for (size_t i = 0 ; i < post.size (); i++) {
195
195
switch (CountArgs (post[i])) {
196
196
default :
@@ -199,15 +199,15 @@ void RegexpGenerator::RunPostfix(const std::vector<string>& post) {
199
199
regexps.push (post[i]);
200
200
break ;
201
201
case 1 : {
202
- string a = regexps.top ();
202
+ std:: string a = regexps.top ();
203
203
regexps.pop ();
204
204
regexps.push (" (?:" + StringPrintf (post[i].c_str (), a.c_str ()) + " )" );
205
205
break ;
206
206
}
207
207
case 2 : {
208
- string b = regexps.top ();
208
+ std:: string b = regexps.top ();
209
209
regexps.pop ();
210
- string a = regexps.top ();
210
+ std:: string a = regexps.top ();
211
211
regexps.pop ();
212
212
regexps.push (" (?:" +
213
213
StringPrintf (post[i].c_str (), a.c_str (), b.c_str ()) +
@@ -238,38 +238,38 @@ void RegexpGenerator::RunPostfix(const std::vector<string>& post) {
238
238
}
239
239
240
240
// Split s into an vector of strings, one for each UTF-8 character.
241
- std::vector<string> Explode (const StringPiece& s) {
242
- std::vector<string> v;
241
+ std::vector<std:: string> Explode (const StringPiece& s) {
242
+ std::vector<std:: string> v;
243
243
244
244
for (const char *q = s.begin (); q < s.end (); ) {
245
245
const char * p = q;
246
246
Rune r;
247
247
q += chartorune (&r, q);
248
- v.push_back (string (p, q - p));
248
+ v.push_back (std:: string (p, q - p));
249
249
}
250
250
251
251
return v;
252
252
}
253
253
254
254
// Split string everywhere a substring is found, returning
255
255
// vector of pieces.
256
- std::vector<string> Split (const StringPiece& sep, const StringPiece& s) {
257
- std::vector<string> v;
256
+ std::vector<std:: string> Split (const StringPiece& sep, const StringPiece& s) {
257
+ std::vector<std:: string> v;
258
258
259
259
if (sep.size () == 0 )
260
260
return Explode (s);
261
261
262
262
const char *p = s.begin ();
263
263
for (const char *q = s.begin (); q + sep.size () <= s.end (); q++) {
264
264
if (StringPiece (q, sep.size ()) == sep) {
265
- v.push_back (string (p, q - p));
265
+ v.push_back (std:: string (p, q - p));
266
266
p = q + sep.size ();
267
267
q = p - 1 ; // -1 for ++ in loop
268
268
continue ;
269
269
}
270
270
}
271
271
if (p < s.end ())
272
- v.push_back (string (p, s.end () - p));
272
+ v.push_back (std:: string (p, s.end () - p));
273
273
return v;
274
274
}
275
275
0 commit comments