XLAT_REGISTER_ARGS("log.destination", xlat_func_log_dst, FR_TYPE_STRING, xlat_func_log_dst_args);
XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, FR_TYPE_UINT64, xlat_func_next_time_args);
XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, FR_TYPE_STRING, xlat_func_pairs_args);
+
+ XLAT_REGISTER_ARGS("str.subst", xlat_func_subst, FR_TYPE_STRING, xlat_func_subst_args);
+#ifdef HAVE_REGEX_PCRE2
+ xlat_func_instantiate_set(xlat, xlat_instantiate_subst_regex, xlat_subst_regex_inst_t, NULL, NULL);
+#endif
XLAT_REGISTER_ARGS("subst", xlat_func_subst, FR_TYPE_STRING, xlat_func_subst_args);
+ XLAT_NEW("str.subst");
#ifdef HAVE_REGEX_PCRE2
xlat_func_instantiate_set(xlat, xlat_instantiate_subst_regex, xlat_subst_regex_inst_t, NULL, NULL);
#endif
+
XLAT_REGISTER_ARGS("time", xlat_func_time, FR_TYPE_VOID, xlat_func_time_args);
XLAT_REGISTER_ARGS("trigger", trigger_xlat, FR_TYPE_STRING, trigger_xlat_args);
XLAT_REGISTER_ARGS("base64.encode", xlat_func_base64_encode, FR_TYPE_STRING, xlat_func_base64_encode_arg);
#
# Global substitution
-if (!(%subst(test_string1, 'a', 'b') == 'bbb')) {
+if (!(%str.subst(test_string1, 'a', 'b') == 'bbb')) {
test_fail
}
# No match
-if (!(%subst(test_string1, 'c', 'b') == 'aaa')) {
+if (!(%str.subst(test_string1, 'c', 'b') == 'aaa')) {
test_fail
}
# Line ending rewrite
-if (!(%subst(test_string2, "\n", "\r") == "\r\r\r")) {
+if (!(%str.subst(test_string2, "\n", "\r") == "\r\r\r")) {
test_fail
}
# Removal
-if (!(%subst(test_string1, 'a', '') == "")) {
+if (!(%str.subst(test_string1, 'a', '') == "")) {
test_fail
}
# Removal of last word only
-if (!(%subst(test_string3, 'dog', '') == "the quick brown fox jumped over the lazy ")) {
+if (!(%str.subst(test_string3, 'dog', '') == "the quick brown fox jumped over the lazy ")) {
test_fail
}
# Removal of first and subsequent word
-if (!(%subst(test_string3, 'the', '') == " quick brown fox jumped over lazy dog")) {
+if (!(%str.subst(test_string3, 'the', '') == " quick brown fox jumped over lazy dog")) {
test_fail
}
# Removal of middle word
-if (!(%subst(test_string3, 'jumped', '') == "the quick brown fox over the lazy dog")) {
+if (!(%str.subst(test_string3, 'jumped', '') == "the quick brown fox over the lazy dog")) {
test_fail
}
# Replacement of last word only
-if (!(%subst(test_string3, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) {
+if (!(%str.subst(test_string3, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) {
test_fail
}
# Replacement of first and subsequent word
-if (!(%subst(test_string3, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) {
+if (!(%str.subst(test_string3, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) {
test_fail
}
# Replacement of middle word
-if (!(%subst(test_string3, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) {
+if (!(%str.subst(test_string3, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) {
test_fail
}
if ("${feature.regex-pcre2}" == 'yes') {
# Basic substitutions
-if (!(%subst(test_string1, '/a/', 'b') == 'baa')) {
+if (!(%str.subst(test_string1, '/a/', 'b') == 'baa')) {
test_fail
}
# Global substitution
-if (!(%subst(test_string1, '/a/g', 'b') == 'bbb')) {
+if (!(%str.subst(test_string1, '/a/g', 'b') == 'bbb')) {
test_fail
}
# No match
-if (!(%subst(test_string1, '/z/', 'b') == 'aaa')) {
+if (!(%str.subst(test_string1, '/z/', 'b') == 'aaa')) {
test_fail
}
# Basic substitutions - Dynamic
-if (!(%subst(test_string1, "/a%{empty_string}/", 'b') == 'baa')) {
+if (!(%str.subst(test_string1, "/a%{empty_string}/", 'b') == 'baa')) {
test_fail
}
# Global substitution - Dynamic
-if (!(%subst(test_string1, "/a%{empty_string}/g", 'b') == 'bbb')) {
+if (!(%str.subst(test_string1, "/a%{empty_string}/g", 'b') == 'bbb')) {
test_fail
}
}
# Strip out just the first newline
-if (!(%subst(test_string2, '/^./s', '') == "\n\n")) {
+if (!(%str.subst(test_string2, '/^./s', '') == "\n\n")) {
test_fail
}
-if (!(%subst(test_string2, '/\n/', '') == "\n\n")) {
+if (!(%str.subst(test_string2, '/\n/', '') == "\n\n")) {
test_fail
}
# Strip out all the newlines
-if (!(%subst(test_string2, '/\n/g', '') == '')) {
+if (!(%str.subst(test_string2, '/\n/g', '') == '')) {
test_fail
}
# Line ending switch
-if (!(%subst(test_string2, '/\n/g', "\r") == "\r\r\r")) {
+if (!(%str.subst(test_string2, '/\n/g', "\r") == "\r\r\r")) {
test_fail
}
# Capture groups
-if (!(%subst(test_string3, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) {
+if (!(%str.subst(test_string3, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) {
test_fail
}
-if (!(%subst(test_string3, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) {
+if (!(%str.subst(test_string3, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) {
test_fail
}