Skip to content

Commit 145a3e1

Browse files
committed
successfully upgrades icu crate dependency to v2
1 parent 6605f80 commit 145a3e1

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use icu::collator::options;
2-
3-
use icu::collator::options::CollatorOptions;
4-
// use icu::locid::Locale;
5-
use icu::locale::locale;
1+
// use core::cmp::Ordering;
2+
use icu::locale::Locale;
3+
// use icu::locale::locale;
64
use rand::prelude::SliceRandom;
75
use rand::rng;
86
pub mod cards;
@@ -337,21 +335,23 @@ pub fn tidy_list(req: TidyRequest) -> Vec<String> {
337335
// accented characters very well.
338336

339337
// First, parse the given locale into a valid Locale
340-
let locale: Locale = req
341-
.locale
338+
let loc = req.locale.to_string();
339+
let loc: Locale = loc
342340
.parse()
343341
.expect("Error: given locale is not parse-able. Try form similar to en-US or es-ES.");
342+
344343
// Now use that Locale to sort the list more carefully
345-
tidied_list = sort_carefully(tidied_list, locale);
344+
tidied_list = sort_carefully(tidied_list, loc);
346345
}
347346
if req.sort_by_length {
348347
// First, parse the given locale into a valid Locale
349-
let locale: Locale = req
350-
.locale
348+
let loc = req.locale.to_string();
349+
let loc: Locale = loc
351350
.parse()
352351
.expect("Error: given locale is not parse-able. Try form similar to en-US or es-ES.");
352+
353353
eprintln!("Calling sort_by_length");
354-
tidied_list = sort_by_length(tidied_list, locale);
354+
tidied_list = sort_by_length(tidied_list, loc);
355355
}
356356
// And remove duplicates one more time
357357
tidied_list = dedup_without_sorting(&mut tidied_list);

src/list_manipulations.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ pub fn normalize_unicode(word: &str, nf: &str) -> Result<String, String> {
1616
}
1717
}
1818

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;
2223
/// Sort a Vector of words alphabetically, taking into account the locale of the words
2324
/// `.sorted()` words -> ["Zambia", "abbey", "eager", "enlever", "ezra", "zoo", "énigme"]
2425
/// 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();
3033

3134
let mut newly_sorted_list = list;
3235
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> {
3538

3639
/// Sort by word length, with longest words first. For words of equal length, sorts
3740
/// 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> {
3942
// Set up the collator again
40-
let mut options = CollatorOptions::new();
43+
let mut options = CollatorOptions::default();
4144
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();
4347

4448
let mut list = list;
4549
// Order by count_characters(w) descending, then within that,

0 commit comments

Comments
 (0)