Browse Source

LibUnicode: Sort special casing array by locale specificity

This is to simply the Default Case Conversion implementation. Otherwise,
the implementation would need to determine which special casing rule to
apply, instead of just picking the first match.
Timothy Flynn 3 years ago
parent
commit
077a693de6
1 changed files with 13 additions and 1 deletions
  1. 13 1
      Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp

+ 13 - 1
Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp

@@ -181,7 +181,6 @@ static void parse_special_casing(Core::File& file, UnicodeData& unicode_data)
         VERIFY(segments.size() == 5 || segments.size() == 6);
         VERIFY(segments.size() == 5 || segments.size() == 6);
 
 
         SpecialCasing casing {};
         SpecialCasing casing {};
-        casing.index = static_cast<u32>(unicode_data.special_casing.size());
         casing.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
         casing.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
         casing.lowercase_mapping = parse_code_point_list(segments[1]);
         casing.lowercase_mapping = parse_code_point_list(segments[1]);
         casing.titlecase_mapping = parse_code_point_list(segments[2]);
         casing.titlecase_mapping = parse_code_point_list(segments[2]);
@@ -214,6 +213,19 @@ static void parse_special_casing(Core::File& file, UnicodeData& unicode_data)
 
 
         unicode_data.special_casing.append(move(casing));
         unicode_data.special_casing.append(move(casing));
     }
     }
+
+    quick_sort(unicode_data.special_casing, [](auto const& lhs, auto const& rhs) {
+        if (lhs.code_point != rhs.code_point)
+            return lhs.code_point < rhs.code_point;
+        if (lhs.locale.is_empty() && !rhs.locale.is_empty())
+            return false;
+        if (!lhs.locale.is_empty() && rhs.locale.is_empty())
+            return true;
+        return lhs.locale < rhs.locale;
+    });
+
+    for (u32 i = 0; i < unicode_data.special_casing.size(); ++i)
+        unicode_data.special_casing[i].index = i;
 }
 }
 
 
 static void parse_prop_list(Core::File& file, PropList& prop_list, bool multi_value_property = false)
 static void parse_prop_list(Core::File& file, PropList& prop_list, bool multi_value_property = false)