30 releases

new 0.8.0 Nov 23, 2024
0.7.6 May 28, 2024
0.7.5 Nov 16, 2023
0.7.1 Jan 26, 2023
0.3.2 Oct 28, 2019

#19 in Data structures

Download history 161334/week @ 2024-08-03 152639/week @ 2024-08-10 152835/week @ 2024-08-17 165937/week @ 2024-08-24 172373/week @ 2024-08-31 168025/week @ 2024-09-07 166922/week @ 2024-09-14 213533/week @ 2024-09-21 214536/week @ 2024-09-28 208184/week @ 2024-10-05 209829/week @ 2024-10-12 211772/week @ 2024-10-19 190444/week @ 2024-10-26 695376/week @ 2024-11-02 916683/week @ 2024-11-09 815193/week @ 2024-11-16

2,651,779 downloads per month
Used in 28,221 crates (38 directly)

Unicode-3.0

215KB
4K SLoC

tinystr crates.io

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.

Examples

use tinystr::TinyAsciiStr;

let s1: TinyAsciiStr<4> = "tEsT".parse().expect("Failed to parse.");

assert_eq!(s1, "tEsT");
assert_eq!(s1.to_ascii_uppercase(), "TEST");
assert_eq!(s1.to_ascii_lowercase(), "test");
assert_eq!(s1.to_ascii_titlecase(), "Test");
assert!(s1.is_ascii_alphanumeric());
assert!(!s1.is_ascii_numeric());

let s2 = TinyAsciiStr::<8>::try_from_raw(*b"New York")
    .expect("Failed to parse.");

assert_eq!(s2, "New York");
assert_eq!(s2.to_ascii_uppercase(), "NEW YORK");
assert_eq!(s2.to_ascii_lowercase(), "new york");
assert_eq!(s2.to_ascii_titlecase(), "New york");
assert!(!s2.is_ascii_alphanumeric());

Details

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.

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~235–740KB
~18K SLoC