mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-02-26 19:52:06 +01:00
MINOR: sample: add rtrim converter
This converter strips specified characters from the end of a string.
This commit is contained in:
parent
51fc9d1bf1
commit
568415a51f
@ -14442,6 +14442,10 @@ capture-res(<id>)
|
||||
"http-response capture", "capture.req.hdr" and
|
||||
"capture.res.hdr" (sample fetches).
|
||||
|
||||
rtrim(<chars>)
|
||||
Skips any characters from <chars> from the end of the string representation
|
||||
of the input sample.
|
||||
|
||||
sdbm([<avalanche>])
|
||||
Hashes a binary input sample into an unsigned 32-bit quantity using the SDBM
|
||||
hash function. Optionally, it is possible to apply a full avalanche hash
|
||||
|
||||
21
src/sample.c
21
src/sample.c
@ -3015,6 +3015,26 @@ static int sample_conv_ltrim(const struct arg *arg_p, struct sample *smp, void *
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**/
|
||||
static int sample_conv_rtrim(const struct arg *arg_p, struct sample *smp, void *private)
|
||||
{
|
||||
char *delimiters, *p;
|
||||
size_t dlen, l;
|
||||
|
||||
delimiters = arg_p[0].data.str.area;
|
||||
dlen = arg_p[0].data.str.data;
|
||||
|
||||
l = smp->data.u.str.data;
|
||||
p = smp->data.u.str.area + l - 1;
|
||||
while (l && memchr(delimiters, *p, dlen) != NULL) {
|
||||
p--;
|
||||
l--;
|
||||
}
|
||||
|
||||
smp->data.u.str.data = l;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* All supported sample fetch functions must be declared here */
|
||||
/************************************************************************/
|
||||
@ -3486,6 +3506,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
||||
{ "htonl", sample_conv_htonl, 0, NULL, SMP_T_SINT, SMP_T_BIN },
|
||||
{ "cut_crlf", sample_conv_cut_crlf, 0, NULL, SMP_T_STR, SMP_T_STR },
|
||||
{ "ltrim", sample_conv_ltrim, ARG1(1,STR), NULL, SMP_T_STR, SMP_T_STR },
|
||||
{ "rtrim", sample_conv_rtrim, ARG1(1,STR), NULL, SMP_T_STR, SMP_T_STR },
|
||||
{ NULL, NULL, 0, 0, 0 },
|
||||
}};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user