X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Frx.c;h=521376fdb20e5e11b788075179c00ff25848ab8b;hp=6413f69c88fa81c9e4f962be07459986623a39ab;hb=1ee89902de184a640c171ae3285bff6882a791bd;hpb=03fe827a7d4a7ad79ac235654414aa339a9a2c9a diff --git a/lib-lib/rx.c b/lib-lib/rx.c index 6413f69..521376f 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -22,13 +22,7 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include +#include "lib-lib.h" rx_t *rx_compile(const char *s, int flags) { @@ -81,3 +75,27 @@ int rx_lookup (list2_t *l, const char *pat) return -1; } + +int rx_sanitize_string(char *dst, ssize_t n, const char *src) +{ + while (*src) { + if (n <= 1) + break; + + /* these characters must be escaped in regular expressions */ + if (strchr("^.[$()|*+?{\\", *src)) { + if (n <= 2) + break; + + *dst++ = '\\'; + n--; + } + + *dst++ = *src++; + n--; + } + + *dst = '\0'; + + return *src ? -1 : 0; +}