switch statement cleanup (#148382)

This PR is step 12 in the journey to solve issue #136139 and make the
entire Flutter repo more readable.

Most of it involves implementing switch expressions, and there's also a
few other random things that I wanted to clean up a bit.
This commit is contained in:
Nate
2024-05-16 18:16:06 -06:00
committed by GitHub
parent c4ad1dc1e9
commit fa9992eff6
39 changed files with 301 additions and 529 deletions

View File

@@ -62,29 +62,12 @@ class LocaleInfo implements Comparable<LocaleInfo> {
/// across various countries. For example, we know Taiwan uses traditional (Hant)
/// script, so it is safe to apply (Hant) to Taiwanese languages.
if (deriveScriptCode && scriptCode == null) {
switch (languageCode) {
case 'zh': {
if (countryCode == null) {
scriptCode = 'Hans';
}
switch (countryCode) {
case 'CN':
case 'SG':
scriptCode = 'Hans';
case 'TW':
case 'HK':
case 'MO':
scriptCode = 'Hant';
}
break;
}
case 'sr': {
if (countryCode == null) {
scriptCode = 'Cyrl';
}
break;
}
}
scriptCode = switch ((languageCode, countryCode)) {
('zh', 'CN' || 'SG' || null) => 'Hans',
('zh', 'TW' || 'HK' || 'MO') => 'Hant',
('sr', null) => 'Cyrl',
_ => null,
};
// Increment length if we were able to assume a scriptCode.
if (scriptCode != null) {
length += 1;