MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / RunPostfix

Method RunPostfix

extern/re2/re2/testing/regexp_generator.cc:192–238  ·  view source on GitHub ↗

Interprets the postfix command sequence to create a regular expression passed to HandleRegexp. The results of operators like %s|%s are wrapped in (?: ) to avoid needing to maintain a precedence table.

Source from the content-addressed store, hash-verified

190// passed to HandleRegexp. The results of operators like %s|%s are wrapped
191// in (?: ) to avoid needing to maintain a precedence table.
192void RegexpGenerator::RunPostfix(const std::vector<std::string>& post) {
193 std::stack<std::string> regexps;
194 for (size_t i = 0; i < post.size(); i++) {
195 switch (CountArgs(post[i])) {
196 default:
197 LOG(FATAL) << "Bad operator: " << post[i];
198 case 0:
199 regexps.push(post[i]);
200 break;
201 case 1: {
202 std::string a = regexps.top();
203 regexps.pop();
204 regexps.push("(?:" + StringPrintf(post[i].c_str(), a.c_str()) + ")");
205 break;
206 }
207 case 2: {
208 std::string b = regexps.top();
209 regexps.pop();
210 std::string a = regexps.top();
211 regexps.pop();
212 regexps.push("(?:" +
213 StringPrintf(post[i].c_str(), a.c_str(), b.c_str()) +
214 ")");
215 break;
216 }
217 }
218 }
219
220 if (regexps.size() != 1) {
221 // Internal error - should never happen.
222 printf("Bad regexp program:\n");
223 for (size_t i = 0; i < post.size(); i++) {
224 printf(" %s\n", CEscape(post[i]).c_str());
225 }
226 printf("Stack after running program:\n");
227 while (!regexps.empty()) {
228 printf(" %s\n", CEscape(regexps.top()).c_str());
229 regexps.pop();
230 }
231 LOG(FATAL) << "Bad regexp program.";
232 }
233
234 HandleRegexp(regexps.top());
235 HandleRegexp("^(?:" + regexps.top() + ")$");
236 HandleRegexp("^(?:" + regexps.top() + ")");
237 HandleRegexp("(?:" + regexps.top() + ")$");
238}
239
240// Split s into an vector of strings, one for each UTF-8 character.
241std::vector<std::string> Explode(const StringPiece& s) {

Callers

nothing calls this directly

Calls 9

CountArgsFunction · 0.85
StringPrintfFunction · 0.85
CEscapeFunction · 0.85
topMethod · 0.80
sizeMethod · 0.45
pushMethod · 0.45
popMethod · 0.45
c_strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected