Restructure code
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 19 Jun 2019 23:36:09 +0000 (16:36 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 19 Jun 2019 23:36:09 +0000 (16:36 -0700)
src/hb-ot-tag.cc

index 61b609d..e3d1aa7 100644 (file)
@@ -305,28 +305,24 @@ parse_private_use_subtag (const char     *private_use_subtag,
                          const char     *prefix,
                          unsigned char (*normalize) (unsigned char))
 {
-  if (private_use_subtag && count && tags && *count)
-  {
-    const char *s = strstr (private_use_subtag, prefix);
-    if (s)
-    {
-      char tag[4];
-      int i;
-      s += strlen (prefix);
-      for (i = 0; i < 4 && ISALNUM (s[i]); i++)
-       tag[i] = normalize (s[i]);
-      if (i)
-      {
-       for (; i < 4; i++)
-         tag[i] = ' ';
-       tags[0] = HB_TAG (tag[0], tag[1], tag[2], tag[3]);
-       if ((tags[0] & 0xDFDFDFDF) == HB_OT_TAG_DEFAULT_SCRIPT)
-         tags[0] ^= ~0xDFDFDFDF;
-       *count = 1;
-       return false;
-      }
-    }
-  }
+  if (!(private_use_subtag && count && tags && *count)) return false;
+
+  const char *s = strstr (private_use_subtag, prefix);
+  if (!s) return false;
+
+  char tag[4];
+  int i;
+  s += strlen (prefix);
+  for (i = 0; i < 4 && ISALNUM (s[i]); i++)
+    tag[i] = normalize (s[i]);
+  if (!i) return false;
+
+  for (; i < 4; i++)
+    tag[i] = ' ';
+  tags[0] = HB_TAG (tag[0], tag[1], tag[2], tag[3]);
+  if ((tags[0] & 0xDFDFDFDF) == HB_OT_TAG_DEFAULT_SCRIPT)
+    tags[0] ^= ~0xDFDFDFDF;
+  *count = 1;
   return true;
 }
 
@@ -394,8 +390,8 @@ hb_ot_tags_from_script_and_language (hb_script_t   script,
        limit = s;
     }
 
-    needs_script = parse_private_use_subtag (private_use_subtag, script_count, script_tags, "-hbsc", TOLOWER);
-    needs_language = parse_private_use_subtag (private_use_subtag, language_count, language_tags, "-hbot", TOUPPER);
+    needs_script = !parse_private_use_subtag (private_use_subtag, script_count, script_tags, "-hbsc", TOLOWER);
+    needs_language = !parse_private_use_subtag (private_use_subtag, language_count, language_tags, "-hbot", TOUPPER);
 
     if (needs_language && language_count && language_tags && *language_count)
       hb_ot_tags_from_language (lang_str, limit, language_count, language_tags);