Commit 44080166 authored by Geoff Simmons's avatar Geoff Simmons

Document the element parameter.

parent c71e7938
...@@ -25,7 +25,8 @@ SYNOPSIS ...@@ -25,7 +25,8 @@ SYNOPSIS
import selector; import selector;
# Set creation # Set creation
new <obj> = selector.set([BOOL case_sensitive]) new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex] VOID <obj>.add(STRING [, STRING string] [, STRING regex]
[, BACKEND backend] [, INT integer]) [, BACKEND backend] [, INT integer])
VOID <obj>.compile() VOID <obj>.compile()
...@@ -42,12 +43,13 @@ SYNOPSIS ...@@ -42,12 +43,13 @@ SYNOPSIS
# Retrieving objects after match # Retrieving objects after match
STRING <obj>.element([INT n] [, ENUM select]) STRING <obj>.element([INT n] [, ENUM select])
STRING <obj>.string([INT n] [, ENUM select]) STRING <obj>.string([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, ENUM select]) INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BACKEND <obj>.backend([INT n] [, ENUM select]) BACKEND <obj>.backend([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.re_match(STRING [, INT n] [, ENUM select]) BOOL <obj>.re_match(STRING [, INT n] [, STRING element]
[, ENUM select])
STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n] STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n]
[, ENUM select]) [, STRING element] [, ENUM select])
# VMOD version # VMOD version
STRING selector.version() STRING selector.version()
...@@ -236,51 +238,74 @@ uses it may be necessary to identify one matching element of the set; ...@@ -236,51 +238,74 @@ uses it may be necessary to identify one matching element of the set;
this is done in particular for the ``.element()``, ``.backend()``, this is done in particular for the ``.element()``, ``.backend()``,
``.string()``, ``.integer()``, ``.re_match()`` and ``.sub()`` methods, ``.string()``, ``.integer()``, ``.re_match()`` and ``.sub()`` methods,
which retrieve data associated with a specific set element. For such which retrieve data associated with a specific set element. For such
cases, the method parameters ``INT n`` and ``ENUM select`` are used to cases, the method parameters ``INT n``, ``STRING element`` and ``ENUM
choose a matched element. select`` are used to choose a matched element.
As indicated in the example, elements of a set are implicitly numbered As indicated in the example, elements of a set are implicitly numbered
in the order in which they were added to the set using the ``.add()`` in the order in which they were added to the set using the ``.add()``
method, starting from 1. In all of the following, the ``n`` and method, starting from 1. In all of the following, the ``n``,
``select`` parameters for a method call are evaluated as follows: ``element`` and ``select`` parameters for a method call are evaluated
as follows:
* If ``n`` >= 1, then the ``n``-th element of the set is chosen, and * If ``n`` >= 1, then the ``n``-th element of the set is chosen, and
the ``select`` parameter has no effect. A method with ``n`` >= 1 can the ``element`` and ``select`` parameters have no effect. A method
be called in any context, and does not depend on prior match with ``n`` >= 1 can be called in any context, and does not depend on
operations. This is essentially a lookup by index. prior match operations. This is essentially a lookup by index.
* If ``n`` is greater than the number of elements in the set, the * If ``n`` is greater than the number of elements in the set, the
method invokes VCL failure (see `ERRORS`_). method invokes VCL failure (see `ERRORS`_).
* If ``n`` <= 0, then the ``select`` parameter is used to choose an * If ``n`` <= 0 and the ``element`` parameter is set, then the VMOD
element based on the most recent ``.match()`` or ``.hasprefix()`` searches for the string specified by ``element``, in the same way
call for the same set object in the same task scope; that is, the that the ``.match()`` method is executed. This is in essence a
most recent call in the same client or backend context. Thus a lookup in an associative array.
method call in one of the ``vcl_backend_*`` subroutines refers back
to the most recent ``.match()`` or ``.hasprefix()`` invocation in If ``element`` is set but the lookup fails, that is if there is no
the same backend context. such element in the set, then VCL failure is invoked. If the lookup
for the ``element`` succeeds, then the successful match establishes
``n`` is 0 by default, so it can be left out of the method call for a match context for subsequent code. That means that the rules
this purpose. presently described can be applied again, as if ``.match()`` had
returned ``true`` for the ``element`` (internally, that is in fact
* If ``n`` <= 0 and neither of ``.match()`` or ``.hasprefix()`` has what happens).
been called for the same set object in the same task scope, or if
the most recent call resulted in a failed match, then the method The internal match against ``element`` is case sensitive if and only
invokes VCL failure. if the ``case_sensitive`` flag was ``true`` in the set constructor
(this is the default).
* When ``n`` <= 0 after a successful ``.match()`` call, then for any
value of ``select``, the element chosen is the one that matched. ``n`` is 0 by default, so it can be left out of the method call when
``element`` is set.
* When ``n`` <= 0 after a successful ``.hasprefix()`` call, then the
value of ``select`` determines the element chosen, as follows: * If ``n`` <= 0 and ``element`` is unset, then the ``select``
parameter is used to choose an element based on the most recent
``.match()`` or ``.hasprefix()`` call for the same set object in the
same task scope; that is, the most recent call in the same client or
backend context. Thus a method call in one of the ``vcl_backend_*``
subroutines refers back to the most recent ``.match()`` or
``.hasprefix()`` invocation in the same backend context.
By default, ``n`` is 0 and ``element`` is unset, so both of them can
be left out of the call to use ``select``.
* If ``n`` <= 0 and ``element`` is unset, and neither of ``.match()``
or ``.hasprefix()`` has been called for the same set object in the
same task scope, or if the most recent call resulted in a failed
match, then the method invokes VCL failure.
* When ``n`` <= 0 and ``element`` is unset after a successful
``.match()`` call, then for any value of ``select``, the element
chosen is the one that matched.
* When ``n`` <= 0 and ``element`` is unset after a successful
``.hasprefix()`` call, then the value of ``select`` determines the
element chosen, as follows:
* ``UNIQUE`` (default): if exactly one element of the set matched, * ``UNIQUE`` (default): if exactly one element of the set matched,
choose that element. The method invokes VCL failure in this case choose that element. The method invokes VCL failure in this case
if more than one element matched. if more than one element matched.
Since the defaults for ``n`` and ``select`` are 0 and ``UNIQUE``, Since the defaults for ``n`` and ``select`` are 0 and ``UNIQUE``,
``select=UNIQUE`` is in effect if both parameters are left out of and ``element`` is unset by default, ``select=UNIQUE`` is in
the method call. effect if all three parameters are left out of the method call.
* ``EXACT``: if one of the elements in the set matched exactly (even * ``EXACT``: if one of the elements in the set matched exactly (even
if other prefixes in the set matched as well), choose that if other prefixes in the set matched as well), choose that
...@@ -325,6 +350,33 @@ or the longest match, and so on:: ...@@ -325,6 +350,33 @@ or the longest match, and so on::
# bar_backend for /foo/bar/quux # bar_backend for /foo/bar/quux
# foo_backend for /foo/quux # foo_backend for /foo/quux
To re-state the rules more informally:
* Use only one of ``n``, ``element`` or ``select`` to select a string
in the set.
* If ``n`` > 0, use ``n``. ``n`` = 0 by default.
* Otherwise if ``element`` is set, use ``element``. ``element`` is
unset by default.
* Otherwise use ``select``, default ``UNIQUE``.
* ``n`` is a lookup by numeric index, as implied by the order of
``.add()`` in ``vcl_init``.
* ``element`` is an associative array lookup by string.
* ``select`` refers back to the previous invocation of ``.match()`` or
``.hasprefix()``.
* The value of ``select`` is irrelevant (and can just as well be
left out) if the prior invocation was ``.match()``, or if it was
``.hasprefix()`` and exactly one string was found (which is always
the case if strings in the set have no common
prefixes). ``select`` is meant to pick an element when
``.hasprefix()`` finds more than one string.
.. _selector.set(): .. _selector.set():
new xset = selector.set(BOOL case_sensitive, BOOL allow_overlaps) new xset = selector.set(BOOL case_sensitive, BOOL allow_overlaps)
...@@ -732,13 +784,13 @@ BACKEND xset.backend(INT n, STRING element, ENUM select) ...@@ -732,13 +784,13 @@ BACKEND xset.backend(INT n, STRING element, ENUM select)
) )
Returns the backend associated with the element of the set indicated Returns the backend associated with the element of the set indicated
by ``n`` and ``select``, according to the rules given above; that is, by ``n``, ``element`` and ``select``, according to the rules given
it returns the backend that was set via the ``backend`` parameter in above; that is, it returns the backend that was set via the
``.add()``. ``backend`` parameter in ``.add()``.
``.backend()`` invokes VCL failure if: ``.backend()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No backend was set with the ``backend`` parameter in the ``.add()`` * No backend was set with the ``backend`` parameter in the ``.add()``
call corresponding to the selected element. call corresponding to the selected element.
...@@ -765,12 +817,12 @@ STRING xset.string(INT n, STRING element, ENUM select) ...@@ -765,12 +817,12 @@ STRING xset.string(INT n, STRING element, ENUM select)
) )
Returns the string set by the ``string`` parameter for the element of Returns the string set by the ``string`` parameter for the element of
the set indicated by ``n`` and ``select``, according to the rules the set indicated by ``n``, ``element`` and ``select``, according to
given above. the rules given above.
``.string()`` invokes VCL failure if: ``.string()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No string was set with the ``string`` parameter in ``.add()``. * No string was set with the ``string`` parameter in ``.add()``.
...@@ -794,13 +846,13 @@ INT xset.integer(INT n, STRING element, ENUM select) ...@@ -794,13 +846,13 @@ INT xset.integer(INT n, STRING element, ENUM select)
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
) )
Returns the integer set by the ``integer`` parameter for the element of Returns the integer set by the ``integer`` parameter for the element
the set indicated by ``n`` and ``select``, according to the rules of the set indicated by ``n``, ``element`` and ``select``, according
given above. to the rules given above.
``.integer()`` invokes VCL failure if: ``.integer()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No integer was set with the ``integer`` parameter in ``.add()``. * No integer was set with the ``integer`` parameter in ``.add()``.
...@@ -831,10 +883,10 @@ BOOL xset.re_match(STRING subject, INT n, STRING element, ENUM select) ...@@ -831,10 +883,10 @@ BOOL xset.re_match(STRING subject, INT n, STRING element, ENUM select)
) )
Using the regular expression set by the ``regex`` parameter for the Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the element of the set indicated by ``n``, ``element`` and ``select``,
result of matching the regex against ``subject``. The regex match is return the result of matching the regex against ``subject``. The regex
the same operation performed for the native VCL ``~`` operator, see match is the same operation performed for the native VCL ``~``
vcl(7). operator, see vcl(7).
In other words, this method can be used to perform a second match with In other words, this method can be used to perform a second match with
the saved regular expression, after matching a fixed string against the saved regular expression, after matching a fixed string against
...@@ -847,7 +899,7 @@ parameters ``pcre_match_limit`` and ``pcre_match_limit_recursion`` ...@@ -847,7 +899,7 @@ parameters ``pcre_match_limit`` and ``pcre_match_limit_recursion``
``.re_match()`` invokes VCL failure if: ``.re_match()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No regular expression was set with the ``regex`` parameter in * No regular expression was set with the ``regex`` parameter in
``.add()``. ``.add()``.
...@@ -884,8 +936,8 @@ STRING xset.sub(STRING str, STRING sub, BOOL all, INT n, STRING element, ENUM se ...@@ -884,8 +936,8 @@ STRING xset.sub(STRING str, STRING sub, BOOL all, INT n, STRING element, ENUM se
) )
Using the regular expression set by the ``regex`` parameter for the Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the element of the set indicated by ``n``, ``element`` and ``select``,
result of a substitution using ``str`` and ``sub``. return the result of a substitution using ``str`` and ``sub``.
If ``all`` is ``false``, then return the result of replacing the first If ``all`` is ``false``, then return the result of replacing the first
portion of ``str`` that matches the regex with ``sub``. ``sub`` may portion of ``str`` that matches the regex with ``sub``. ``sub`` may
...@@ -901,7 +953,7 @@ VCL's ``regsuball(str, regex, sub)``. ...@@ -901,7 +953,7 @@ VCL's ``regsuball(str, regex, sub)``.
``.sub()`` invokes VCL failure if: ``.sub()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No regular expression was set with the ``regex`` parameter in * No regular expression was set with the ``regex`` parameter in
``.add()``. ``.add()``.
......
...@@ -21,7 +21,8 @@ SYNOPSIS ...@@ -21,7 +21,8 @@ SYNOPSIS
import selector; import selector;
# Set creation # Set creation
new <obj> = selector.set([BOOL case_sensitive]) new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex] VOID <obj>.add(STRING [, STRING string] [, STRING regex]
[, BACKEND backend] [, INT integer]) [, BACKEND backend] [, INT integer])
VOID <obj>.compile() VOID <obj>.compile()
...@@ -38,12 +39,13 @@ SYNOPSIS ...@@ -38,12 +39,13 @@ SYNOPSIS
# Retrieving objects after match # Retrieving objects after match
STRING <obj>.element([INT n] [, ENUM select]) STRING <obj>.element([INT n] [, ENUM select])
STRING <obj>.string([INT n] [, ENUM select]) STRING <obj>.string([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, ENUM select]) INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BACKEND <obj>.backend([INT n] [, ENUM select]) BACKEND <obj>.backend([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.re_match(STRING [, INT n] [, ENUM select]) BOOL <obj>.re_match(STRING [, INT n] [, STRING element]
[, ENUM select])
STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n] STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n]
[, ENUM select]) [, STRING element] [, ENUM select])
# VMOD version # VMOD version
STRING selector.version() STRING selector.version()
...@@ -232,51 +234,74 @@ uses it may be necessary to identify one matching element of the set; ...@@ -232,51 +234,74 @@ uses it may be necessary to identify one matching element of the set;
this is done in particular for the ``.element()``, ``.backend()``, this is done in particular for the ``.element()``, ``.backend()``,
``.string()``, ``.integer()``, ``.re_match()`` and ``.sub()`` methods, ``.string()``, ``.integer()``, ``.re_match()`` and ``.sub()`` methods,
which retrieve data associated with a specific set element. For such which retrieve data associated with a specific set element. For such
cases, the method parameters ``INT n`` and ``ENUM select`` are used to cases, the method parameters ``INT n``, ``STRING element`` and ``ENUM
choose a matched element. select`` are used to choose a matched element.
As indicated in the example, elements of a set are implicitly numbered As indicated in the example, elements of a set are implicitly numbered
in the order in which they were added to the set using the ``.add()`` in the order in which they were added to the set using the ``.add()``
method, starting from 1. In all of the following, the ``n`` and method, starting from 1. In all of the following, the ``n``,
``select`` parameters for a method call are evaluated as follows: ``element`` and ``select`` parameters for a method call are evaluated
as follows:
* If ``n`` >= 1, then the ``n``-th element of the set is chosen, and * If ``n`` >= 1, then the ``n``-th element of the set is chosen, and
the ``select`` parameter has no effect. A method with ``n`` >= 1 can the ``element`` and ``select`` parameters have no effect. A method
be called in any context, and does not depend on prior match with ``n`` >= 1 can be called in any context, and does not depend on
operations. This is essentially a lookup by index. prior match operations. This is essentially a lookup by index.
* If ``n`` is greater than the number of elements in the set, the * If ``n`` is greater than the number of elements in the set, the
method invokes VCL failure (see `ERRORS`_). method invokes VCL failure (see `ERRORS`_).
* If ``n`` <= 0, then the ``select`` parameter is used to choose an * If ``n`` <= 0 and the ``element`` parameter is set, then the VMOD
element based on the most recent ``.match()`` or ``.hasprefix()`` searches for the string specified by ``element``, in the same way
call for the same set object in the same task scope; that is, the that the ``.match()`` method is executed. This is in essence a
most recent call in the same client or backend context. Thus a lookup in an associative array.
method call in one of the ``vcl_backend_*`` subroutines refers back
to the most recent ``.match()`` or ``.hasprefix()`` invocation in If ``element`` is set but the lookup fails, that is if there is no
the same backend context. such element in the set, then VCL failure is invoked. If the lookup
for the ``element`` succeeds, then the successful match establishes
``n`` is 0 by default, so it can be left out of the method call for a match context for subsequent code. That means that the rules
this purpose. presently described can be applied again, as if ``.match()`` had
returned ``true`` for the ``element`` (internally, that is in fact
* If ``n`` <= 0 and neither of ``.match()`` or ``.hasprefix()`` has what happens).
been called for the same set object in the same task scope, or if
the most recent call resulted in a failed match, then the method The internal match against ``element`` is case sensitive if and only
invokes VCL failure. if the ``case_sensitive`` flag was ``true`` in the set constructor
(this is the default).
* When ``n`` <= 0 after a successful ``.match()`` call, then for any
value of ``select``, the element chosen is the one that matched. ``n`` is 0 by default, so it can be left out of the method call when
``element`` is set.
* When ``n`` <= 0 after a successful ``.hasprefix()`` call, then the
value of ``select`` determines the element chosen, as follows: * If ``n`` <= 0 and ``element`` is unset, then the ``select``
parameter is used to choose an element based on the most recent
``.match()`` or ``.hasprefix()`` call for the same set object in the
same task scope; that is, the most recent call in the same client or
backend context. Thus a method call in one of the ``vcl_backend_*``
subroutines refers back to the most recent ``.match()`` or
``.hasprefix()`` invocation in the same backend context.
By default, ``n`` is 0 and ``element`` is unset, so both of them can
be left out of the call to use ``select``.
* If ``n`` <= 0 and ``element`` is unset, and neither of ``.match()``
or ``.hasprefix()`` has been called for the same set object in the
same task scope, or if the most recent call resulted in a failed
match, then the method invokes VCL failure.
* When ``n`` <= 0 and ``element`` is unset after a successful
``.match()`` call, then for any value of ``select``, the element
chosen is the one that matched.
* When ``n`` <= 0 and ``element`` is unset after a successful
``.hasprefix()`` call, then the value of ``select`` determines the
element chosen, as follows:
* ``UNIQUE`` (default): if exactly one element of the set matched, * ``UNIQUE`` (default): if exactly one element of the set matched,
choose that element. The method invokes VCL failure in this case choose that element. The method invokes VCL failure in this case
if more than one element matched. if more than one element matched.
Since the defaults for ``n`` and ``select`` are 0 and ``UNIQUE``, Since the defaults for ``n`` and ``select`` are 0 and ``UNIQUE``,
``select=UNIQUE`` is in effect if both parameters are left out of and ``element`` is unset by default, ``select=UNIQUE`` is in
the method call. effect if all three parameters are left out of the method call.
* ``EXACT``: if one of the elements in the set matched exactly (even * ``EXACT``: if one of the elements in the set matched exactly (even
if other prefixes in the set matched as well), choose that if other prefixes in the set matched as well), choose that
...@@ -321,6 +346,33 @@ or the longest match, and so on:: ...@@ -321,6 +346,33 @@ or the longest match, and so on::
# bar_backend for /foo/bar/quux # bar_backend for /foo/bar/quux
# foo_backend for /foo/quux # foo_backend for /foo/quux
To re-state the rules more informally:
* Use only one of ``n``, ``element`` or ``select`` to select a string
in the set.
* If ``n`` > 0, use ``n``. ``n`` = 0 by default.
* Otherwise if ``element`` is set, use ``element``. ``element`` is
unset by default.
* Otherwise use ``select``, default ``UNIQUE``.
* ``n`` is a lookup by numeric index, as implied by the order of
``.add()`` in ``vcl_init``.
* ``element`` is an associative array lookup by string.
* ``select`` refers back to the previous invocation of ``.match()`` or
``.hasprefix()``.
* The value of ``select`` is irrelevant (and can just as well be
left out) if the prior invocation was ``.match()``, or if it was
``.hasprefix()`` and exactly one string was found (which is always
the case if strings in the set have no common
prefixes). ``select`` is meant to pick an element when
``.hasprefix()`` finds more than one string.
$Object set(BOOL case_sensitive=1, BOOL allow_overlaps=1) $Object set(BOOL case_sensitive=1, BOOL allow_overlaps=1)
Create a set object. Create a set object.
...@@ -658,13 +710,13 @@ $Method BACKEND .backend(INT n=0, STRING element=0, ...@@ -658,13 +710,13 @@ $Method BACKEND .backend(INT n=0, STRING element=0,
select=UNIQUE) select=UNIQUE)
Returns the backend associated with the element of the set indicated Returns the backend associated with the element of the set indicated
by ``n`` and ``select``, according to the rules given above; that is, by ``n``, ``element`` and ``select``, according to the rules given
it returns the backend that was set via the ``backend`` parameter in above; that is, it returns the backend that was set via the
``.add()``. ``backend`` parameter in ``.add()``.
``.backend()`` invokes VCL failure if: ``.backend()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No backend was set with the ``backend`` parameter in the ``.add()`` * No backend was set with the ``backend`` parameter in the ``.add()``
call corresponding to the selected element. call corresponding to the selected element.
...@@ -682,12 +734,12 @@ $Method STRING .string(INT n=0, STRING element=0, ...@@ -682,12 +734,12 @@ $Method STRING .string(INT n=0, STRING element=0,
select=UNIQUE) select=UNIQUE)
Returns the string set by the ``string`` parameter for the element of Returns the string set by the ``string`` parameter for the element of
the set indicated by ``n`` and ``select``, according to the rules the set indicated by ``n``, ``element`` and ``select``, according to
given above. the rules given above.
``.string()`` invokes VCL failure if: ``.string()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No string was set with the ``string`` parameter in ``.add()``. * No string was set with the ``string`` parameter in ``.add()``.
...@@ -702,13 +754,13 @@ $Method INT .integer(INT n=0, STRING element=0, ...@@ -702,13 +754,13 @@ $Method INT .integer(INT n=0, STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE) select=UNIQUE)
Returns the integer set by the ``integer`` parameter for the element of Returns the integer set by the ``integer`` parameter for the element
the set indicated by ``n`` and ``select``, according to the rules of the set indicated by ``n``, ``element`` and ``select``, according
given above. to the rules given above.
``.integer()`` invokes VCL failure if: ``.integer()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No integer was set with the ``integer`` parameter in ``.add()``. * No integer was set with the ``integer`` parameter in ``.add()``.
...@@ -729,10 +781,10 @@ $Method BOOL .re_match(STRING subject, INT n=0, STRING element=0, ...@@ -729,10 +781,10 @@ $Method BOOL .re_match(STRING subject, INT n=0, STRING element=0,
select=UNIQUE) select=UNIQUE)
Using the regular expression set by the ``regex`` parameter for the Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the element of the set indicated by ``n``, ``element`` and ``select``,
result of matching the regex against ``subject``. The regex match is return the result of matching the regex against ``subject``. The regex
the same operation performed for the native VCL ``~`` operator, see match is the same operation performed for the native VCL ``~``
vcl(7). operator, see vcl(7).
In other words, this method can be used to perform a second match with In other words, this method can be used to perform a second match with
the saved regular expression, after matching a fixed string against the saved regular expression, after matching a fixed string against
...@@ -745,7 +797,7 @@ parameters ``pcre_match_limit`` and ``pcre_match_limit_recursion`` ...@@ -745,7 +797,7 @@ parameters ``pcre_match_limit`` and ``pcre_match_limit_recursion``
``.re_match()`` invokes VCL failure if: ``.re_match()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No regular expression was set with the ``regex`` parameter in * No regular expression was set with the ``regex`` parameter in
``.add()``. ``.add()``.
...@@ -771,8 +823,8 @@ $Method STRING .sub(STRING str, STRING sub, BOOL all=0, INT n=0, ...@@ -771,8 +823,8 @@ $Method STRING .sub(STRING str, STRING sub, BOOL all=0, INT n=0,
select=UNIQUE) select=UNIQUE)
Using the regular expression set by the ``regex`` parameter for the Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the element of the set indicated by ``n``, ``element`` and ``select``,
result of a substitution using ``str`` and ``sub``. return the result of a substitution using ``str`` and ``sub``.
If ``all`` is ``false``, then return the result of replacing the first If ``all`` is ``false``, then return the result of replacing the first
portion of ``str`` that matches the regex with ``sub``. ``sub`` may portion of ``str`` that matches the regex with ``sub``. ``sub`` may
...@@ -788,7 +840,7 @@ VCL's ``regsuball(str, regex, sub)``. ...@@ -788,7 +840,7 @@ VCL's ``regsuball(str, regex, sub)``.
``.sub()`` invokes VCL failure if: ``.sub()`` invokes VCL failure if:
* The rules for ``n`` and ``select`` indicate failure. * The rules for ``n``, ``element`` and ``select`` indicate failure.
* No regular expression was set with the ``regex`` parameter in * No regular expression was set with the ``regex`` parameter in
``.add()``. ``.add()``.
......
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