X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fregex.c;h=24846981fbf16b945c5d7e90a9e4b62c26f2f66e;hb=328035fb7e98630862ae8b43088631f62b807c77;hp=f419e4bbf4e7d1a3cf739b17d12efeb74b1d6c85;hpb=7a38d8ac56b61e9582af8eb5d0449fc89a795c71;p=i3%2Fi3 diff --git a/src/regex.c b/src/regex.c index f419e4bb..24846981 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1,12 +1,14 @@ +#undef I3__FILE__ +#define I3__FILE__ "regex.c" /* * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * + * regex.c: Interface to libPCRE (perl compatible regular expressions). * */ - #include "all.h" /* @@ -23,11 +25,14 @@ struct regex *regex_new(const char *pattern) { const char *error; int errorcode, offset; - struct regex *re = scalloc(sizeof(struct regex)); + struct regex *re = scalloc(1, sizeof(struct regex)); re->pattern = sstrdup(pattern); + int options = PCRE_UTF8; +#ifdef PCRE_HAS_UCP /* We use PCRE_UCP so that \B, \b, \D, \d, \S, \s, \W, \w and some POSIX * character classes play nicely with Unicode */ - int options = PCRE_UCP | PCRE_UTF8; + options |= PCRE_UCP; +#endif while (!(re->regex = pcre_compile2(pattern, options, &errorcode, &error, &offset, NULL))) { /* If the error is that PCRE was not compiled with UTF-8 support we * disable it and try again */ @@ -59,12 +64,13 @@ void regex_free(struct regex *regex) { FREE(regex->pattern); FREE(regex->regex); FREE(regex->extra); + FREE(regex); } /* * Checks if the given regular expression matches the given input and returns * true if it does. In either case, it logs the outcome using LOG(), so it will - * be visible without any debug loglevel. + * be visible without debug logging. * */ bool regex_matches(struct regex *regex, const char *input) {