]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.c
ccanlint: enhance and streamline "output" testing lines.
[ccan] / ccan / tal / str / str.c
index 15aa0c046883633d956eb8abbf50c48e9e362c5e..059817b6aa7e928b8e9ceeef372e2510b6ebd3f3 100644 (file)
@@ -11,7 +11,6 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <ccan/str/str.h>
-#include <ccan/tal/tal.h>
 #include <ccan/take/take.h>
 
 char *tal_strdup(const tal_t *ctx, const char *p)
@@ -237,9 +236,31 @@ fail:
        goto out;
 }
 
+static size_t count_open_braces(const char *string)
+{
+#if 1
+       size_t num = 0, esc = 0;
+
+       while (*string) {
+               if (*string == '\\')
+                       esc++;
+               else {
+                       /* An odd number of \ means it's escaped. */
+                       if (*string == '(' && (esc & 1) == 0)
+                               num++;
+                       esc = 0;
+               }
+               string++;
+       }
+       return num;
+#else
+       return strcount(string, "(");
+#endif
+}
+
 bool tal_strreg(const tal_t *ctx, const char *string, const char *regex, ...)
 {
-       size_t nmatch = 1 + strcount(regex, "(");
+       size_t nmatch = 1 + count_open_braces(regex);
        regmatch_t matches[nmatch];
        regex_t r;
        bool ret = false;