[][src]Crate focaccia

Unicode case folding methods for case-insensitive string comparisons.

Focaccia supports full, ASCII, and Turkic Unicode case folding equality and Ordering comparisons.

The primary entrypoint to Focaccia is the CaseFold enum. Focaccia also provides free functions for each case folding scheme.

Examples

For Unicode text, Focaccia recommends the Full folding scheme. 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"));

ASCII case comparison can be checked on a byte slice:

assert_eq!(ascii_casecmp(b"Artichoke Ruby", b"artichoke ruby"), Ordering::Equal);
assert!(ascii_case_eq(b"Artichoke Ruby", b"artichoke ruby"));

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

no_std

Focaccia is no_std compatible. By default, Focaccia builds with its std feature enabled to implement Error.

When built without the std feature, Focaccia does not link to alloc.

Crate features

All features are enabled by default.

  • std - Enable linking to the Rust Standard Library. Enabling this feature adds Error implementations to error types in this crate.

Structs

NoSuchCaseFoldingScheme

Error type for returned when a folding scheme could not be resolved in a TryFrom implementation.

Enums

CaseFold

Unicode case folding strategies.

Functions

ascii_case_eq

Check two bytestrings for equality with ASCII case folding.

ascii_casecmp

Compare two bytestrings with ASCII case folding.

unicode_full_case_eq

Check two strings for equality with Full Unicode case folding.

unicode_full_casecmp

Compare two strings with Full Unicode case folding.

unicode_full_turkic_case_eq

Check two strings for equality with Full Unicode case folding for Turkic languages.

unicode_full_turkic_casecmp

Compare two strings with Full Unicode case folding for Turkic languages.