Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
0eb6916a
Commit
0eb6916a
authored
Aug 03, 2021
by
Dridi Boukelmoune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vre: Optionally capture groups in a txt array
parent
76f72a39
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
+27
-7
vre.c
lib/libvarnish/vre.c
+27
-7
No files found.
lib/libvarnish/vre.c
View file @
0eb6916a
...
...
@@ -182,11 +182,14 @@ VRE_export(const vre_t *code, size_t *sz)
}
static
int
vre_match
(
const
vre_t
*
code
,
const
char
*
subject
,
size_t
length
,
size_t
offset
,
int
options
,
pcre2_match_data
**
datap
)
vre_capture
(
const
vre_t
*
code
,
const
char
*
subject
,
size_t
length
,
size_t
offset
,
int
options
,
txt
*
groups
,
size_t
*
count
,
pcre2_match_data
**
datap
)
{
pcre2_match_data
*
data
;
pcre2_code
*
re
;
PCRE2_SIZE
*
ovector
;
size_t
nov
,
g
;
int
matches
;
re
=
VRE_unpack
(
code
);
...
...
@@ -202,6 +205,21 @@ vre_match(const vre_t *code, const char *subject, size_t length, size_t offset,
matches
=
pcre2_match
(
re
,
(
PCRE2_SPTR
)
subject
,
length
,
offset
,
options
,
data
,
code
->
re_ctx
);
if
(
groups
!=
NULL
)
{
AN
(
count
);
AN
(
*
count
);
ovector
=
pcre2_get_ovector_pointer
(
data
);
nov
=
pcre2_get_ovector_count
(
data
);
if
(
nov
>
*
count
)
nov
=
*
count
;
for
(
g
=
0
;
g
<
nov
;
g
++
)
{
groups
->
b
=
subject
+
ovector
[
2
*
g
];
groups
->
e
=
subject
+
ovector
[
2
*
g
+
1
];
groups
++
;
}
*
count
=
nov
;
}
if
(
datap
!=
NULL
&&
matches
>
VRE_ERROR_NOMATCH
)
*
datap
=
data
;
else
...
...
@@ -221,7 +239,8 @@ VRE_match(const vre_t *code, const char *subject, size_t length,
if
(
length
==
0
)
length
=
PCRE2_ZERO_TERMINATED
;
vre_limit
(
code
,
lim
);
return
(
vre_match
(
code
,
subject
,
length
,
0
,
options
,
NULL
));
return
(
vre_capture
(
code
,
subject
,
length
,
0
,
options
,
NULL
,
NULL
,
NULL
));
}
int
...
...
@@ -242,7 +261,8 @@ VRE_sub(const vre_t *code, const char *subject, const char *replacement,
AN
(
replacement
);
vre_limit
(
code
,
lim
);
i
=
vre_match
(
code
,
subject
,
PCRE2_ZERO_TERMINATED
,
offset
,
0
,
&
data
);
i
=
vre_capture
(
code
,
subject
,
PCRE2_ZERO_TERMINATED
,
offset
,
0
,
NULL
,
NULL
,
&
data
);
if
(
i
<=
VRE_ERROR_NOMATCH
)
return
(
i
);
...
...
@@ -274,8 +294,8 @@ VRE_sub(const vre_t *code, const char *subject, const char *replacement,
offset
=
ovector
[
1
];
if
(
!
all
)
break
;
i
=
vre_
match
(
code
,
subject
,
PCRE2_ZERO_TERMINATED
,
offset
,
PCRE2_NOTEMPTY
,
&
data
);
i
=
vre_
capture
(
code
,
subject
,
PCRE2_ZERO_TERMINATED
,
offset
,
PCRE2_NOTEMPTY
,
NULL
,
NULL
,
&
data
);
if
(
i
<
VRE_ERROR_NOMATCH
)
return
(
i
);
}
while
(
i
!=
VRE_ERROR_NOMATCH
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment