Enum spinoso_string::CaseFold[][src]

pub enum CaseFold {
    Full,
    Ascii,
    Turkic,
    Lithuanian,
}
Expand description

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

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.

Ascii

Only the ASCII region, i.e. the characters “A” to “Z” and “a” to “z”, are affected.

Turkic

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.

Lithuanian

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

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"));

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));

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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"));

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.