more include simplifications
[apps/madmutt.git] / lib-lib / rx.c
index 6413f69..521376f 100644 (file)
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/rx.h>
+#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;
+}