Reduce again the number of match calls (#7815)

- Reduce the number of match calls (see commit messages)
- A few miscellaneous improvements
This commit is contained in:
Hofer-Julian
2023-01-24 12:23:42 +01:00
committed by GitHub
parent 0bb2e47c98
commit 41306aa7e0
49 changed files with 467 additions and 634 deletions

View File

@ -9,20 +9,15 @@ pub fn get_system_locale() -> Locale {
// however Locale::from_name() wants only de so we split and parse it out.
let locale_string = locale_string.replace('_', "-"); // en_AU -> en-AU
match Locale::from_name(&locale_string) {
Ok(loc) => loc,
_ => {
let all = num_format::Locale::available_names();
let locale_prefix = &locale_string.split('-').collect::<Vec<&str>>();
if all.contains(&locale_prefix[0]) {
// eprintln!("Found alternate: {}", &locale_prefix[0]);
Locale::from_name(locale_prefix[0]).unwrap_or(Locale::en)
} else {
// eprintln!("Unable to find matching locale. Defaulting to en-US");
Locale::en
}
Locale::from_name(&locale_string).unwrap_or_else(|_| {
let all = num_format::Locale::available_names();
let locale_prefix = &locale_string.split('-').collect::<Vec<&str>>();
if all.contains(&locale_prefix[0]) {
Locale::from_name(locale_prefix[0]).unwrap_or(Locale::en)
} else {
Locale::en
}
}
})
}
#[cfg(debug_assertions)]

File diff suppressed because one or more lines are too long