Skip to content

Commit c314954

Browse files
WGH-zimmerle
authored andcommitted
Fix build/re2.m4 file lookup
There's no such include file as "re2/re2_parse.h", and there was a typo in RE2_POSSIBLE_PATHS.
1 parent 2253df1 commit c314954

File tree

2 files changed

+62
-46
lines changed

2 files changed

+62
-46
lines changed

build/re2.m4

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ AC_ARG_WITH(
3131
)
3232
3333
if test "x${with_re2}" == "xno"; then
34-
AC_DEFINE(HAVE_GEOIP, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
34+
AC_DEFINE(HAVE_RE2, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
3535
AC_MSG_NOTICE([Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
3636
RE2_DISABLED=yes
3737
else
@@ -48,7 +48,7 @@ else
4848
4949
# if test "x${with_re2}" != "xyes" or test "x${with_re2}" == "xyes"; then
5050
if test "x${with_re2}" == "x" || test "x${with_re2}" == "xyes"; then
51-
# Nothing about GeoIP was informed, using the pkg-config to figure things out.
51+
# Nothing about RE2 was informed, using the pkg-config to figure things out.
5252
if test -n "${PKG_CONFIG}"; then
5353
RE2_PKG_NAME=""
5454
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
@@ -58,7 +58,7 @@ else
5858
fi
5959
done
6060
fi
61-
AC_MSG_NOTICE([Nothing about GeoIP was informed during the configure phase. Trying to detect it on the platform...])
61+
AC_MSG_NOTICE([Nothing about RE2 was informed during the configure phase. Trying to detect it on the platform...])
6262
if test -n "${RE2_PKG_NAME}"; then
6363
# Package was found using the pkg-config scripts
6464
RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`"
@@ -68,7 +68,7 @@ else
6868
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
6969
else
7070
# If pkg-config did not find anything useful, go over file lookup.
71-
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
71+
for x in ${RE2_POSSIBLE_PATHS}; do
7272
CHECK_FOR_RE2_AT(${x})
7373
if test -n "${RE2_VERSION}"; then
7474
break
@@ -149,11 +149,11 @@ AC_DEFUN([CHECK_FOR_RE2_AT], [
149149
break
150150
fi
151151
done
152-
if test -e "${path}/include/re2_parse.h"; then
152+
if test -e "${path}/include/re2.h"; then
153153
re2_inc_path="${path}/include"
154-
elif test -e "${path}/re2_parse.h"; then
154+
elif test -e "${path}/re2.h"; then
155155
re2_inc_path="${path}"
156-
elif test -e "${path}/include/re2/re2_parse.h"; then
156+
elif test -e "${path}/include/re2/re2.h"; then
157157
re2_inc_path="${path}/include"
158158
fi
159159

src/regex/backend/re2.cc

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,55 +44,71 @@ Re2::Re2(const std::string& pattern)
4444
{
4545
}
4646

47-
std::list<RegexMatch> Re2::searchAll(const std::string& s) const {
48-
std::list<RegexMatch> retList;
49-
50-
re2::StringPiece subject(s);
51-
52-
size_t offset = 0;
53-
while (offset <= s.size()) {
54-
int ngroups = re.NumberOfCapturingGroups() + 1;
55-
re2::StringPiece submatches[ngroups];
47+
static bool do_match(
48+
const RE2 &re,
49+
const char *s,
50+
size_t n,
51+
RegexMatch *m,
52+
ssize_t max_groups,
53+
size_t offset)
54+
{
55+
if (m == nullptr) {
56+
max_groups = 0;
57+
}
5658

57-
if (!re.Match(subject, offset, s.size(), RE2::UNANCHORED,
58-
&submatches[0], ngroups)) {
59-
break;
59+
// "+1" is required for full match (aka group 0)
60+
size_t ngroups = re.NumberOfCapturingGroups() + 1;
61+
if (max_groups >= 0 && max_groups < ngroups) {
62+
ngroups = max_groups;
63+
}
64+
re2::StringPiece submatches[ngroups];
65+
66+
if (re.Match(re2::StringPiece(s, n), offset, n, RE2::UNANCHORED,
67+
&submatches[0], ngroups)) {
68+
if (ngroups != 0) {
69+
RegexMatch::MatchGroupContainer groups;
70+
groups.reserve(ngroups);
71+
for (size_t i = 0; i < ngroups; i++) {
72+
size_t start = submatches[i].data() - s;
73+
std::string group = submatches[i].as_string();
74+
groups.push_back(MatchGroup{start, std::move(group)});
75+
}
76+
*m = RegexMatch(std::move(groups));
6077
}
78+
return true;
79+
}
80+
return false;
81+
}
6182

62-
for (int i = 0; i < ngroups; i++) {
63-
// N.B. StringPiece::as_string returns value, not reference
64-
auto match_string = submatches[i].as_string();
65-
auto start = &submatches[i][0] - &subject[0];
66-
retList.push_front(RegexMatch(std::move(match_string), start));
67-
}
83+
std::vector<RegexMatch> Re2::searchAll(const std::string& s, bool overlapping) const {
84+
std::vector<RegexMatch> res;
85+
size_t offset = 0;
6886

69-
offset = (&submatches[0][0] - &subject[0]) + submatches[0].length();
70-
if (submatches[0].size() == 0) {
71-
offset++;
87+
while (1) {
88+
RegexMatch m;
89+
bool match = do_match(re, s.data(), s.size(), &m, -1, offset);
90+
if (!match) break;
91+
92+
if (overlapping) {
93+
// start just after the beginning of the last match
94+
offset = m.group(0).offset + 1;
95+
} else {
96+
// start just at the end of the last match
97+
offset = m.group(0).offset + m.group(0).string.size();
98+
if (offset == m.group(0).offset) {
99+
// empty match - advance by one to not match empty string repeatedly
100+
offset++;
101+
}
72102
}
103+
res.push_back(std::move(m));
73104
}
74-
75-
return retList;
105+
return res;
76106
}
77107

78-
int Re2::search(const std::string& s, RegexMatch *match) const {
79-
re2::StringPiece subject(s);
80-
re2::StringPiece submatches[1];
81-
if (re.Match(subject, 0, s.size(), RE2::UNANCHORED, &submatches[0], 1)) {
82-
// N.B. StringPiece::as_string returns value, not reference
83-
auto match_string = submatches[0].as_string();
84-
auto start = &submatches[0][0] - &subject[0];
85-
*match = RegexMatch(std::move(match_string), start);
86-
return 1;
87-
} else {
88-
return 0;
89-
}
108+
bool Re2::search(const std::string &s, RegexMatch *m, ssize_t max_groups) const {
109+
return do_match(re, s.data(), s.size(), m, max_groups, 0);
90110
}
91111

92-
int Re2::search(const std::string& s) const {
93-
re2::StringPiece subject(s);
94-
return re.Match(subject, 0, s.size(), RE2::UNANCHORED, NULL, 0);
95-
}
96112
#endif
97113

98114
} // namespace backend

0 commit comments

Comments
 (0)