/*
- * $XFree86: xc/lib/fontconfig/src/fcstr.c,v 1.7 2002/07/13 05:43:25 keithp Exp $
+ * $RCSId: xc/lib/fontconfig/src/fcstr.c,v 1.10 2002/08/31 22:17:32 keithp Exp $
*
- * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2000 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
{
c1 = *s1++;
c2 = *s2++;
- if (!c1 || !c2)
- break;
- c1 = FcToLower (c1);
- c2 = FcToLower (c2);
- if (c1 != c2)
+ if (!c1 || (c1 != c2 && (c1 = FcToLower(c1)) != (c2 = FcToLower(c2))))
break;
}
return (int) c1 - (int) c2;
do
c2 = *s2++;
while (c2 == ' ');
- if (!c1 || !c2)
- break;
- c1 = FcToLower (c1);
- c2 = FcToLower (c2);
- if (c1 != c2)
+ if (!c1 || (c1 != c2 && (c1 = FcToLower(c1)) != (c2 = FcToLower(c2))))
break;
}
return (int) c1 - (int) c2;
{
c1 = *s1++;
c2 = *s2++;
- if (!c1 || !c2)
- break;
- if (c1 != c2)
+ if (!c1 || c1 != c2)
break;
}
return (int) c1 - (int) c2;
}
+/*
+ * Is the head of s1 equal to s2?
+ */
+
+static FcBool
+FcStrIsAtIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2)
+{
+ FcChar8 c1, c2;
+
+ for (;;)
+ {
+ do
+ c1 = *s1++;
+ while (c1 == ' ');
+ do
+ c2 = *s2++;
+ while (c2 == ' ');
+ if (!c1 || (c1 != c2 && (c1 = FcToLower(c1)) != (c2 = FcToLower(c2))))
+ break;
+ }
+ return c1 == c2 || !c2;
+}
+
+/*
+ * Does s1 contain an instance of s2 (ignoring blanks and case)?
+ */
+
+const FcChar8 *
+FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2)
+{
+ while (*s1)
+ {
+ if (FcStrIsAtIgnoreBlanksAndCase (s1, s2))
+ return s1;
+ s1++;
+ }
+ return 0;
+}
+
+/*
+ * Is the head of s1 equal to s2?
+ */
+
+static FcBool
+FcStrIsAtIgnoreCase (const FcChar8 *s1, const FcChar8 *s2)
+{
+ FcChar8 c1, c2;
+
+ for (;;)
+ {
+ c1 = *s1++;
+ c2 = *s2++;
+ if (!c1 || (c1 != c2 && (c1 = FcToLower(c1)) != (c2 = FcToLower(c2))))
+ break;
+ }
+ return c1 == c2 || !c2;
+}
+
+/*
+ * Does s1 contain an instance of s2 (ignoring blanks and case)?
+ */
+
+const FcChar8 *
+FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2)
+{
+ while (*s1)
+ {
+ if (FcStrIsAtIgnoreCase (s1, s2))
+ return s1;
+ s1++;
+ }
+ return 0;
+}
+
int
FcUtf8ToUcs4 (const FcChar8 *src_orig,
FcChar32 *dst,
if ((b & 0xfc00) != 0xdc00)
return 0;
result = ((((FcChar32) a & 0x3ff) << 10) |
- ((FcChar32) b & 0x3ff)) | 0x10000;
+ ((FcChar32) b & 0x3ff)) + 0x10000;
}
else
result = a;
{
if (buf->allocated)
{
+ FcMemFree (FC_MEM_STRBUF, buf->size);
free (buf->buf);
FcStrBufInit (buf, 0, 0);
}
ret = malloc (buf->len + 1);
if (ret)
{
+ FcMemAlloc (FC_MEM_STRING, buf->len + 1);
memcpy (ret, buf->buf, buf->len);
ret[buf->len] = '\0';
}
buf->failed = FcTrue;
return FcFalse;
}
+ if (buf->size)
+ FcMemFree (FC_MEM_STRBUF, buf->size);
+ FcMemAlloc (FC_MEM_STRBUF, size);
buf->size = size;
buf->buf = new;
}
return FcTrue;
}
+FcBool
+FcStrUsesHome (const FcChar8 *s)
+{
+ return *s == '~';
+}
+
FcChar8 *
FcStrCopyFilename (const FcChar8 *s)
{
if (*s == '~')
{
- FcChar8 *home = (FcChar8 *) getenv ("HOME");
- int size = strlen ((char *) home) + strlen ((char *) s);
+ FcChar8 *home = FcConfigHome ();
+ int size;
if (!home)
return 0;
+ size = strlen ((char *) home) + strlen ((char *) s);
new = (FcChar8 *) malloc (size);
if (!new)
return 0;
return new;
}
+FcChar8 *
+FcStrLastSlash (const FcChar8 *path)
+{
+ FcChar8 *slash;
+
+ slash = (FcChar8 *) strrchr ((const char *) path, '/');
+#ifdef _WIN32
+ {
+ FcChar8 *backslash;
+
+ backslash = (FcChar8 *) strrchr ((const char *) path, '\\');
+ if (!slash || (backslash && backslash > slash))
+ slash = backslash;
+ }
+#endif
+
+ return slash;
+}
+
FcChar8 *
FcStrDirname (const FcChar8 *file)
{
FcChar8 *slash;
FcChar8 *dir;
- slash = (FcChar8 *) strrchr ((char *) file, '/');
+ slash = FcStrLastSlash (file);
if (!slash)
return FcStrCopy ((FcChar8 *) ".");
dir = malloc ((slash - file) + 1);
{
FcChar8 *slash;
- slash = (FcChar8 *) strrchr ((char *) file, '/');
+ slash = FcStrLastSlash (file);
if (!slash)
return FcStrCopy (file);
return FcStrCopy (slash + 1);