Skip to main content

Crate roe

Crate roe 

Source
Expand description

This crate provides Unicode case mapping routines and iterators for conventionally UTF-8 binary strings.

Unicode case mapping or case conversion can be used to transform the characters in a string. To quote the Unicode FAQ:

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 supports full Unicode, Turkic, and ASCII lowercase, uppercase, and capitalization and swapcase mappings. Full Unicode case folding is available through LowercaseMode::Fold. Invalid UTF-8 is preserved.

Mappings use bundled Unicode 18.0.0 tables, independent of the Rust compiler. Like MRI Ruby, mappings are context-independent and Lithuanian mode is an alias for full Unicode mapping. The API is still evolving ahead of 1.0.

§Usage

You can convert case like:

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 provides fast path routines that assume the byte slice is ASCII-only.

To detect a change without allocating, compare the mapped byte iterator with the original bytes:

let input = b"artichoke";
assert!(lowercase(input, LowercaseMode::Full).eq(input.iter().copied()));

§Crate Features

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.

Modules§

ruby
Case mapping with Ruby string semantics.
unicode_termsdoc
Roe is derived from Unicode Data Files and is subject to Unicode License v3.

Structs§

InvalidCaseMappingMode
Error that indicates a failure to parse a LowercaseMode, UppercaseMode, SwapcaseMode, or ruby::CapitalizeMode.
Lowercase
An iterator that yields the lowercase equivalent of a conventionally UTF-8 byte string.
Swapcase
An iterator yielding bytes with the case of each character swapped.
Uppercase
An iterator that yields the uppercase equivalent of a conventionally UTF-8 byte string.

Enums§

LowercaseMode
Options to configure the behavior of lowercase.
SwapcaseMode
Options to configure the behavior of swapcase.
UppercaseMode
Options to configure the behavior of uppercase.

Constants§

UNICODE_VERSION
The bundled Unicode case mapping version as (major, minor, patch).

Functions§

lowercase
Returns an iterator that yields a copy of the bytes in the given slice with all uppercase letters replaced with their lowercase counterparts.
make_ascii_lowercase
Converts the given slice to its ASCII lower case equivalent in-place.
make_ascii_swapcase
Swap the case of ASCII letters in-place, preserving all other bytes.
make_ascii_uppercase
Converts the given slice to its ASCII upper case equivalent in-place.
swapcase
Returns an iterator that yields a copy of the bytes in the given slice with the case of each character swapped.
to_ascii_lowercasealloc
Returns a vector containing a copy of the given slice where each byte is mapped to its ASCII lower case equivalent.
to_ascii_swapcasealloc
Return a copy with ASCII letters case-swapped and all other bytes preserved.
to_ascii_uppercasealloc
Returns a vector containing a copy of the given slice where each byte is mapped to its ASCII upper case equivalent.
to_titlecase
Take a char and return its Unicode titlecase as 3 chars.
try_to_lowercasealloc
Fallibly lowercase a byte string, borrowing it when no bytes change.
try_to_swapcasealloc
Fallibly swap the case of a byte string, borrowing it when no bytes change.
try_to_uppercasealloc
Fallibly uppercase a byte string, borrowing it when no bytes change.
uppercase
Returns an iterator that yields a copy of the bytes in the given slice with all lowercase letters replaced with their uppercase counterparts.