/unicode-categories

Traits and methods to extend the char type with unicode-category metadata

Primary LanguageRustApache License 2.0Apache-2.0

unicode-categories

This crate provides a method and Extension Trait on top of the char type for returning a corresponding Unicode General Category as defined in the latest standard.

Including the crate

For now the crate can be included by branch or by tag via git.

#[dependencies]
unicode-categories = { git = "https://github.com/ncatelli/unicode-categories.git", branch = "main" }

Examples

Using the char type extension trait.

use unicode_categories::*;

assert_eq!(Some(Category::Lu), 'A'.unicode_category());
assert_eq!(Some(Category::Ll), 'a'.unicode_category());

Using the included conversion method:

use unicode_categories::*;

assert_eq!(Some(Category::Lu), unicode_category_from_char('A'));
assert_eq!(Some(Category::Ll), unicode_category_from_char('a'));