Commit 92ef0fa9 authored by Geoff Simmons's avatar Geoff Simmons

Add the EXACT selector.

parent 99818aae
...@@ -161,7 +161,7 @@ INT xset.which(ENUM select) ...@@ -161,7 +161,7 @@ INT xset.which(ENUM select)
:: ::
INT xset.which( INT xset.which(
ENUM {UNIQUE, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
) )
Returns ... Returns ...
......
...@@ -278,6 +278,10 @@ pt_search(const struct pt_y * const restrict y, ...@@ -278,6 +278,10 @@ pt_search(const struct pt_y * const restrict y,
match->min = y->idx; match->min = y->idx;
if (y->idx > match->max) if (y->idx > match->max)
match->max = y->idx; match->max = y->idx;
if (*c == '\0') {
match->exact = y->idx;
return (0);
}
} }
if (i < y->len) if (i < y->len)
...@@ -306,6 +310,7 @@ PT_Prefixes(const struct pt_y * const restrict root, ...@@ -306,6 +310,7 @@ PT_Prefixes(const struct pt_y * const restrict root,
match->n = 0; match->n = 0;
match->min = UINT_MAX; match->min = UINT_MAX;
match->max = 0; match->max = 0;
match->exact = UINT_MAX;
return (pt_search(root, strings, (unsigned char *)subject, match)); return (pt_search(root, strings, (unsigned char *)subject, match));
} }
......
...@@ -40,6 +40,7 @@ struct match_data { ...@@ -40,6 +40,7 @@ struct match_data {
unsigned *indices; unsigned *indices;
unsigned limit; unsigned limit;
unsigned n; unsigned n;
unsigned exact;
unsigned min; unsigned min;
unsigned max; unsigned max;
}; };
......
This diff is collapsed.
...@@ -387,6 +387,8 @@ select(VRT_CTX, const struct match_data * const restrict match, ...@@ -387,6 +387,8 @@ select(VRT_CTX, const struct match_data * const restrict match,
} }
return match->indices[0]; return match->indices[0];
} }
if (selects == vmod_enum_EXACT)
return match->exact;
if (selects == vmod_enum_FIRST) if (selects == vmod_enum_FIRST)
return match->min; return match->min;
if (selects == vmod_enum_LAST) if (selects == vmod_enum_LAST)
......
...@@ -94,7 +94,8 @@ Example:: ...@@ -94,7 +94,8 @@ Example::
# ... # ...
} }
$Method INT .which(ENUM {UNIQUE, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE) $Method INT .which(ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
Returns ... Returns ...
......
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