1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Ports include/mln/style/expression/collator.hpp,
// src/mln/style/expression/collator.cpp and the default platform collator
// (platform/default/src/mln/i18n/collator.cpp).
//
// The default collator ignores the locale; it compares with nunicode's DUCET
// collation (`nu_strcoll` / `nu_strcasecoll`) and strips diacritics with
// nunicode's `unaccent` (//vendor/nunicode).
/// `mln::platform::Collator` (default implementation: ignores the locale).
#[derive(Clone, Debug, PartialEq, Eq)]
struct PlatformCollator {
case_sensitive: bool,
diacritic_sensitive: bool,
}
impl PlatformCollator {
fn compare(&self, lhs: &str, rhs: &str) -> i32 {
nunicode::collator_compare(lhs, rhs, self.case_sensitive, self.diacritic_sensitive)
}
fn resolved_locale(&self) -> String {
String::new()
}
}
/// `expression::Collator`.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Collator {
collator: PlatformCollator,
}
impl Collator {
pub fn new(case_sensitive: bool, diacritic_sensitive: bool, _locale: Option<String>) -> Self {
Collator {
collator: PlatformCollator {
case_sensitive,
diacritic_sensitive,
},
}
}
pub fn compare(&self, lhs: &str, rhs: &str) -> i32 {
self.collator.compare(lhs, rhs)
}
pub fn resolved_locale(&self) -> String {
self.collator.resolved_locale()
}
}