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
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::default();
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::default();
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::*;
use icu::locale::locale;
let mut options = CollatorOptions::default();
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 ja_collator =
Collator::try_new(locale!("ja").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 = 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::*;
use icu::locale::locale;
let mut options = CollatorOptions::default();
options.strength = Some(Strength::Quaternary);
let ja_collator =
Collator::try_new(locale!("ja").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(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::*;
use icu::locale::locale;
let mut options = CollatorOptions::default();
options.strength = Some(Strength::Identical);
let ja_collator =
Collator::try_new(locale!("ja").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(Default::default(),
options).unwrap();
assert_eq!(collator.compare("דחי", "דחי֭"),
core::cmp::Ordering::Less);
Trait Implementations§
source§impl Ord for Strength
impl Ord for Strength
source§impl PartialOrd for Strength
impl PartialOrd for Strength
impl Copy for Strength
impl Eq for Strength
impl StructuralPartialEq for Strength
Auto Trait Implementations§
impl Freeze for Strength
impl RefUnwindSafe for Strength
impl Send for Strength
impl Sync for Strength
impl Unpin for Strength
impl UnwindSafe for Strength
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more