@@ -16,17 +16,20 @@ pub fn normalize_unicode(word: &str, nf: &str) -> Result<String, String> {
16
16
}
17
17
}
18
18
19
- use icu:: collator:: options:: CollatorOptions ;
20
- use icu:: collator:: * ;
21
- // use icu::locid::Locale;
19
+ // use core::cmp::Ordering;
20
+ use icu:: collator:: { options:: * , * } ;
21
+ // use icu::locale::locale;
22
+ use icu:: locale:: Locale ;
22
23
/// Sort a Vector of words alphabetically, taking into account the locale of the words
23
24
/// `.sorted()` words -> ["Zambia", "abbey", "eager", "enlever", "ezra", "zoo", "énigme"]
24
25
/// sort_carefully words -> ["abbey", "eager", "énigme", "enlever", "ezra", "Zambia", "zoo"]
25
- pub fn sort_carefully ( list : Vec < String > , locale : Locale ) -> Vec < String > {
26
- // https://github.com/unicode-org/icu4x/tree/main/components/collator#examples
27
- let mut options = CollatorOptions :: new ( ) ;
28
- options. strength = Some ( Strength :: Secondary ) ;
29
- let collator: Collator = Collator :: try_new ( & locale. into ( ) , options) . unwrap ( ) ;
26
+ pub fn sort_carefully ( list : Vec < String > , loc : Locale ) -> Vec < String > {
27
+ // Examples: https://github.com/unicode-org/icu4x/tree/main/components/collator#examples
28
+ // Reference: https://docs.rs/icu/latest/icu/collator/index.html
29
+ // https://docs.rs/icu/latest/icu/locale/struct.Locale.html
30
+ let mut options = CollatorOptions :: default ( ) ;
31
+ options. strength = Some ( Strength :: Secondary ) ; // Note this is not the locally defined passphrase Strength!
32
+ let collator = Collator :: try_new ( loc. into ( ) , options) . unwrap ( ) ;
30
33
31
34
let mut newly_sorted_list = list;
32
35
newly_sorted_list. sort_by ( |a, b| collator. compare ( a, b) ) ;
@@ -35,11 +38,12 @@ pub fn sort_carefully(list: Vec<String>, locale: Locale) -> Vec<String> {
35
38
36
39
/// Sort by word length, with longest words first. For words of equal length, sorts
37
40
/// word alphabetically, respecting inputted locale.
38
- pub fn sort_by_length ( list : Vec < String > , locale : Locale ) -> Vec < String > {
41
+ pub fn sort_by_length ( list : Vec < String > , loc : Locale ) -> Vec < String > {
39
42
// Set up the collator again
40
- let mut options = CollatorOptions :: new ( ) ;
43
+ let mut options = CollatorOptions :: default ( ) ;
41
44
options. strength = Some ( Strength :: Secondary ) ;
42
- let collator: Collator = Collator :: try_new ( & locale. into ( ) , options) . unwrap ( ) ;
45
+ // let collator = Collator::try_new(locale, options).unwrap();
46
+ let collator = Collator :: try_new ( loc. into ( ) , options) . unwrap ( ) ;
43
47
44
48
let mut list = list;
45
49
// Order by count_characters(w) descending, then within that,
0 commit comments