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

Method CheckRewriteString

extern/re2/re2/re2.cc:948–984  ·  view source on GitHub ↗

Checks that the rewrite string is well-formed with respect to this regular expression.

Source from the content-addressed store, hash-verified

946// Checks that the rewrite string is well-formed with respect to this
947// regular expression.
948bool RE2::CheckRewriteString(const StringPiece& rewrite,
949 std::string* error) const {
950 int max_token = -1;
951 for (const char *s = rewrite.data(), *end = s + rewrite.size();
952 s < end; s++) {
953 int c = *s;
954 if (c != '\\') {
955 continue;
956 }
957 if (++s == end) {
958 *error = "Rewrite schema error: '\\' not allowed at end.";
959 return false;
960 }
961 c = *s;
962 if (c == '\\') {
963 continue;
964 }
965 if (!isdigit(c)) {
966 *error = "Rewrite schema error: "
967 "'\\' must be followed by a digit or '\\'.";
968 return false;
969 }
970 int n = (c - '0');
971 if (max_token < n) {
972 max_token = n;
973 }
974 }
975
976 if (max_token > NumberOfCapturingGroups()) {
977 *error = StringPrintf(
978 "Rewrite schema requests %d matches, but the regexp only has %d "
979 "parenthesized subexpressions.",
980 max_token, NumberOfCapturingGroups());
981 return false;
982 }
983 return true;
984}
985
986// Returns the maximum submatch needed for the rewrite to be done by Replace().
987// E.g. if rewrite == "foo \\2,\\1", returns 2.

Callers 1

ASSERT_DECIMALFunction · 0.45

Calls 3

StringPrintfFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

ASSERT_DECIMALFunction · 0.36