Implements Unicode case mapping for conventionally UTF-8 binary strings.
Case mapping or case conversion is a process whereby strings are converted to a particular form—uppercase, lowercase, or titlecase—possibly for display to the user.
roe can convert conventionally UTF-8 binary strings to capitalized, lowercase,
and uppercase forms. This crate is used to implement String#capitalize,
Symbol#capitalize, String#downcase, Symbol#downcase,
String#upcase, Symbol#upcase, String#swapcase, and
Symbol#swapcase in Artichoke Ruby.
This crate depends on bstr.
Roe generates conversion tables from Unicode Data Files. Roe implements case
mapping as defined in the Unicode standard (see PropList.txt,
SpecialCasing.txt, UnicodeData.txt, CaseFolding.txt).
Roe supports full Unicode, Turkic, and ASCII lowercase, uppercase, and
capitalization and swapcase mappings for conventionally UTF-8 byte slices. Full
Unicode case folding is available through LowercaseMode::Fold. Invalid UTF-8
is preserved.
Like MRI Ruby, mappings are context-independent and Lithuanian mode currently uses the full Unicode mappings. All Unicode mappings use bundled tables rather than the Rust compiler's Unicode version.
The API is still evolving ahead of a 1.0 release.
Add this to your Cargo.toml:
[dependencies]
roe = "0.0.11"Then convert case like:
use roe::ruby::{CapitalizeMode, capitalize};
use roe::{LowercaseMode, UppercaseMode};
assert_eq!(
roe::lowercase(b"Artichoke Ruby", LowercaseMode::Ascii).collect::<Vec<_>>(),
b"artichoke ruby"
);
assert_eq!(
roe::uppercase("Αύριο".as_bytes(), UppercaseMode::Full).collect::<Vec<_>>(),
"ΑΎΡΙΟ".as_bytes()
);
assert_eq!(
capitalize("ffi".as_bytes(), CapitalizeMode::Full).collect::<Vec<_>>(),
"Ffi".as_bytes()
);roe is no_std compatible with an optional dependency on the alloc crate.
The alloc feature is enabled by default and provides APIs that allocate
String or Vec. Disable default features to use Roe without allocation.
This crate requires at least Rust 1.85.0. This version can be bumped in minor releases.
Roe implements Unicode case mapping with the Unicode 18.0.0 case mapping ruleset.
Each new release of Unicode may bring updates to the Data Files which are the source for the case mappings in this crate. Updates to the case mapping rules will be accompanied with a minor version bump.
roe is licensed under the MIT License (c) Ryan Lopopolo.
roe includes Unicode Data Files which are subject to the Unicode Terms of
Use and Unicode License v3 (c) Unicode, Inc.