Skip to content

Commit 7aae5dc

Browse files
zimmerleFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Fix Regex::searchAll to behave like global modifier
1 parent 4d66481 commit 7aae5dc

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/utils/regex.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,31 @@ Regex::~Regex() {
7272

7373

7474
std::list<SMatch> Regex::searchAll(const std::string& s) {
75-
int ovector[OVECCOUNT];
76-
std::list<SMatch> retList;
77-
int i;
7875
const char *subject = s.c_str();
79-
int rc;
8076
const std::string tmpString = std::string(s.c_str(), s.size());
77+
int ovector[OVECCOUNT];
78+
int rc, i, offset = 0;
79+
std::list<SMatch> retList;
8180

82-
rc = pcre_exec(m_pc, m_pce, subject,
83-
s.size(), 0, 0, ovector, OVECCOUNT);
84-
85-
for (i = 0; i < rc; i++) {
86-
SMatch match;
87-
size_t start = ovector[2*i];
88-
size_t end = ovector[2*i+1];
89-
size_t len = end - start;
90-
if (end > s.size()) {
91-
continue;
81+
do {
82+
rc = pcre_exec(m_pc, m_pce, subject,
83+
s.size() - offset, offset, 0, ovector, OVECCOUNT);
84+
85+
for (i = 0; i < rc; i++) {
86+
SMatch match;
87+
size_t start = ovector[2*i];
88+
size_t end = ovector[2*i+1];
89+
size_t len = end - start;
90+
if (end > s.size()) {
91+
continue;
92+
}
93+
match.match = std::string(tmpString, start, len);
94+
match.m_offset = start;
95+
match.m_length = len;
96+
offset = start + len;
97+
retList.push_front(match);
9298
}
93-
match.match = std::string(tmpString, start, len);
94-
match.m_offset = start;
95-
match.m_length = len;
96-
retList.push_front(match);
97-
}
99+
} while (rc > 0);
98100

99101
return retList;
100102
}

0 commit comments

Comments
 (0)