Skip to content

Commit 97bf626

Browse files
authored
Provide Regex::exec backwards compatibility (#12549)
This tweaks #12546 to maintain ABI compatibility for the already existing exec functions.
1 parent d95d6a4 commit 97bf626

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

include/tsutil/Regex.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,44 @@ class Regex
125125
*
126126
* It is safe to call this method concurrently on the same instance of @a this.
127127
*/
128-
bool exec(std::string_view subject, uint32_t flags = 0) const;
128+
bool exec(std::string_view subject) const;
129+
130+
/** Execute the regular expression.
131+
*
132+
* @param subject String to match against.
133+
* @param flags Match flags (e.g., RE_NOTEMPTY).
134+
* @return @c true if the pattern matched, @a false if not.
135+
*
136+
* It is safe to call this method concurrently on the same instance of @a this.
137+
*/
138+
bool exec(std::string_view subject, uint32_t flags) const;
139+
140+
/** Execute the regular expression.
141+
*
142+
* @param subject String to match against.
143+
* @param matches Place to store the capture groups.
144+
* @return @c The number of capture groups. < 0 if an error occurred. 0 if the number of Matches is too small.
145+
*
146+
* It is safe to call this method concurrently on the same instance of @a this.
147+
*
148+
* Each capture group takes 3 elements of @a ovector, therefore @a ovecsize must
149+
* be a multiple of 3 and at least three times the number of desired capture groups.
150+
*/
151+
int exec(std::string_view subject, RegexMatches &matches) const;
129152

130153
/** Execute the regular expression.
131154
*
132155
* @param subject String to match against.
133156
* @param matches Place to store the capture groups.
157+
* @param flags Match flags (e.g., RE_NOTEMPTY).
134158
* @return @c The number of capture groups. < 0 if an error occurred. 0 if the number of Matches is too small.
135159
*
136160
* It is safe to call this method concurrently on the same instance of @a this.
137161
*
138162
* Each capture group takes 3 elements of @a ovector, therefore @a ovecsize must
139163
* be a multiple of 3 and at least three times the number of desired capture groups.
140164
*/
141-
int exec(std::string_view subject, RegexMatches &matches, uint32_t flags = 0) const;
165+
int exec(std::string_view subject, RegexMatches &matches, uint32_t flags) const;
142166

143167
/// @return The number of capture groups in the compiled pattern.
144168
int get_capture_count();

src/tsutil/Regex.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ Regex::compile(std::string_view pattern, std::string &error, int &erroroffset, u
295295
return true;
296296
}
297297

298+
//----------------------------------------------------------------------------
299+
bool
300+
Regex::exec(std::string_view subject) const
301+
{
302+
return this->exec(subject, 0);
303+
}
304+
298305
//----------------------------------------------------------------------------
299306
bool
300307
Regex::exec(std::string_view subject, uint32_t flags) const
@@ -308,6 +315,13 @@ Regex::exec(std::string_view subject, uint32_t flags) const
308315
return count > 0;
309316
}
310317

318+
//----------------------------------------------------------------------------
319+
int32_t
320+
Regex::exec(std::string_view subject, RegexMatches &matches) const
321+
{
322+
return this->exec(subject, matches, 0);
323+
}
324+
311325
//----------------------------------------------------------------------------
312326
int32_t
313327
Regex::exec(std::string_view subject, RegexMatches &matches, uint32_t flags) const

0 commit comments

Comments
 (0)