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 and only depends on core
. Focaccia does not
link to alloc
in its no_std
configuration.
§Unicode Version
Focaccia implements Unicode case folding with the Unicode 16.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.
Modules§
- Focaccia is derived from Unicode Data Files and is subject to Unicode License v3.
Structs§
- Error type for returned when a folding scheme could not be resolved in a
TryFrom
implementation.
Enums§
- Unicode case folding strategies.
Functions§
- Check two byte strings for equality with ASCII case folding.
- Compare two byte strings with ASCII case folding.
- Check two strings for equality with Full Unicode case folding.
- Compare two strings with Full Unicode case folding.
- Check two strings for equality with Full Unicode case folding for Turkic languages.
- Compare two strings with Full Unicode case folding for Turkic languages.