[−][src]Enum spinoso_symbol::CaseFold
artichoke
only.Unicode case folding strategies.
Unicode case folding data supports both implementations that require simple case foldings (where string lengths don't change), and implementations that allow full case folding (where string lengths may grow). Note that where they can be supported, the full case foldings are superior: for example, they allow "MASSE" and "Maße" to match.
The CaseFold
enum supports the folding strategies available in Ruby.
Examples
For Unicode text, the default folding schem is Full
. To
make a comparison:
let fold = CaseFold::Full; assert_eq!(fold.casecmp("MASSE", "Maße"), Ordering::Equal); assert_eq!(fold.casecmp("São Paulo", "Sao Paulo"), Ordering::Greater); assert!(fold.case_eq("MASSE", "Maße")); assert!(!fold.case_eq("São Paulo", "Sao Paulo"));
For text known to be ASCII, Focaccia can make a more performant comparison check:
let fold = CaseFold::Ascii; assert_eq!(fold.casecmp("Crate: focaccia", "Crate: FOCACCIA"), Ordering::Equal); assert_eq!(fold.casecmp("Fabled", "failed"), Ordering::Less); assert!(fold.case_eq("Crate: focaccia", "Crate: FOCACCIA")); assert!(!fold.case_eq("Fabled", "failed"));
Turkic case folding is similar to full case folding with additional mappings for dotted and dotless I:
let fold = CaseFold::Turkic; assert!(matches!(fold.casecmp("İstanbul", "istanbul"), Ordering::Equal)); assert!(!matches!(fold.casecmp("İstanbul", "Istanbul"), Ordering::Equal)); assert!(fold.case_eq("İstanbul", "istanbul")); assert!(!fold.case_eq("İstanbul", "Istanbul"));
Variants
Full Unicode case mapping, suitable for most languages (see Turkic
and Lithuanian
strategies for exceptions). Context-dependent case
mapping as described in Table 3-14 of the Unicode standard is currently
not supported.
Only the ASCII region, i.e. the characters "A" to "Z" and "a" to "z", are affected.
Full Unicode case mapping, adapted for Turkic languages (Turkish, Azerbaijani, ...). This means that upper case I is mapped to lower case dotless i, and so on.
Currently, just full Unicode case mapping. In the future, full Unicode case mapping adapted for Lithuanian (keeping the dot on the lower case i even if there is an accent on top).
Implementations
impl CaseFold
[src]
#[must_use]pub const fn new() -> CaseFold
[src]
Construct a new full Unicode case folding.
See CaseFold::Full
.
Examples
const FOLD: CaseFold = CaseFold::new(); assert_eq!(CaseFold::new(), CaseFold::Full); assert!(CaseFold::new().case_eq("MASSE", "Maße")); assert!(!CaseFold::new().case_eq("São Paulo", "Sao Paulo"));
#[must_use]pub fn casecmp(self, left: &str, right: &str) -> Ordering
[src]
Make a case-insensitive string comparison based on the dispatching folding strategy.
Return Ordering::Equal
if the given strings match when folding case.
For example, when using CaseFold::Full
, ß
is considered equal to
ss
. The differences between the folding strategies are documented on
the variants of the CaseFold
enum.
This function is a wrapper around the underlying scheme-specific functions.
Examples – Full case folding
let fold = CaseFold::Full; assert_eq!(fold.casecmp("MASSE", "Maße"), Ordering::Equal); assert_eq!(fold.casecmp("São Paulo", "Sao Paulo"), Ordering::Greater);
Examples – ASCII case folding
let fold = CaseFold::Ascii; assert_eq!(fold.casecmp("Crate: focaccia", "Crate: FOCACCIA"), Ordering::Equal); assert_eq!(fold.casecmp("Fabled", "failed"), Ordering::Less);
Examples – Turkic case folding
let fold = CaseFold::Turkic; assert!(matches!(fold.casecmp("İstanbul", "istanbul"), Ordering::Equal)); assert!(!matches!(fold.casecmp("İstanbul", "Istanbul"), Ordering::Equal));
#[must_use]pub fn case_eq(self, left: &str, right: &str) -> bool
[src]
Make a case-insensitive string equality check based on the dispatching folding strategy.
Return true
if the given strings match when folding case. For example,
when using CaseFold::Full
, ß
is considered equal to ss
. The
differences between the folding strategies are documented on the
variants of the CaseFold
enum.
This function is a wrapper around the underlying scheme-specific functions.
Examples – Full case folding
let fold = CaseFold::Full; assert!(fold.case_eq("MASSE", "Maße")); assert!(!fold.case_eq("São Paulo", "Sao Paulo"));
Examples – ASCII case folding
let fold = CaseFold::Ascii; assert!(fold.case_eq("Crate: focaccia", "Crate: FOCACCIA")); assert!(!fold.case_eq("Fabled", "failed"));
Examples – Turkic case folding
let fold = CaseFold::Turkic; assert!(fold.case_eq("İstanbul", "istanbul")); assert!(!fold.case_eq("İstanbul", "Istanbul"));
Trait Implementations
impl Clone for CaseFold
[src]
impl Copy for CaseFold
[src]
impl Debug for CaseFold
[src]
impl Default for CaseFold
[src]
pub fn default() -> CaseFold
[src]
Default to full Unicode case folding.
See CaseFold::Full
.
Examples
assert_eq!(CaseFold::default(), CaseFold::Full); assert!(CaseFold::default().case_eq("MASSE", "Maße")); assert!(!CaseFold::default().case_eq("São Paulo", "Sao Paulo"));
impl Eq for CaseFold
[src]
impl Hash for CaseFold
[src]
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for CaseFold
[src]
pub fn cmp(&self, other: &CaseFold) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<CaseFold> for CaseFold
[src]
pub fn eq(&self, other: &CaseFold) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<CaseFold> for CaseFold
[src]
pub fn partial_cmp(&self, other: &CaseFold) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for CaseFold
[src]
impl StructuralPartialEq for CaseFold
[src]
impl<'_> TryFrom<Option<&'_ [u8]>> for CaseFold
[src]
type Error = NoSuchCaseFoldingScheme
The type returned in the event of a conversion error.
pub fn try_from(
value: Option<&[u8]>
) -> Result<CaseFold, <CaseFold as TryFrom<Option<&'_ [u8]>>>::Error>
[src]
value: Option<&[u8]>
) -> Result<CaseFold, <CaseFold as TryFrom<Option<&'_ [u8]>>>::Error>
impl<'_> TryFrom<Option<&'_ str>> for CaseFold
[src]
Auto Trait Implementations
impl RefUnwindSafe for CaseFold
[src]
impl Send for CaseFold
[src]
impl Sync for CaseFold
[src]
impl Unpin for CaseFold
[src]
impl UnwindSafe for CaseFold
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,