]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Implement new semantics for Contains and LISTING:
[fontconfig.git] / src / fclang.c
index 521aa91526dba666d479d2425dc1a58e0fabbe5d..582b92b54f9054789eb231f5eea5d09ac013b4f9 100644 (file)
@@ -144,29 +144,33 @@ FcLangCompare (const FcChar8 *s1, const FcChar8 *s2)
 }
 
 /*
- * Return FcTrue when s1 contains s2
+ * Return FcTrue when super contains sub
  *
- * s1 contains s2 if s1 equals s2 or if s1 is a
- * language with a country and s2 is just a language
+ * super contains sub if super and sub have the same
+ * language and either the same country or one
+ * is missing the country
  */
 
 static FcBool
-FcLangContains (const FcChar8 *s1, const FcChar8 *s2)
+FcLangContains (const FcChar8 *super, const FcChar8 *sub)
 {
     FcChar8        c1, c2;
 
     for (;;)
     {
-       c1 = *s1++;
-       c2 = *s2++;
+       c1 = *super++;
+       c2 = *sub++;
        
        c1 = FcToLower (c1);
        c2 = FcToLower (c2);
        if (c1 != c2)
        {
-           /* see if s1 has a country while s2 is mising one */
+           /* see if super has a country while sub is mising one */
            if (c1 == '-' && c2 == '\0')
                return FcTrue;
+           /* see if sub has a country while super is mising one */
+           if (c1 == '\0' && c2 == '-')
+               return FcTrue;
            return FcFalse;
        }
        else if (!c1)
@@ -259,9 +263,10 @@ bail0:
 static int
 FcLangSetIndex (const FcChar8 *lang)
 {
-    int            low, high, mid;
-    int            cmp;
+    int            low, high, mid = 0;
+    int            cmp = 0;
     FcChar8 firstChar = FcToLower(lang[0]); 
+    FcChar8 secondChar = firstChar ? FcToLower(lang[1]) : '\0';
     
     if (firstChar < 'a')
     {
@@ -290,22 +295,14 @@ FcLangSetIndex (const FcChar8 *lang)
        else
        {   /* fast path for resolving 2-letter languages (by far the most common) after
             * finding the first char (probably already true because of the hash table) */
-           FcChar8 secondChar = FcToLower(lang[1]);
-           if (fcLangCharSets[mid].lang[1] > secondChar) // check second chars
+           cmp = fcLangCharSets[mid].lang[1] - secondChar;
+           if (cmp == 0 && 
+               (fcLangCharSets[mid].lang[2] != '\0' || 
+                lang[2] != '\0'))
            {
-               high = mid - 1;
-               continue;
+               cmp = FcStrCmpIgnoreCase(fcLangCharSets[mid].lang+2, 
+                                        lang+2);
            }
-           else if (fcLangCharSets[mid].lang[1] < secondChar)
-           {
-               low = mid + 1;
-               continue;
-           }
-           else if (fcLangCharSets[mid].lang[2] == '\0' && lang[2] == '\0')
-               return mid;
-
-           else /* identical through the first two charcters, but at least one string didn't end there */
-               cmp = FcStrCmpIgnoreCase(fcLangCharSets[mid].lang+2, lang+2);
        }
        if (cmp == 0)
            return mid;
@@ -582,7 +579,6 @@ static FcBool
 FcLangSetContainsLang (const FcLangSet *ls, const FcChar8 *lang)
 {
     int                    id;
-    FcLangResult    r;
     int                    i;
 
     id = FcLangSetIndex (lang);
@@ -613,7 +609,6 @@ FcLangSetContainsLang (const FcLangSet *ls, const FcChar8 *lang)
     {
        FcStrList       *list = FcStrListCreate (ls->extra);
        FcChar8         *extra;
-       FcLangResult    r;
        
        if (list)
        {