MINOR: map: Add regex matching replacement
This patch declares a new map which provides a string based on
a string with back references replaced by the content matched
by the regex.
diff --git a/src/map.c b/src/map.c
index 35feea9..a28ceda 100644
--- a/src/map.c
+++ b/src/map.c
@@ -163,6 +163,7 @@
{
struct map_descriptor *desc;
struct pattern *pat;
+ struct chunk *str;
/* get config */
desc = arg_p[0].data.map;
@@ -172,8 +173,19 @@
/* Match case. */
if (pat) {
- /* Copy sample. */
if (pat->data) {
+ /* In the regm case, merge the sample with the input. */
+ if ((long)private == PAT_MATCH_REGM) {
+ str = get_trash_chunk();
+ str->len = exp_replace(str->str, str->size, smp->data.u.str.str,
+ pat->data->u.str.str,
+ (regmatch_t *)smp->ctx.a[0]);
+ if (str->len == -1)
+ return 0;
+ smp->data.u.str = *str;
+ return 1;
+ }
+ /* Copy sample. */
smp->data = *pat->data;
smp->flags |= SMP_F_CONST;
return 1;
@@ -242,6 +254,7 @@
{ "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
{ "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
{ "map_reg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REG },
+ { "map_regm", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REGM},
{ "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_STR, (void *)PAT_MATCH_INT },
{ "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, (void *)PAT_MATCH_IP },