Skip to main content

mln_expression/
collator.rs

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