Commit 512c6512 authored by Geoff Simmons's avatar Geoff Simmons

Remove the .suball() method, use the BOOL param all in .sub() instead.

parent 81cc0105
......@@ -36,7 +36,6 @@ CONTENTS
* :ref:`func_set.re_match`
* :ref:`func_set.string`
* :ref:`func_set.sub`
* :ref:`func_set.suball`
* :ref:`func_set.which`
* :ref:`func_version`
......@@ -267,37 +266,15 @@ Example::
.. _func_set.sub:
STRING xset.sub(STRING str, STRING sub, INT n, ENUM select)
-----------------------------------------------------------
set.sub(...)
------------
::
STRING xset.sub(
STRING str,
STRING sub,
INT n=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
Returns ...
Example::
if (myset.hasprefix(req.url)) {
# ...
}
.. _func_set.suball:
set.suball(...)
---------------
::
STRING xset.suball(
STRING str,
STRING sub,
BOOL all=0,
INT n=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
......
......@@ -21,18 +21,34 @@ varnish v1 -vcl {
}
sub vcl_synth {
set resp.http.N-1-1 = s.sub("_barf_", "\0\0", 1);
set resp.http.N-1-1 = s.sub("_barf_", "\0\0", n=1);
set resp.http.N-1-2
= s.sub("_barf_", resp.http.nosuchheader, 1);
= s.sub("_barf_", resp.http.nosuchheader, n=1);
set resp.http.N-1-3
= "zoom" + s.sub(resp.http.Foomble, "\0\0", 1) + "box";
set resp.http.N-2-1 = s.sub("_barf_", "\4\3\2p", 2);
set resp.http.N-2-2 = s.sub("_barf_", "\4\\\3\2p", 2);
set resp.http.N-2-3 = s.sub("_barf_", "\4\&\3\2p", 2);
set resp.http.N-2-4 = s.sub("_barf_", "\0\4\3\2\\p", 2);
set resp.http.N-3 = s.sub(resp.http.bar, "XXX", 3);
set resp.http.N-4 = s.sub("/", client.ip, 4);
set resp.http.N-5 = s.sub(client.ip, client.ip, 5);
= "zoom" + s.sub(resp.http.Foomble, "\0\0", n=1) + "box";
set resp.http.N-2-1 = s.sub("_barf_", "\4\3\2p", n=2);
set resp.http.N-2-2 = s.sub("_barf_", "\4\\\3\2p", n=2);
set resp.http.N-2-3 = s.sub("_barf_", "\4\&\3\2p", n=2);
set resp.http.N-2-4 = s.sub("_barf_", "\0\4\3\2\\p", n=2);
set resp.http.N-3 = s.sub(resp.http.bar, "XXX", n=3);
set resp.http.N-4 = s.sub("/", client.ip, n=4);
set resp.http.N-5 = s.sub(client.ip, client.ip, n=5);
set resp.http.N-1-1-F = s.sub("_barf_", "\0\0", false, 1);
set resp.http.N-1-2-F
= s.sub("_barf_", resp.http.nosuchheader, false, 1);
set resp.http.N-1-3-F
= "zoom" + s.sub(resp.http.Foomble, "\0\0", false, 1)
+ "box";
set resp.http.N-2-1-F = s.sub("_barf_", "\4\3\2p", false, 2);
set resp.http.N-2-2-F = s.sub("_barf_", "\4\\\3\2p", false, 2);
set resp.http.N-2-3-F = s.sub("_barf_", "\4\&\3\2p", false, 2);
set resp.http.N-2-4-F
= s.sub("_barf_", "\0\4\3\2\\p", false, 2);
set resp.http.N-3-F = s.sub(resp.http.bar, "XXX", false, 3);
set resp.http.N-4-F = s.sub("/", client.ip, false, 4);
set resp.http.N-5-F = s.sub(client.ip, client.ip, false, 5);
return (deliver);
}
} -start
......@@ -51,6 +67,17 @@ client c1 {
expect resp.http.N-3 == "XXX"
expect resp.http.N-4 == "${localhost}"
expect resp.http.N-5 == "${localhost}"
expect resp.http.N-1-1-F == resp.http.N-1-1
expect resp.http.N-1-2-F == resp.http.N-1-2
expect resp.http.N-1-3-F == resp.http.N-1-3
expect resp.http.N-2-1-F == resp.http.N-2-1
expect resp.http.N-2-2-F == resp.http.N-2-2
expect resp.http.N-2-3-F == resp.http.N-2-3
expect resp.http.N-2-4-F == resp.http.N-2-4
expect resp.http.N-3-F == resp.http.N-3
expect resp.http.N-4-F == resp.http.N-4
expect resp.http.N-5-F == resp.http.N-5
} -run
# cf. Varnish c00047.vtc, r01557.vtc, r01566.vtc
......@@ -75,14 +102,15 @@ varnish v1 -vcl {
}
sub vcl_synth {
set resp.http.N-1 = s.suball("barbar", "zz", 1);
set resp.http.N-2 = s.suball("barbar", "zz", 2);
set resp.http.N-3 = s.suball("barbar", "baz", 3);
set resp.http.N-4 = s.suball("barbar", "baz", 4);
set resp.http.N-5-1 = s.suball("bbbar", "b", 5);
set resp.http.N-5-2 = s.suball("barbar", "z", 5);
set resp.http.N-6 = s.suball("barbar", "pong", 6);
set resp.http.N-7 = s.suball("/?foo=0&bar=1&foobar=2", "", 7);
set resp.http.N-1 = s.sub("barbar", "zz", true, n=1);
set resp.http.N-2 = s.sub("barbar", "zz", true, n=2);
set resp.http.N-3 = s.sub("barbar", "baz", true, n=3);
set resp.http.N-4 = s.sub("barbar", "baz", true, n=4);
set resp.http.N-5-1 = s.sub("bbbar", "b", true, n=5);
set resp.http.N-5-2 = s.sub("barbar", "z", true, n=5);
set resp.http.N-6 = s.sub("barbar", "pong", true, n=6);
set resp.http.N-7
= s.sub("/?foo=0&bar=1&foobar=2", "", true, n=7);
return (deliver);
}
}
......
......@@ -701,33 +701,18 @@ vmod_set_re_match(VRT_CTX, struct vmod_selector_set *set, VCL_STRING subject,
return (VRT_re_match(ctx, subject, re));
}
static VCL_STRING
sub(VRT_CTX, struct vmod_selector_set * const restrict set, int all,
VCL_STRING const restrict str, VCL_STRING const restrict sub, VCL_INT n,
VCL_ENUM const restrict selects, const char * const restrict method)
VCL_STRING
vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
VCL_STRING sub, VCL_BOOL all, VCL_INT n, VCL_ENUM selects)
{
vre_t *re;
re = get_re(ctx, set, n, selects, method);
re = get_re(ctx, set, n, selects, "sub");
if (re == NULL)
return (NULL);
return (VRT_regsub(ctx, all, str, re, sub));
}
VCL_STRING
vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
VCL_STRING subst, VCL_INT n, VCL_ENUM selects)
{
return (sub(ctx, set, 0, str, subst, n, selects, "sub"));
}
VCL_STRING
vmod_set_suball(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
VCL_STRING subst, VCL_INT n, VCL_ENUM selects)
{
return (sub(ctx, set, 1, str, subst, n, selects, "suball"));
}
VCL_STRING
vmod_set_debug(VRT_CTX, struct vmod_selector_set *set)
{
......
......@@ -153,24 +153,12 @@ Example::
# ...
}
$Method STRING .sub(STRING str, STRING sub, INT n=0,
$Method STRING .sub(STRING str, STRING sub, BOOL all=0, INT n=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
Returns ...
Example::
if (myset.hasprefix(req.url)) {
# ...
}
$Method STRING .suball(STRING str, STRING sub, INT n=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
Returns ...
Example::
if (myset.hasprefix(req.url)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment