Crate focaccia

Source
Expand description

Unicode case folding methods for case-insensitive string comparisons.

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

The primary entry point 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_eq!(fold.casecmp("İstanbul", "istanbul"), Ordering::Equal);
assert_ne!(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.

§Unicode Version

Focaccia implements Unicode case folding with the Unicode 15.0.0 case folding ruleset.

Each new release of Unicode may bring updates to the CaseFolding.txt which is the source for the folding mappings in this crate. Updates to the case folding rules will be accompanied with a minor version bump.

Structs§

Enums§

  • Unicode case folding strategies.

Functions§