X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fstr%2Fstr.c;h=059817b6aa7e928b8e9ceeef372e2510b6ebd3f3;hb=b87f63cb8228c8fcbf760defdcf9e4c332da7667;hp=237652f738fc2217b5f0e9eeb117f299b2a484b0;hpb=d61a0d6c2c9d2b385075338665d64ae1d1bbe3dc;p=ccan diff --git a/ccan/tal/str/str.c b/ccan/tal/str/str.c index 237652f7..059817b6 100644 --- a/ccan/tal/str/str.c +++ b/ccan/tal/str/str.c @@ -236,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;