tinystr
is a utility crate of the [ICU4X
] project.
It includes [TinyAsciiStr
], a core API for representing small ASCII-only bounded length strings.
It is optimized for operations on strings of size 8 or smaller. When use cases involve comparison
and conversion of strings for lowercase/uppercase/titlecase, or checking
numeric/alphabetic/alphanumeric, TinyAsciiStr
is the edge performance library.
```rust use tinystr::TinyAsciiStr;
let s1: TinyAsciiStr<4> = "tEsT".parse().expect("Failed to parse.");
asserteq!(s1, "tEsT"); asserteq!(s1.toasciiuppercase(), "TEST"); asserteq!(s1.toasciilowercase(), "test"); asserteq!(s1.toasciititlecase(), "Test"); asserteq!(s1.isasciialphanumeric(), true); asserteq!(s1.isasciinumeric(), false);
let s2 = TinyAsciiStr::<8>::tryfromraw(*b"New York") .expect("Failed to parse.");
asserteq!(s2, "New York"); asserteq!(s2.toasciiuppercase(), "NEW YORK"); asserteq!(s2.toasciilowercase(), "new york"); asserteq!(s2.toasciititlecase(), "New york"); asserteq!(s2.isascii_alphanumeric(), false); ```
When strings are of size 8 or smaller, the struct transforms the strings as u32
/u64
and uses
bitmasking to provide basic string manipulation operations:
* is_ascii_numeric
* is_ascii_alphabetic
* is_ascii_alphanumeric
* to_ascii_lowercase
* to_ascii_uppercase
* to_ascii_titlecase
* PartialEq
TinyAsciiStr
will fall back to u8
character manipulation for strings of length greater than 8.
For more information on development, authorship, contributing etc. please visit ICU4X home page
.