From 47bf083d0a1e8092c8bcad7ad1f405f7ecc6b0c2 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 22 Oct 2026 02:39:21 +0000 Subject: [PATCH] Integration: #2116 move name_sort_key and its test into the existing tests module --- crates/ui-egui/src/i18n.rs | 47 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 935c0cc80..551f6f237 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -227,6 +227,27 @@ pub fn set_current(ctx: &egui::Context, language: Language) { ctx.data_mut(|d| d.insert_temp(lang_key(), language)); } +/// `name` lowercased with the Latin accents that occur in language names folded away, so a +/// byte-wise sort reads alphabetically. Other scripts are left as they are. +fn name_sort_key(name: &str) -> String { + name.chars() + .flat_map(char::to_lowercase) + .map(|c| match c { + 'à'..='å' | 'ā' | 'ă' | 'ą' => 'a', + 'ç' | 'ć' | 'č' => 'c', + 'è'..='ë' | 'ē' | 'ě' | 'ę' | 'ế' | 'ệ' => 'e', + 'ì'..='ï' | 'ī' => 'i', + 'ñ' | 'ń' | 'ň' => 'n', + 'ò'..='ö' | 'ø' | 'ő' => 'o', + 'ś' | 'š' => 's', + 'ù'..='ü' | 'ū' | 'ů' | 'ű' => 'u', + 'ý' | 'ÿ' => 'y', + 'ź' | 'ż' | 'ž' => 'z', + c => c, + }) + .collect() +} + #[cfg(test)] mod tests { use super::*; @@ -494,32 +515,6 @@ mod tests { assert_eq!(Language::parse(l.code()), Some(l)); } } -} - -/// `name` lowercased with the Latin accents that occur in language names folded away, so a -/// byte-wise sort reads alphabetically. Other scripts are left as they are. -fn name_sort_key(name: &str) -> String { - name.chars() - .flat_map(char::to_lowercase) - .map(|c| match c { - 'à'..='å' | 'ā' | 'ă' | 'ą' => 'a', - 'ç' | 'ć' | 'č' => 'c', - 'è'..='ë' | 'ē' | 'ě' | 'ę' | 'ế' | 'ệ' => 'e', - 'ì'..='ï' | 'ī' => 'i', - 'ñ' | 'ń' | 'ň' => 'n', - 'ò'..='ö' | 'ø' | 'ő' => 'o', - 'ś' | 'š' => 's', - 'ù'..='ü' | 'ū' | 'ů' | 'ű' => 'u', - 'ý' | 'ÿ' => 'y', - 'ź' | 'ż' | 'ž' => 'z', - c => c, - }) - .collect() -} - -#[cfg(test)] -mod picker_order_tests { - use super::*; #[test] fn picker_lists_english_first_then_names_alphabetically() {