#[repr(u8)]
#[non_exhaustive]
pub enum Strength {
Primary,
Secondary,
Tertiary,
Quaternary,
Identical,
}
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
Primary
Compare only on the level of base letters. This level corresponds to the ECMA-402 sensitivity “base”.
use icu_collator::*;
let mut options = CollatorOptions::new();
options.strength = Some(Strength::Primary);
let collator = Collator::try_new_unstable(
&icu_testdata::unstable(),
&Default::default(),
options,
)
.unwrap();
assert_eq!(collator.compare("E", "é"), core::cmp::Ordering::Equal);
Secondary
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_unstable(
&icu_testdata::unstable(),
&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
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_unstable(&icu_testdata::unstable(),
&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");
let ja_collator =
Collator::try_new_unstable(&icu_testdata::unstable(),
&locale.into(),
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
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");
let ja_collator =
Collator::try_new_unstable(&icu_testdata::unstable(),
&ja_locale.into(),
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_unstable(&icu_testdata::unstable(),
&Default::default(),
options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
core::cmp::Ordering::Equal);
TODO: Thai example.
Identical
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");
let ja_collator =
Collator::try_new_unstable(&icu_testdata::unstable(),
&ja_locale.into(),
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_unstable(&icu_testdata::unstable(),
&Default::default(),
options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
core::cmp::Ordering::Less);
Trait Implementations
sourceimpl Ord for Strength
impl Ord for Strength
sourceimpl PartialOrd<Strength> for Strength
impl PartialOrd<Strength> for Strength
sourcefn partial_cmp(&self, other: &Strength) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Copy for Strength
impl Eq for Strength
impl StructuralEq for Strength
impl StructuralPartialEq for Strength
Auto Trait Implementations
impl RefUnwindSafe for Strength
impl Send for Strength
impl Sync for Strength
impl Unpin for Strength
impl UnwindSafe for Strength
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more