Unicode 14.0.0 case folding methods for case-insensitive string comparisons.
Used to implement case folding operations on the [Symbol
] and [String
]
classes in the Ruby Core implementation in Artichoke Ruby.
Focaccia supports full, ASCII, and Turkic [Unicode case folding] equality comparisons. ASCII folding supports determining case-insensitive ordering.
One of the most common things that software developers do is "normalize" text for the purposes of comparison. And one of the most basic ways that developers are taught to normalize text for comparison is to compare it in a "case insensitive" fashion. In other cases, developers want to compare strings in a case sensitive manner. Unicode defines upper, lower, and title case properties for characters, plus special cases that impact specific language's use of text. (W3C, Case Folding)
focaccia is a flat Italian bread. The focaccia crate compares UTF-8 strings by flattening them to folded downcase. Artichoke goes well with focaccia.
Add this to your Cargo.toml
:
toml
[dependencies]
focaccia = "1.1"
Then make case insensitive string comparisons like:
```rust use core::cmp::Ordering; use focaccia::CaseFold;
let fold = CaseFold::Full; asserteq!(fold.casecmp("MASSE", "Maße"), Ordering::Equal); asserteq!(fold.casecmp("São Paulo", "Sao Paulo"), Ordering::Greater);
assert!(fold.caseeq("MASSE", "Maße")); assert!(!fold.caseeq("São Paulo", "Sao Paulo")); ```
For text known to be ASCII, Focaccia can make a more performant comparison check:
```rust use core::cmp::Ordering; use focaccia::CaseFold;
let fold = CaseFold::Ascii; asserteq!(fold.casecmp("Crate: focaccia", "Crate: FOCACCIA"), Ordering::Equal); asserteq!(fold.casecmp("Fabled", "failed"), Ordering::Less);
assert!(fold.caseeq("Crate: focaccia", "Crate: FOCACCIA")); assert!(!fold.caseeq("Fabled", "failed")); ```
ASCII case comparison can be checked on a byte slice:
```rust use core::cmp::Ordering; use focaccia::{asciicasecmp, asciicase_eq};
asserteq!(asciicasecmp(b"Artichoke Ruby", b"artichoke ruby"), Ordering::Equal); assert!(asciicaseeq(b"Artichoke Ruby", b"artichoke ruby")); ```
Turkic case folding is similar to full case folding with additional mappings for [dotted and dotless I]:
```rust use core::cmp::Ordering; use focaccia::CaseFold;
let fold = CaseFold::Turkic; assert!(matches!(fold.casecmp("İstanbul", "istanbul"), Ordering::Equal)); assert!(!matches!(fold.casecmp("İstanbul", "Istanbul"), Ordering::Equal));
assert!(fold.caseeq("İstanbul", "istanbul")); assert!(!fold.caseeq("İstanbul", "Istanbul")); ```
Focaccia generates conversion tables from Unicode data files. Focaccia
implements case folding as defined in Unicode 13 (see
CaseFolding.txt
).
no_std
Focaccia is no_std
compatible with an optional and enabled by default
dependency on std
. Unlike [unicase
], Focaccia does not link to alloc
in
its no_std
configuration.
All features are enabled by default.
Error
] implementations to error types in this crate.This crate requires at least Rust 1.52.0. This version can be bumped in minor releases.
Focaccia implements Unicode case folding with the Unicode 14.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.
focaccia
is licensed under the MIT License (c) Ryan Lopopolo.