From d4d1e8bc604c98d647d70f9188744b95deba8723 Mon Sep 17 00:00:00 2001 From: James Su Date: Wed, 28 May 2003 01:34:38 +0000 Subject: [PATCH] Fix "contains" op for strings and langsets. --- fontconfig/fontconfig.h | 6 +++ src/fccfg.c | 16 ++++--- src/fcstr.c | 103 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 6 deletions(-) diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 1f0bd9c..a4954f6 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -737,6 +737,12 @@ FcStrCmpIgnoreCase (const FcChar8 *s1, const FcChar8 *s2); int FcStrCmp (const FcChar8 *s1, const FcChar8 *s2); +const FcChar8 * +FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2); + +const FcChar8 * +FcStrStr (const FcChar8 *s1, const FcChar8 *s2); + int FcUtf8ToUcs4 (const FcChar8 *src_orig, FcChar32 *dst, diff --git a/src/fccfg.c b/src/fccfg.c index 3684d79..cbb6ecb 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -565,13 +565,17 @@ FcConfigCompareValue (const FcValue m_o, case FcTypeString: switch (op) { case FcOpEqual: - case FcOpContains: ret = FcStrCmpIgnoreCase (m.u.s, v.u.s) == 0; break; + case FcOpContains: + ret = FcStrStrIgnoreCase (m.u.s, v.u.s) != 0; + break; case FcOpNotEqual: - case FcOpNotContains: ret = FcStrCmpIgnoreCase (m.u.s, v.u.s) != 0; break; + case FcOpNotContains: + ret = FcStrStrIgnoreCase (m.u.s, v.u.s) == 0; + break; default: break; } @@ -613,16 +617,16 @@ FcConfigCompareValue (const FcValue m_o, case FcTypeLangSet: switch (op) { case FcOpContains: - ret = FcLangSetContains (v.u.l, m.u.l); + ret = FcLangSetContains (m.u.l, v.u.l); break; case FcOpNotContains: - ret = FcLangSetContains (v.u.l, m.u.l); + ret = FcLangSetContains (m.u.l, v.u.l); break; case FcOpEqual: - ret = FcLangSetEqual (v.u.l, m.u.l); + ret = FcLangSetEqual (m.u.l, v.u.l); break; case FcOpNotEqual: - ret = !FcLangSetEqual (v.u.l, m.u.l); + ret = !FcLangSetEqual (m.u.l, v.u.l); break; default: break; diff --git a/src/fcstr.c b/src/fcstr.c index ecbfd29..e67563d 100644 --- a/src/fcstr.c +++ b/src/fcstr.c @@ -188,6 +188,109 @@ FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) return 0; } +const FcChar8 * +FcStrStrIgnoreCase (const FcChar8 *s1, const FcChar8 *s2) +{ + FcChar8 c1, c2; + const FcChar8 * p = s1; + const FcChar8 * b = s2; + + if (!s1 || !s2) + return 0; + + if (s1 == s2) + return s1; + +again: + c2 = *s2++; + c2 = FcToLower (c2); + + if (!c2) + return 0; + + for (;;) + { + p = s1; + c1 = *s1++; + if (!c1 || (c1 = FcToLower (c1)) == c2) + break; + } + + if (c1 != c2) + return 0; + + for (;;) + { + c1 = *s1; + c2 = *s2; + if (c1 && c2 && (c1 = FcToLower (c1)) != (c2 = FcToLower (c2))) + { + s1 = p + 1; + s2 = b; + goto again; + } + if (!c2) + return p; + if (!c1) + return 0; + ++ s1; + ++ s2; + } + + return 0; +} + +const FcChar8 * +FcStrStr (const FcChar8 *s1, const FcChar8 *s2) +{ + FcChar8 c1, c2; + const FcChar8 * p = s1; + const FcChar8 * b = s2; + + if (!s1 || !s2) + return 0; + + if (s1 == s2) + return s1; + +again: + c2 = *s2++; + + if (!c2) + return 0; + + for (;;) + { + p = s1; + c1 = *s1++; + if (!c1 || c1 == c2) + break; + } + + if (c1 != c2) + return 0; + + for (;;) + { + c1 = *s1; + c2 = *s2; + if (c1 && c2 && c1 != c2) + { + s1 = p + 1; + s2 = b; + goto again; + } + if (!c2) + return p; + if (!c1) + return 0; + ++ s1; + ++ s2; + } + + return 0; +} + int FcUtf8ToUcs4 (const FcChar8 *src_orig, FcChar32 *dst, -- 2.39.5