Enum icu_collator::Strength

source ·
#[non_exhaustive]
#[repr(u8)]
pub enum Strength { Primary = 0, Secondary = 1, Tertiary = 2, Quaternary = 3, Identical = 7, }
Expand description

The collation strength that indicates how many levels to compare. If an earlier level isn’t equal, the earlier level is decisive. If the result is equal on a level, but the strength is higher, the comparison proceeds to the next level.

Note: The bit layout of CollatorOptions requires Strength to fit in 3 bits.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Primary = 0

Compare only on the level of base letters. This level corresponds to the ECMA-402 sensitivity “base” with CaseLevel::Off (the default for CaseLevel) and to ECMA-402 sensitivity “case” with CaseLevel::On.

use icu::collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Primary);
let collator = Collator::try_new(&Default::default(), options).unwrap();
assert_eq!(collator.compare("E", "é"), core::cmp::Ordering::Equal);
§

Secondary = 1

Compare also on the secondary level, which corresponds to diacritics in scripts that use them. This level corresponds to the ECMA-402 sensitivity “accent”.

use icu::collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Secondary);
let collator = Collator::try_new(&Default::default(), options).unwrap();
assert_eq!(collator.compare("E", "e"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("e", "é"), core::cmp::Ordering::Less);
assert_eq!(collator.compare("あ", "ア"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("ァ", "ア"), core::cmp::Ordering::Equal);
assert_eq!(collator.compare("ア", "ア"), core::cmp::Ordering::Equal);
§

Tertiary = 2

Compare also on the tertiary level. By default, if the separate case level is disabled, this corresponds to case for bicameral scripts. This level distinguishes Hiragana and Katakana. This also captures other minor differences, such as half-width vs. full-width when the Japanese tailoring isn’t in use.

This is the default comparison level and appropriate for most scripts. This level corresponds to the ECMA-402 sensitivity “variant”.

use icu::collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Tertiary);
let collator =
  Collator::try_new(&Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("E", "e"),
           core::cmp::Ordering::Greater);
assert_eq!(collator.compare("e", "é"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("あ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("ァ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("ア", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Less);

let locale = icu::locid::locale!("ja").into();
let ja_collator =
  Collator::try_new(&locale, options).unwrap();
assert_eq!(ja_collator.compare("E", "e"),
           core::cmp::Ordering::Greater);
assert_eq!(ja_collator.compare("e", "é"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("あ", "ア"),
           core::cmp::Ordering::Equal); // Unlike root!
assert_eq!(ja_collator.compare("ァ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Equal); // Unlike root!
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Equal); // Unlike root!
§

Quaternary = 3

Compare also on the quaternary level. For Japanese, Higana and Katakana are distinguished at the quaternary level. Also, if AlternateHandling::Shifted is used, the collation elements whose level gets shifted are shifted to this level.

use icu::collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Quaternary);

let ja_locale = icu::locid::locale!("ja").into();
let ja_collator =
  Collator::try_new(&ja_locale, options).unwrap();
assert_eq!(ja_collator.compare("あ", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Equal);
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Equal);

// Even this level doesn't distinguish everything,
// e.g. Hebrew cantillation marks are still ignored.
let collator =
  Collator::try_new(&Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
           core::cmp::Ordering::Equal);

TODO: Thai example.

§

Identical = 7

Compare the NFD form by code point order as the quinary level. This level makes the comparison slower and should not be used in the general case. However, it can be used to distinguish full-width and half-width forms when the Japanese tailoring is in use and to distinguish e.g. Hebrew cantillation markse. Use this level if you need JIS X 4061-1996 compliance for Japanese on the level of distinguishing full-width and half-width forms.

use icu::collator::*;

let mut options = CollatorOptions::new();
options.strength = Some(Strength::Identical);

let ja_locale = icu::locid::locale!("ja").into();
let ja_collator =
  Collator::try_new(&ja_locale, options).unwrap();
assert_eq!(ja_collator.compare("ア", "ア"),
           core::cmp::Ordering::Less);
assert_eq!(ja_collator.compare("e", "e"), // Full-width e
           core::cmp::Ordering::Less);

let collator =
  Collator::try_new(&Default::default(),
                    options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
           core::cmp::Ordering::Less);

Trait Implementations§

source§

impl Clone for Strength

source§

fn clone(&self) -> Strength

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Strength

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Ord for Strength

source§

fn cmp(&self, other: &Strength) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Strength

source§

fn eq(&self, other: &Strength) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Strength

source§

fn partial_cmp(&self, other: &Strength) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Strength

source§

impl Eq for Strength

source§

impl StructuralPartialEq for Strength

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T