diff options
Diffstat (limited to 'fontconfig/src/fcstr.c')
-rw-r--r-- | fontconfig/src/fcstr.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/fontconfig/src/fcstr.c b/fontconfig/src/fcstr.c index b712e5daf..a6f0ba766 100644 --- a/fontconfig/src/fcstr.c +++ b/fontconfig/src/fcstr.c @@ -26,6 +26,9 @@ #include <stdlib.h> #include <ctype.h> #include <string.h> +#ifdef HAVE_REGEX_H +#include <regex.h> +#endif #ifdef _WIN32 #include <windows.h> #endif @@ -269,6 +272,55 @@ FcStrCmp (const FcChar8 *s1, const FcChar8 *s2) return (int) c1 - (int) c2; } +#ifdef USE_REGEX +static FcBool +_FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex, int cflags, int eflags) +{ + int ret = -1; + regex_t reg; + + if ((ret = regcomp (®, (const char *)regex, cflags)) != 0) + { + if (FcDebug () & FC_DBG_MATCHV) + { + char buf[512]; + + regerror (ret, ®, buf, 512); + printf("Regexp compile error: %s\n", buf); + } + return FcFalse; + } + ret = regexec (®, (const char *)s, 0, NULL, eflags); + if (ret != 0) + { + if (FcDebug () & FC_DBG_MATCHV) + { + char buf[512]; + + regerror (ret, ®, buf, 512); + printf("Regexp exec error: %s\n", buf); + } + } + regfree (®); + + return ret == 0 ? FcTrue : FcFalse; +} +#else +# define _FcStrRegexCmp(_s_, _regex_) (FcFalse) +#endif + +FcBool +FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex) +{ + return _FcStrRegexCmp (s, regex, REG_EXTENDED | REG_NOSUB, 0); +} + +FcBool +FcStrRegexCmpIgnoreCase (const FcChar8 *s, const FcChar8 *regex) +{ + return _FcStrRegexCmp (s, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE, 0); +} + /* * Return a hash value for a string */ |