summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-05-20 07:24:22 +0200
committerTyge Lovset <[email protected]>2023-05-20 07:24:22 +0200
commited9ccf1dcca8d3651e13ff1686148b4b23773721 (patch)
tree0594df357a1b4239a0d38c686099242cc16b0b44 /src
parent26513bb1352ab4e4ffe931aabd80868216afc551 (diff)
downloadSTC-modified-ed9ccf1dcca8d3651e13ff1686148b4b23773721.tar.gz
STC-modified-ed9ccf1dcca8d3651e13ff1686148b4b23773721.zip
Bug fix (NB!): cregex_captures() now returns num of cap. group *excluding* the full match group (0).
Diffstat (limited to 'src')
-rw-r--r--src/cregex.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cregex.c b/src/cregex.c
index 981a256a..5ba07550 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -1251,12 +1251,12 @@ cregex_compile_3(cregex *self, const char* pattern, int cflags) {
int
cregex_captures(const cregex* self) {
- return self->prog ? 1 + self->prog->nsubids : 0;
+ return self->prog ? self->prog->nsubids : 0;
}
int
cregex_find_4(const cregex* re, const char* input, csview match[], int mflags) {
- int res = _regexec(re->prog, input, cregex_captures(re), match, mflags);
+ int res = _regexec(re->prog, input, cregex_captures(re) + 1, match, mflags);
switch (res) {
case 1: return CREG_OK;
case 0: return CREG_NOMATCH;
@@ -1281,7 +1281,7 @@ cregex_replace_sv_6(const cregex* re, csview input, const char* replace, int cou
cstr out = cstr_NULL;
cstr subst = cstr_NULL;
csview match[CREG_MAX_CAPTURES];
- int nmatch = cregex_captures(re);
+ int nmatch = cregex_captures(re) + 1;
if (!count) count = INT32_MAX;
bool copy = !(rflags & CREG_R_STRIP);