summaryrefslogtreecommitdiff
path: root/src/fcstr.c
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2012-04-09 12:51:12 +0900
committerAkira TAGOH <akira@tagoh.org>2012-04-11 16:36:36 +0900
commit9231d79ad180f992f9bbef4f3127576870a75075 (patch)
treea3d6899c28418360ca01b84c499bbd3f26f08bfb /src/fcstr.c
parent2589207cfd4c7e948a4b50d7c07c13a3a52fe0aa (diff)
downloadfontconfig-9231d79ad180f992f9bbef4f3127576870a75075.tar.gz
Bug 28491 - Allow matching on FC_FILE
Allow :file=/path/to/font/file on matching
Diffstat (limited to 'src/fcstr.c')
-rw-r--r--src/fcstr.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/fcstr.c b/src/fcstr.c
index b712e5d..9484d46 100644
--- a/src/fcstr.c
+++ b/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,53 @@ FcStrCmp (const FcChar8 *s1, const FcChar8 *s2)
return (int) c1 - (int) c2;
}
+static FcBool
+_FcStrRegexCmp (const FcChar8 *s, const FcChar8 *regex, int cflags, int eflags)
+{
+ int ret = -1;
+#if defined (HAVE_REGCOMP) && defined (HAVE_REGERROR) && defined (HAVE_REGEXEC) && defined (HAVE_REGFREE)
+ regex_t reg;
+
+ if ((ret = regcomp (&reg, (const char *)regex, cflags)) != 0)
+ {
+ if (FcDebug () & FC_DBG_MATCHV)
+ {
+ char buf[512];
+
+ regerror (ret, &reg, buf, 512);
+ printf("Regexp compile error: %s\n", buf);
+ }
+ return FcFalse;
+ }
+ ret = regexec (&reg, (const char *)s, 0, NULL, eflags);
+ if (ret != 0)
+ {
+ if (FcDebug () & FC_DBG_MATCHV)
+ {
+ char buf[512];
+
+ regerror (ret, &reg, buf, 512);
+ printf("Regexp exec error: %s\n", buf);
+ }
+ }
+ regfree (&reg);
+#endif
+
+ return ret == 0 ? FcTrue : FcFalse;
+}
+
+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
*/