Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-re2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-re2
Commits
452fab32
Commit
452fab32
authored
Mar 29, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factor out some common code for sub(), suball() and extract() in the
C++ implementation
parent
9b897f6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
vre2.cpp
src/vre2/vre2.cpp
+19
-16
No files found.
src/vre2/vre2.cpp
View file @
452fab32
...
...
@@ -182,6 +182,23 @@ vre2_get_group(vre2 *vre2, const char * const name, int * const refnum)
CATCHALL
}
static
inline
const
char
*
copy_on_match
(
const
string
&
result
,
const
int
match
,
char
*
const
dest
,
const
size_t
bytes
,
size_t
*
const
len
)
{
try
{
if
(
!
match
)
return
NULL
;
if
(
result
.
size
()
+
1
>
bytes
)
throw
runtime_error
(
"insufficient workspace"
);
*
len
=
result
.
size
()
+
1
;
result
.
copy
(
dest
,
*
len
);
dest
[
*
len
]
=
'\0'
;
return
NULL
;
}
CATCHALL
}
const
char
*
vre2_replace
(
vre2
*
vre2
,
const
int
all
,
const
char
*
const
text
,
const
char
*
const
rewrite
,
char
*
const
dest
,
const
size_t
bytes
,
...
...
@@ -193,14 +210,7 @@ vre2_replace(vre2 *vre2, const int all, const char * const text,
*
match
=
vre2
->
global_replace
(
&
t
,
rewrite
);
else
*
match
=
vre2
->
replace
(
&
t
,
rewrite
);
if
(
!*
match
)
return
NULL
;
if
(
t
.
size
()
+
1
>
bytes
)
throw
runtime_error
(
"insufficient workspace"
);
*
len
=
t
.
size
()
+
1
;
t
.
copy
(
dest
,
*
len
);
dest
[
*
len
]
=
'\0'
;
return
NULL
;
return
copy_on_match
(
t
,
*
match
,
dest
,
bytes
,
len
);
}
CATCHALL
}
...
...
@@ -213,14 +223,7 @@ vre2_extract(vre2 *vre2, const char * const text, const char * const rewrite,
try
{
string
out
;
*
match
=
vre2
->
extract
(
&
out
,
text
,
rewrite
);
if
(
!*
match
)
return
NULL
;
if
(
out
.
size
()
+
1
>
bytes
)
throw
runtime_error
(
"insufficient workspace"
);
*
len
=
out
.
size
()
+
1
;
out
.
copy
(
dest
,
*
len
);
dest
[
*
len
]
=
'\0'
;
return
NULL
;
return
copy_on_match
(
out
,
*
match
,
dest
,
bytes
,
len
);
}
CATCHALL
}
...
...
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