### Install toolchains with mise Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Run this command after activating mise to install the Rust, Ruby, and Node.js toolchains declared in mise.toml. ```sh mise install ``` -------------------------------- ### Install Node.js dependencies Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Installs Node.js via mise and installs repository-local dependencies with pnpm. Required for formatting markdown, YAML, and YML files. ```sh mise install pnpm install ``` -------------------------------- ### unicode_full_casecmp usage example Source: https://github.com/artichoke/focaccia Example usage of unicode_full_casecmp with assertions for equal, greater, and less orderings. ```rust use core::cmp::Ordering; use focaccia::unicode_full_casecmp; assert_eq!(unicode_full_casecmp("MASSE", "Maße"), Ordering::Equal); assert_eq!(unicode_full_casecmp("São Paulo", "Sao Paulo"), Ordering::Greater); assert_eq!(unicode_full_casecmp("", "São Paulo"), Ordering::Less); ``` -------------------------------- ### unicode_full_case_eq usage example Source: https://github.com/artichoke/focaccia Example usage of unicode_full_case_eq with assertions covering equal, unequal, ASCII fast path, length mismatch, and empty strings. ```rust use focaccia::unicode_full_case_eq; assert!(unicode_full_case_eq("MASSE", "Maße")); assert!(!unicode_full_case_eq("São Paulo", "Sao Paulo")); assert!(unicode_full_case_eq("aBcDeF", "abcdef")); // pure ASCII fast path assert!(!unicode_full_case_eq("abcdef", "abcde")); // length mismatch assert!(unicode_full_case_eq("", "")); // empty strings are equal ``` -------------------------------- ### Build with mise Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Installs the Rust crates specified in Cargo.toml and runs the build task. ```sh mise run build ``` -------------------------------- ### unicode_full_lithuanian_casecmp usage example Source: https://github.com/artichoke/focaccia Example of comparing strings with Lithuanian case folding. The first assertion expects Equal, the second expects Less. ```rust use core::cmp::Ordering; use focaccia::unicode_full_lithuanian_casecmp; assert_eq!(unicode_full_lithuanian_casecmp("I\u{301}", "i\u{301}"), Ordering::Equal); assert_eq!(unicode_full_lithuanian_casecmp("I\u{301}", "i\u{307}\u{301}"), Ordering::Less); ``` -------------------------------- ### ascii_casecmp usage example Source: https://github.com/artichoke/focaccia Usage of ascii_casecmp with byte strings. Demonstrates equality, ordering, and length tiebreak behavior. ```rust use core::cmp::Ordering; use focaccia::ascii_casecmp; assert_eq!(ascii_casecmp(b"Artichoke Ruby", b"artichoke ruby"), Ordering::Equal); assert_eq!(ascii_casecmp(b"artichoke ruby", b"Artichoke"), Ordering::Greater); assert_eq!(ascii_casecmp(b"abcdef", b"abcde"), Ordering::Greater); // length tiebreak ``` -------------------------------- ### unicode_full_turkic_casecmp usage example Source: https://github.com/artichoke/focaccia Example usage of unicode_full_turkic_casecmp. Demonstrates equality for Turkish case folding and compatibility with full folding. Requires importing the function from focaccia. ```rust use core::cmp::Ordering; use focaccia::unicode_full_turkic_casecmp; assert_eq!(unicode_full_turkic_casecmp("İstanbul", "istanbul"), Ordering::Equal); assert_ne!(unicode_full_turkic_casecmp("İstanbul", "Istanbul"), Ordering::Equal); // Largely compatible with full folding: assert_eq!(unicode_full_turkic_casecmp("MASSE", "Maße"), Ordering::Equal); ``` -------------------------------- ### unicode_full_turkic_case_eq usage example Source: https://github.com/artichoke/focaccia Example usage of unicode_full_turkic_case_eq. Demonstrates equality for Turkish case folding and compatibility with full folding. Requires importing the function from focaccia. ```rust use focaccia::unicode_full_turkic_case_eq; assert!(unicode_full_turkic_case_eq("İstanbul", "istanbul")); assert!(!unicode_full_turkic_case_eq("İstanbul", "Istanbul")); assert!(unicode_full_turkic_case_eq("MASSE", "Maße")); ``` -------------------------------- ### unicode_full_lithuanian_case_eq usage example Source: https://github.com/artichoke/focaccia Example of checking equality with Lithuanian case folding. The first two assertions show expected results, and the third demonstrates case-insensitive comparison. ```rust use focaccia::unicode_full_lithuanian_case_eq; assert!(unicode_full_lithuanian_case_eq("I\u{301}", "i\u{301}")); assert!(!unicode_full_lithuanian_case_eq("I\u{301}", "i\u{307}\u{301}")); assert!(unicode_full_lithuanian_case_eq("MASSE", "Maße")); ``` -------------------------------- ### ascii_case_eq usage example Source: https://github.com/artichoke/focaccia Usage of ascii_case_eq with byte strings. Demonstrates equality, length mismatch, and unchanged non-ASCII bytes. ```rust use focaccia::ascii_case_eq; assert!(ascii_case_eq(b"Artichoke Ruby", b"artichoke ruby")); assert!(!ascii_case_eq(b"artichoke ruby", b"Artichoke")); // different lengths assert!(ascii_case_eq(b"\u{FFFD}".as_bytes(), "\u{FFFD}".as_bytes())); // U+FFFD unchanged ``` -------------------------------- ### CaseFold::case_eq usage with all folding strategies Source: https://github.com/artichoke/focaccia Example showing case_eq with Full, Ascii, Turkic, and Lithuanian strategies. Includes assertions for equality and inequality, including the Lithuanian dot handling. ```rust use focaccia::CaseFold; assert!(CaseFold::Full.case_eq("MASSE", "Maße")); assert!(!CaseFold::Full.case_eq("São Paulo", "Sao Paulo")); assert!(CaseFold::Ascii.case_eq("Crate: focaccia", "Crate: FOCACCIA")); assert!(!CaseFold::Ascii.case_eq("Fabled", "failed")); assert!(CaseFold::Turkic.case_eq("İstanbul", "istanbul")); assert!(!CaseFold::Turkic.case_eq("İstanbul", "Istanbul")); assert!(CaseFold::Lithuanian.case_eq("I\u{301}", "i\u{301}")); assert!(!CaseFold::Lithuanian.case_eq("I\u{301}", "i\u{307}\u{301}")); ``` -------------------------------- ### CaseFold::casecmp usage with Ascii folding Source: https://github.com/artichoke/focaccia Example using CaseFold::Ascii for ASCII-only case-insensitive comparison. Shows that 'Crate: focaccia' equals 'Crate: FOCACCIA' and 'Fabled' is less than 'failed'. ```rust use core::cmp::Ordering; use focaccia::CaseFold; let fold = CaseFold::Ascii; assert_eq!(fold.casecmp("Crate: focaccia", "Crate: FOCACCIA"), Ordering::Equal); assert_eq!(fold.casecmp("Fabled", "failed"), Ordering::Less); ``` -------------------------------- ### CaseFold::casecmp usage with Full folding Source: https://github.com/artichoke/focaccia Example using CaseFold::Full to compare strings case-insensitively. Shows that 'ß' is considered equal to 'ss' and that 'São Paulo' is greater than 'Sao Paulo'. ```rust use core::cmp::Ordering; use focaccia::CaseFold; let fold = CaseFold::Full; assert_eq!(fold.casecmp("MASSE", "Maße"), Ordering::Equal); assert_eq!(fold.casecmp("São Paulo", "Sao Paulo"), Ordering::Greater); ``` -------------------------------- ### CaseFold::casecmp usage with Turkic folding Source: https://github.com/artichoke/focaccia Example using CaseFold::Turkic, which handles the Turkish I differently. Shows that 'İstanbul' equals 'istanbul' but not 'Istanbul'. ```rust use core::cmp::Ordering; use focaccia::CaseFold; let fold = CaseFold::Turkic; assert_eq!(fold.casecmp("İstanbul", "istanbul"), Ordering::Equal); assert_ne!(fold.casecmp("İstanbul", "Istanbul"), Ordering::Equal); ``` -------------------------------- ### Run tests with cargo test filter Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md `cargo test` accepts a filter argument that limits test execution to tests that substring match. For example, to run all tests for ascii casecmp, use `cargo test ascii`. ```sh cargo test ascii ``` -------------------------------- ### Prefix enum definition Source: https://github.com/artichoke/focaccia Defines the result of the ASCII fast path comparison. Complete(Ordering) indicates the comparison was decided by ASCII prefixes, while Unicode(left, right) carries the remaining suffixes starting at the first non-ASCII byte. ```rust pub(super) enum Prefix<'a> { Complete(Ordering), Unicode(&'a str, &'a str), } ``` -------------------------------- ### Run benchmarks with cargo bench Source: https://github.com/artichoke/focaccia/blob/trunk/docs/benchmarks.md Runs the case_mapping benchmark and writes CSV output to target/benchmarks/results.csv. The second command uses BENCH_FILTER, BENCH_MS, and BENCH_SAMPLES to select workloads and adjust timing. ```sh mkdir -p target/benchmarks cargo bench --bench case_mapping > target/benchmarks/results.csv BENCH_FILTER=ascii_long BENCH_MS=50 BENCH_SAMPLES=11 cargo bench --bench case_mapping ``` -------------------------------- ### Create and push a release tag Source: https://github.com/artichoke/focaccia/blob/trunk/docs/publishing.md Run these commands to create a signed tag for a release. The tag must match the exact vX.Y.Z form required by the publish workflow. ```sh git switch trunk git pull --ff-only git tag -s "vX.Y.Z" -m "vX.Y.Z" git push origin "vX.Y.Z" ``` -------------------------------- ### Run validation commands Source: https://github.com/artichoke/focaccia/blob/trunk/docs/automations/dependency-sweep.md Run these commands to validate changes before opening a pull request. They format, lint, test, and package the project. ```sh mise run fmt mise run lint mise run test cargo package --allow-dirty ``` -------------------------------- ### Run tests with mise Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Use `mise run test` to run the test suite. Tests are run for every PR and all builds must pass before merging. ```sh mise run test ``` -------------------------------- ### Add Focaccia dependency to Cargo.toml Source: https://github.com/artichoke/focaccia/blob/trunk/README.md Adds the Focaccia crate version 2.6.0 as a dependency in Cargo.toml. ```toml [dependencies] focaccia = "2.6.0" ``` -------------------------------- ### Import focaccia public API Source: https://github.com/artichoke/focaccia Shows the crate root imports for the public API: CaseFold, ascii_casecmp, ascii_case_eq, NoSuchCaseFoldingScheme, and UNICODE_VERSION. ```rust use focaccia::CaseFold; use focaccia::{ascii_casecmp, ascii_case_eq}; use focaccia::NoSuchCaseFoldingScheme; use focaccia::UNICODE_VERSION; ``` -------------------------------- ### Error handling pattern with CaseFold::try_from Source: https://github.com/artichoke/focaccia Shows how to resolve a folding strategy name with try_from, falling back to CaseFold::Full on error. Then uses case_eq to compare strings. ```rust use core::convert::TryFrom; use focaccia::CaseFold; let fold = match CaseFold::try_from(Some("turkic")) { Ok(fold) => fold, Err(_) => CaseFold::Full, // unknown scheme, fall back to full folding }; assert!(fold.case_eq("İstanbul", "istanbul")); ``` -------------------------------- ### Full Unicode case folding with CaseFold::Full Source: https://github.com/artichoke/focaccia/blob/trunk/README.md Performs case-insensitive comparisons using full Unicode case folding. Demonstrates equality and ordering for non-ASCII strings. ```rust use core::cmp::Ordering; use focaccia::CaseFold; 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")); ``` -------------------------------- ### Update Unicode data Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Downloads the current Unicode license and case-folding data and generates Rust lookup tables. Review changes before committing. ```sh mise run unicode:update mise run unicode:build ``` -------------------------------- ### TryFrom match arms for NoSuchCaseFoldingScheme Source: https://github.com/artichoke/focaccia The canonical byte-slice conversion match in `src/lib.rs:454-470`. It maps `None` to `Full` and exact byte matches for `ascii`, `turkic`, and `lithuanian`; any other value returns `Err(NoSuchCaseFoldingScheme::new())`. There is no wildcard success arm. ```rust match value { None => Ok(Self::Full), Some(scheme) if scheme == b"ascii" => Ok(Self::Ascii), Some(scheme) if scheme == b"turkic" => Ok(Self::Turkic), Some(scheme) if scheme == b"lithuanian" => Ok(Self::Lithuanian), Some(_) => Err(NoSuchCaseFoldingScheme::new()), } ``` -------------------------------- ### ASCII case comparison on byte slices Source: https://github.com/artichoke/focaccia/blob/trunk/README.md Compares ASCII strings as byte slices using the free functions ascii_casecmp and ascii_case_eq. ```rust use core::cmp::Ordering; use focaccia::{ascii_casecmp, ascii_case_eq}; assert_eq!(ascii_casecmp(b"Artichoke Ruby", b"artichoke ruby"), Ordering::Equal); assert!(ascii_case_eq(b"Artichoke Ruby", b"artichoke ruby")); ``` -------------------------------- ### Common development tasks Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Lists the common development tasks declared in mise.toml for building, testing, formatting, linting, and documentation. ```sh mise run build mise run test mise run fmt mise run fmt:check mise run lint mise run lint:clippy:restriction mise run doc mise run doc:open ``` -------------------------------- ### TryFrom> for CaseFold Source: https://github.com/artichoke/focaccia Attempts to convert an optional string into a CaseFold. Returns an error if the string does not match a known case folding scheme. ```APIDOC ## TryFrom> for CaseFold ### Description Attempts to convert an optional string into a CaseFold. Returns an error if the string does not match a known case folding scheme. ### Method TryFrom ### Parameters - `value` (Option<&str>) - The optional string to convert. ### Return Value - `Result` - The resulting CaseFold or an error. ``` -------------------------------- ### CaseFold::try_from Source: https://github.com/artichoke/focaccia Converts a scheme name (as &str or &[u8]) into a CaseFold. Returns Ok(CaseFold) for recognized schemes, or Err(NoSuchCaseFoldingScheme) for unrecognized input. ```APIDOC ## TryFrom> for CaseFold ### Description Converts an optional string scheme name into a CaseFold. `None` maps to `CaseFold::Full`; recognized names "ascii", "turkic", "lithuanian" map to their respective variants; any other string (including "full", empty, or case-variant) returns `Err(NoSuchCaseFoldingScheme)`. ### Method TryFrom ### Endpoint `CaseFold::try_from(Option<&str>)` ### Parameters - **value** (Option<&str>) - Required - The scheme name as an optional string. `None` means no override (full folding). ### Response #### Success Response (Ok) - **CaseFold** - The corresponding case folding scheme. #### Error Response (Err) - **NoSuchCaseFoldingScheme** - Returned when the string is not a recognized scheme name. ### Request Example ```rust use core::convert::TryFrom; use focaccia::CaseFold; let fold = CaseFold::try_from(Some("ascii")); ``` ### Response Example ```rust Ok(CaseFold::Ascii) ``` ## TryFrom> for CaseFold ### Description Converts an optional byte-slice scheme name into a CaseFold. This is the canonical implementation; the string conversion delegates to it. `None` maps to `CaseFold::Full`; recognized byte sequences "ascii", "turkic", "lithuanian" map to their respective variants; any other byte sequence returns `Err(NoSuchCaseFoldingScheme)`. ### Method TryFrom ### Endpoint `CaseFold::try_from(Option<&[u8]>)` ### Parameters - **value** (Option<&[u8]>) - Required - The scheme name as an optional byte slice. `None` means no override (full folding). ### Response #### Success Response (Ok) - **CaseFold** - The corresponding case folding scheme. #### Error Response (Err) - **NoSuchCaseFoldingScheme** - Returned when the byte slice is not a recognized scheme name. ### Request Example ```rust use core::convert::TryFrom; use focaccia::CaseFold; let fold = CaseFold::try_from(Some(b"turkic")); ``` ### Response Example ```rust Ok(CaseFold::Turkic) ``` ``` -------------------------------- ### TryFrom> for CaseFold Source: https://github.com/artichoke/focaccia Attempts to convert an optional byte slice into a CaseFold. Returns an error if the bytes do not match a known case folding scheme. ```APIDOC ## TryFrom> for CaseFold ### Description Attempts to convert an optional byte slice into a CaseFold. Returns an error if the bytes do not match a known case folding scheme. ### Method TryFrom ### Parameters - `value` (Option<&[u8]>) - The optional byte slice to convert. ### Return Value - `Result` - The resulting CaseFold or an error. ``` -------------------------------- ### Run lint and formatting checks with mise Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Use `mise run lint` to lint and check formatting for Rust and text sources. The unenforced Clippy restriction lint pass is available separately as `mise run lint:clippy:restriction`. ```sh mise run lint ``` -------------------------------- ### unicode_terms doc-only module declaration Source: https://github.com/artichoke/focaccia Declares the doc-only `unicode_terms` module, which exists only in documentation builds via `#[cfg(doc)]` and embeds the Unicode License v3 text. It has no runtime content. ```rust #[cfg(doc)] #[cfg_attr(docsrs, doc(cfg(doc)))] pub mod unicode_terms {} ``` -------------------------------- ### impl fmt::Display for NoSuchCaseFoldingScheme Source: https://github.com/artichoke/focaccia Implements `Display` with the exact string `No such Unicode case folding scheme exists`. ```rust impl fmt::Display for NoSuchCaseFoldingScheme { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("No such Unicode case folding scheme exists") } } ``` -------------------------------- ### impl Default for CaseFold Source: https://github.com/artichoke/focaccia Provides the default case folding strategy, which is CaseFold::Full. ```rust impl Default for CaseFold { #[inline] fn default() -> Self { Self::Full } } ``` -------------------------------- ### Catching NoSuchCaseFoldingScheme from TryFrom Source: https://github.com/artichoke/focaccia Shows three ways to handle the `Result` from `TryFrom`: pattern matching, `?` propagation, and catching the error value. The error's display string is `No such Unicode case folding scheme exists`. ```rust use core::convert::TryFrom; use focaccia::{CaseFold, NoSuchCaseFoldingScheme}; // 1. Pattern matching on the Result match CaseFold::try_from(Some("ascii")) { Ok(fold) => assert_eq!(fold, CaseFold::Ascii), Err(err) => unreachable!("ascii is a valid scheme: {err}"), } // 2. Propagation with `?` (e.g. returning Result from a helper) fn strategy(value: Option<&[u8]>) -> Result { Ok(CaseFold::try_from(value)?) } // 3. Catching the error value let err = CaseFold::try_from(Some("bogus")).unwrap_err(); assert_eq!(err, NoSuchCaseFoldingScheme::new()); assert_eq!(err.to_string(), "No such Unicode case folding scheme exists"); ``` -------------------------------- ### Update Unicode data with repository tasks Source: https://github.com/artichoke/focaccia/blob/trunk/docs/automations/unicode.md Run these commands in order to update Unicode data, build, format, lint, test, and package the crate. The updater resolves the final release once before downloading versioned inputs. Review every generated diff and confirm the license is present in the crate package. ```sh mise run unicode:update mise run unicode:build mise run fmt mise run lint mise run test cargo package --allow-dirty ``` -------------------------------- ### UNICODE_VERSION constant Source: https://github.com/artichoke/focaccia Defines the bundled Unicode case folding version as a (major, minor, patch) tuple. Independent of the Rust compiler's Unicode tables; Unicode updates change comparison results and require a minor crate release. ```rust pub const UNICODE_VERSION: (u8, u8, u8) = (18, 0, 0); ``` -------------------------------- ### CaseFold::new Source: https://github.com/artichoke/focaccia Creates a new CaseFold instance. The default case folding scheme is used. ```APIDOC ## CaseFold::new ### Description Creates a new CaseFold instance. The default case folding scheme is used. ### Method new ### Return Value - `CaseFold` - A new CaseFold instance. ``` -------------------------------- ### TryFrom implementations for CaseFold Source: https://github.com/artichoke/focaccia Shows the `TryFrom` impls on `CaseFold` that use `NoSuchCaseFoldingScheme` as their `Error` type. The `// ...` indicates omitted body. ```rust impl TryFrom> for CaseFold { type Error = NoSuchCaseFoldingScheme; // ... } impl TryFrom> for CaseFold { type Error = NoSuchCaseFoldingScheme; // ... } ``` -------------------------------- ### impl TryFrom> for CaseFold Source: https://github.com/artichoke/focaccia Converts an optional string slice into a CaseFold variant. None resolves to Full, unknown names produce an error. ```rust impl TryFrom> for CaseFold { type Error = NoSuchCaseFoldingScheme; #[inline] fn try_from(value: Option<&str>) -> Result { Self::try_from(value.map(str::as_bytes)) } } ``` -------------------------------- ### compare function signature Source: https://github.com/artichoke/focaccia Signature for the ASCII fast path comparison function. It walks both byte slices simultaneously, folding ASCII bytes per mode, and returns a Prefix indicating either a complete ordering or the remaining Unicode suffixes. ```rust #[inline] pub(super) fn compare<'a>(left: &'a str, right: &'a str, mode: Mode) -> Prefix<'a> ``` -------------------------------- ### Update stable Rust compiler Source: https://github.com/artichoke/focaccia/blob/trunk/CONTRIBUTING.md Updates the stable Rust toolchain to the latest version. ```sh rustup update stable ``` -------------------------------- ### CaseFold::new Source: https://github.com/artichoke/focaccia Constructs a new full Unicode case folding strategy. Always returns CaseFold::Full and is usable in const contexts. ```APIDOC ## CaseFold::new ### Description Construct a new full Unicode case folding. Always returns `Self::Full`, and is usable in `const` contexts. ### Method `pub const fn new() -> Self` ### Parameters No parameters. ### Returns - `Self` — always `CaseFold::Full`. ### Usage Example ```rust use focaccia::CaseFold; 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")); ``` ``` -------------------------------- ### impl TryFrom> for CaseFold Source: https://github.com/artichoke/focaccia Converts an optional byte slice into a CaseFold variant. None resolves to Full, unknown names produce an error. ```rust impl TryFrom> for CaseFold { type Error = NoSuchCaseFoldingScheme; #[inline] fn try_from(value: Option<&[u8]>) -> Result { match value { None => Ok(Self::Full), Some(scheme) if scheme == b"ascii" => Ok(Self::Ascii), Some(scheme) if scheme == b"turkic" => Ok(Self::Turkic), Some(scheme) if scheme == b"lithuanian" => Ok(Self::Lithuanian), Some(_) => Err(NoSuchCaseFoldingScheme::new()), } } } ``` -------------------------------- ### unicode_full_casecmp function signature Source: https://github.com/artichoke/focaccia Signature for comparing two strings with Full Unicode case folding. Returns an Ordering. ```rust #[inline] #[must_use] pub fn casecmp(left: &str, right: &str) -> Ordering ``` -------------------------------- ### ascii_casecmp Source: https://github.com/artichoke/focaccia Compares two byte strings using ASCII case folding, returning an Ordering. This function is infallible and always returns a value. ```APIDOC ## ascii_casecmp ### Description Compares two byte strings with ASCII case folding, implemented with ASCII folding functions in Rust `core` (each byte is lowercased via `u8::to_ascii_lowercase`, then the mapped iterators are compared with `Iterator::cmp`). ### Parameters #### Parameters - **left** (`&[u8]`) - Required - Left-hand byte string - **right** (`&[u8]`) - Required - Right-hand byte string ### Returns `Ordering` — `Ordering::Less`/`Equal`/`Greater`. Byte values outside `A`–`Z`/`a`–`z` are compared unchanged, so non-ASCII bytes never fold to each other. ### Usage ```rust use core::cmp::Ordering; use focaccia::ascii_casecmp; assert_eq!(ascii_casecmp(b"Artichoke Ruby", b"artichoke ruby"), Ordering::Equal); assert_eq!(ascii_casecmp(b"artichoke ruby", b"Artichoke"), Ordering::Greater); assert_eq!(ascii_casecmp(b"abcdef", b"abcde"), Ordering::Greater); // length tiebreak ``` ``` -------------------------------- ### CaseFold::default Source: https://github.com/artichoke/focaccia Returns the default CaseFold instance. This is equivalent to `CaseFold::new()`. ```APIDOC ## CaseFold::default ### Description Returns the default CaseFold instance. This is equivalent to `CaseFold::new()`. ### Method default ### Return Value - `CaseFold` - The default CaseFold instance. ``` -------------------------------- ### ascii_casecmp function signature Source: https://github.com/artichoke/focaccia Signature for the ASCII case-insensitive ordering function. It is #[inline] #[must_use] and infallible, returning Ordering. Byte values outside A-Z/a-z are compared unchanged. ```rust #[inline] #[must_use] pub fn casecmp(left: &[u8], right: &[u8]) -> Ordering ``` -------------------------------- ### impl IntoIterator for Mapping Source: https://github.com/artichoke/focaccia Consuming a Mapping yields the folded scalars as u32 values. This is what allows left.chars().flat_map(|c| lookup(c, mode)) in full.rs/turkic.rs to flatten expansions into a single scalar stream. ```rust impl IntoIterator for Mapping { type Item = u32; type IntoIter = Iter; #[inline] fn into_iter(self) -> Self::IntoIter { Iter(self) } } ``` -------------------------------- ### unicode_full_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using Full Unicode case folding and returns an Ordering. It uses a lookup table generated from Unicode case folding tables and compares the folded scalar iterators. ```APIDOC ## `unicode_full_casecmp` ### Description Compare two strings with Full Unicode case folding, implemented with a lookup table generated from Unicode case folding tables. Internally: run `prefix::compare(left, right, Mode::Full)`; if it returns `Prefix::Complete(ordering)` return that ordering immediately, otherwise fold the remaining `&str` suffixes character-by-character through `mapping::lookup(c, Mode::Full)` and compare the flattened `u32` scalar iterators. ### Signature ```rust pub fn casecmp(left: &str, right: &str) -> Ordering ``` ### Parameters - `left` (`&str`) - Required - Left-hand UTF-8 string - `right` (`&str`) - Required - Right-hand UTF-8 string ### Returns `Ordering` ### Usage ```rust use core::cmp::Ordering; use focaccia::unicode_full_casecmp; assert_eq!(unicode_full_casecmp("MASSE", "Maße"), Ordering::Equal); assert_eq!(unicode_full_casecmp("São Paulo", "Sao Paulo"), Ordering::Greater); assert_eq!(unicode_full_casecmp("", "São Paulo"), Ordering::Less); ``` ``` -------------------------------- ### CaseFold::new signature Source: https://github.com/artichoke/focaccia Constructs a new full Unicode case folding. Always returns Self::Full and is usable in const contexts. ```rust #[inline] #[must_use] pub const fn new() -> Self ``` -------------------------------- ### unicode_full_turkic_case_eq Source: https://github.com/artichoke/focaccia Checks two strings for equality using Full Unicode case folding for Turkic languages. Uses the same Turkic-specific mappings as unicode_full_turkic_casecmp. ```APIDOC ## unicode_full_turkic_case_eq ### Description Check two strings for equality with Full Unicode case folding for Turkic languages, using the same `Mode::Turkic` mappings as `unicode_full_turkic_casecmp`. ### Parameters | Parameter | Type | Required | Default | Description | |---|---|---|---|---| | `left` | `&str` | yes | — | Left-hand UTF-8 string | | `right` | `&str` | yes | — | Right-hand UTF-8 string | ### Returns `bool`. ### Usage Example ```rust use focaccia::unicode_full_turkic_case_eq; assert!(unicode_full_turkic_case_eq("İstanbul", "istanbul")); assert!(!unicode_full_turkic_case_eq("İstanbul", "Istanbul")); assert!(unicode_full_turkic_case_eq("MASSE", "Maße")); ``` ``` -------------------------------- ### unicode_full_turkic_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using Full Unicode case folding for Turkic languages. This function handles Turkic-specific mappings where uppercase I maps to dotless ı and İ maps to plain i. ```APIDOC ## unicode_full_turkic_casecmp ### Description Compares two strings with Full Unicode case folding for Turkic languages (Turkish, Azerbaijani, …). Uses the Turkic lookup mode, where upper case `I` maps to dotless `ı` (U+0131) and `İ` (U+0130) maps to plain `i`. Structurally identical to `unicode_full_casecmp`, with `Mode::Turkic` in both the prefix comparison and the scalar lookup. ### Parameters | Parameter | Type | Required | Default | Description | |---|---|---|---|---| | `left` | `&str` | yes | — | Left-hand UTF-8 string | | `right` | `&str` | yes | — | Right-hand UTF-8 string | ### Returns `Ordering`. ### Usage Example ```rust use core::cmp::Ordering; use focaccia::unicode_full_turkic_casecmp; assert_eq!(unicode_full_turkic_casecmp("İstanbul", "istanbul"), Ordering::Equal); assert_ne!(unicode_full_turkic_casecmp("İstanbul", "Istanbul"), Ordering::Equal); // Largely compatible with full folding: assert_eq!(unicode_full_turkic_casecmp("MASSE", "Maße"), Ordering::Equal); ``` ``` -------------------------------- ### CaseFold::new usage Source: https://github.com/artichoke/focaccia Creates a const CaseFold and verifies case equality for full folding. ```rust use focaccia::CaseFold; 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")); ``` -------------------------------- ### unicode_full_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using full Unicode case folding, returning an Ordering. This function is infallible and always returns a value. ```APIDOC ## unicode_full_casecmp ### Description Compares two strings with full Unicode case folding. This function is infallible and always returns a value. ### Parameters #### Parameters - **left** (`&str`) - Required - Left-hand string - **right** (`&str`) - Required - Right-hand string ### Returns `Ordering` — `Ordering::Less`/`Equal`/`Greater`. ### Usage No usage example provided in the source. ``` -------------------------------- ### CaseFold::case_eq_chars signature Source: https://github.com/artichoke/focaccia Tests two caller-decoded Unicode scalar iterators for case-folded equality. ```rust #[must_use] pub fn case_eq_chars(self, left: L, right: R) -> bool where L: IntoIterator, R: IntoIterator, ``` -------------------------------- ### unicode_full_turkic_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using full Unicode case folding with Turkic-specific rules, returning an Ordering. This function is infallible and always returns a value. ```APIDOC ## unicode_full_turkic_casecmp ### Description Compares two strings with full Unicode case folding, including Turkic-specific rules. This function is infallible and always returns a value. ### Parameters #### Parameters - **left** (`&str`) - Required - Left-hand string - **right** (`&str`) - Required - Right-hand string ### Returns `Ordering` — `Ordering::Less`/`Equal`/`Greater`. ### Usage No usage example provided in the source. ``` -------------------------------- ### Usage of NoSuchCaseFoldingScheme::new Source: https://github.com/artichoke/focaccia Shows constructing a `const` error value and asserting it equals the default. Requires importing `focaccia::NoSuchCaseFoldingScheme`. ```rust use focaccia::NoSuchCaseFoldingScheme; const ERR: NoSuchCaseFoldingScheme = NoSuchCaseFoldingScheme::new(); assert_eq!(ERR, NoSuchCaseFoldingScheme::default()); ``` -------------------------------- ### Generic error handling with Box Source: https://github.com/artichoke/focaccia Shows boxing the error as `Box` in a `Result` return. Asserts successful resolution for `Some(b"ascii")` and error for `Some(b"nope")`. ```rust use core::convert::TryFrom; use focaccia::CaseFold; fn resolve(value: Option<&[u8]>) -> Result> { Ok(CaseFold::try_from(value)?) } assert!(matches!(resolve(Some(b"ascii")), Ok(CaseFold::Ascii))); assert!(resolve(Some(b"nope")).is_err()); ``` -------------------------------- ### Mapping::len signature Source: https://github.com/artichoke/focaccia Returns the number of scalars in the mapping: 0 for Empty, 1 for Single, 2 for Double, 3 for Triple. ```rust #[inline] #[must_use] pub fn len(&self) -> usize ``` -------------------------------- ### unicode_full_case_eq function signature Source: https://github.com/artichoke/focaccia Signature for checking equality with Full Unicode case folding. Returns a boolean. ```rust #[inline] #[must_use] pub fn case_eq(left: &str, right: &str) -> bool ``` -------------------------------- ### Turkic case folding with CaseFold::Turkic Source: https://github.com/artichoke/focaccia/blob/trunk/README.md Performs case-insensitive comparisons with additional mappings for dotted and dotless I. Shows equality and inequality for Turkish characters. ```rust use core::cmp::Ordering; use focaccia::CaseFold; 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")); ``` -------------------------------- ### ascii_case_eq function signature Source: https://github.com/artichoke/focaccia Signature for the ASCII case-insensitive equality function. It is #[inline] #[must_use] and infallible, returning bool. Implemented with eq_ignore_ascii_case. ```rust #[inline] #[must_use] pub fn case_eq(left: &[u8], right: &[u8]) -> bool ``` -------------------------------- ### ASCII case folding with CaseFold::Ascii Source: https://github.com/artichoke/focaccia/blob/trunk/README.md Performs case-insensitive comparisons for ASCII text, offering better performance. Shows equality and ordering for ASCII strings. ```rust use core::cmp::Ordering; use focaccia::CaseFold; 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")); ``` -------------------------------- ### Handling error from strategy resolution Source: https://github.com/artichoke/focaccia Matches on `CaseFold::try_from(Some("xxx"))` and falls back to `CaseFold::Full` on error, printing the error. Asserts the fallback works with `case_eq`. ```rust use core::convert::TryFrom; use focaccia::CaseFold; let fold = match CaseFold::try_from(Some("xxx")) { Ok(fold) => fold, Err(err) => { eprintln!("unable to resolve folding scheme: {err}"); CaseFold::Full // fall back to the default strategy } }; assert!(fold.case_eq("MASSE", "Maße")); ``` -------------------------------- ### unicode_full_lithuanian_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using Ruby-compatible Lithuanian case folding with full Unicode case folding. This function does not apply context-dependent Lithuanian mappings or Unicode normalization. ```APIDOC ## unicode_full_lithuanian_casecmp ### Description Compares two strings using Ruby-compatible Lithuanian case folding with full Unicode case folding. This function does not apply context-dependent Lithuanian mappings or Unicode normalization. ### Parameters - `left` (&str) - Required - Left-hand UTF-8 string - `right` (&str) - Required - Right-hand UTF-8 string ### Returns `Ordering` ### Usage Example ```rust use core::cmp::Ordering; use focaccia::unicode_full_lithuanian_casecmp; assert_eq!(unicode_full_lithuanian_casecmp("I\u{301}", "i\u{301}"), Ordering::Equal); assert_eq!(unicode_full_lithuanian_casecmp("I\u{301}", "i\u{307}\u{301}"), Ordering::Less); ``` ``` -------------------------------- ### CaseFold::casecmp_chars usage with chars Source: https://github.com/artichoke/focaccia Compares a string's chars with an array of chars, expecting Ordering::Equal. ```rust use core::cmp::Ordering; use focaccia::CaseFold; assert_eq!( CaseFold::Full.casecmp_chars("Maße".chars(), ['M', 'A', 'S', 'S', 'E']), Ordering::Equal ); ``` -------------------------------- ### unicode_full_lithuanian_casecmp Source: https://github.com/artichoke/focaccia Compares two strings using full Unicode case folding with Lithuanian-specific rules, returning an Ordering. This function is infallible and always returns a value. ```APIDOC ## unicode_full_lithuanian_casecmp ### Description Compares two strings with full Unicode case folding, including Lithuanian-specific rules. This function is infallible and always returns a value. ### Parameters #### Parameters - **left** (`&str`) - Required - Left-hand string - **right** (`&str`) - Required - Right-hand string ### Returns `Ordering` — `Ordering::Less`/`Equal`/`Greater`. ### Usage No usage example provided in the source. ``` -------------------------------- ### unicode_full_case_eq Source: https://github.com/artichoke/focaccia Checks two strings for equality with Full Unicode case folding. It adds fast paths for ASCII inputs and returns whether the folded scalar iterators are equal. ```APIDOC ## `unicode_full_case_eq` ### Description Check two strings for equality with Full Unicode case folding. Adds two fast paths over `casecmp`: an early ASCII first-byte mismatch check, and — when both inputs are entirely ASCII — a direct `left.eq_ignore_ascii_case(right)` call; otherwise it returns whether the folded scalar iterators are equal. ### Signature ```rust pub fn case_eq(left: &str, right: &str) -> bool ``` ### Parameters - `left` (`&str`) - Required - Left-hand UTF-8 string - `right` (`&str`) - Required - Right-hand UTF-8 string ### Returns `bool` ### Usage ```rust use focaccia::unicode_full_case_eq; assert!(unicode_full_case_eq("MASSE", "Maße")); assert!(!unicode_full_case_eq("São Paulo", "Sao Paulo")); assert!(unicode_full_case_eq("aBcDeF", "abcdef")); // pure ASCII fast path assert!(!unicode_full_case_eq("abcdef", "abcde")); // length mismatch assert!(unicode_full_case_eq("", "")); // empty strings are equal ``` ``` -------------------------------- ### Iter struct and iterator impls Source: https://github.com/artichoke/focaccia The state-machine iterator over a Mapping. It reports exact size_hint bounds and implements ExactSizeIterator and FusedIterator. ```rust #[derive(Debug)] pub struct Iter(Mapping); impl Iterator for Iter { type Item = u32; // next(): drains the Mapping step by step (Empty -> None, Single -> one value, ...) // size_hint(): exact via Mapping::len // count(self) -> usize: exact via Mapping::len } impl ExactSizeIterator for Iter {} impl FusedIterator for Iter {} ``` -------------------------------- ### unicode_full_turkic_case_eq Source: https://github.com/artichoke/focaccia Checks two strings for equality using full Unicode case folding with Turkic-specific rules. This function is infallible and always returns a boolean. ```APIDOC ## unicode_full_turkic_case_eq ### Description Check two strings for equality with full Unicode case folding, including Turkic-specific rules. This function is infallible and always returns a boolean. ### Parameters #### Parameters - **left** (`&str`) - Required - Left-hand string - **right** (`&str`) - Required - Right-hand string ### Returns `bool` — `true` iff the strings are equal ignoring case. ### Usage No usage example provided in the source. ``` -------------------------------- ### NoSuchCaseFoldingScheme Source: https://github.com/artichoke/focaccia Error struct implementing core::error::Error. Returned when an invalid case folding scheme is requested. ```APIDOC ## NoSuchCaseFoldingScheme ### Description Error struct implementing core::error::Error. Returned when an invalid case folding scheme is requested. ### Implements - `core::error::Error` ``` -------------------------------- ### Root re-export block Source: https://github.com/artichoke/focaccia Re-exports the case folding functions from the folding module at the crate root. ```rust pub use folding::{ ascii_case_eq, ascii_casecmp, unicode_full_case_eq, unicode_full_casecmp, unicode_full_lithuanian_case_eq, unicode_full_lithuanian_casecmp, unicode_full_turkic_case_eq, unicode_full_turkic_casecmp, }; ``` -------------------------------- ### ascii_case_eq Source: https://github.com/artichoke/focaccia Checks two byte strings for equality using ASCII case folding. This function is infallible and always returns a boolean. ```APIDOC ## ascii_case_eq ### Description Check two byte strings for equality with ASCII case folding. Implemented with `left.eq_ignore_ascii_case(right)` from Rust `core`. ### Parameters #### Parameters - **left** (`&[u8]`) - Required - Left-hand byte string - **right** (`&[u8]`) - Required - Right-hand byte string ### Returns `bool` — `true` iff the byte strings are equal ignoring ASCII case. ### Usage ```rust use focaccia::ascii_case_eq; assert!(ascii_case_eq(b"Artichoke Ruby", b"artichoke ruby")); assert!(!ascii_case_eq(b"artichoke ruby", b"Artichoke")); // different lengths assert!(ascii_case_eq(b"\u{FFFD}".as_bytes(), "\u{FFFD}".as_bytes())); // U+FFFD unchanged ``` ``` -------------------------------- ### Module declarations at crate root Source: https://github.com/artichoke/focaccia Declares the private folding module and the doc-only unicode_terms module at the crate root. ```rust mod folding; // private implementation module, line 110 pub mod unicode_terms {} // doc-only module carrying the Unicode License v3 text, line 127 ``` -------------------------------- ### unicode_full_case_eq Source: https://github.com/artichoke/focaccia Checks two strings for equality using full Unicode case folding. This function is infallible and always returns a boolean. ```APIDOC ## unicode_full_case_eq ### Description Check two strings for equality with full Unicode case folding. This function is infallible and always returns a boolean. ### Parameters #### Parameters - **left** (`&str`) - Required - Left-hand string - **right** (`&str`) - Required - Right-hand string ### Returns `bool` — `true` iff the strings are equal ignoring case. ### Usage No usage example provided in the source. ```