unicode_clusters

Crates.iounicode_clusters
lib.rsunicode_clusters
version0.1.2
sourcesrc
created_at2021-12-09 16:47:45.582713
updated_at2021-12-09 22:26:44.220955
descriptionThis crate provides variable width unicode characters as single items, allowing for array like indexing etc.
homepage
repositoryhttps://github.com/FigmentEngine/unicode_clusters
max_upload_size
id495250
size8,977
Fitz (FigmentEngine)

documentation

README

Unicode Clusters

Unicode Clusters is a library that support variable width unicode characters as single items, allowing for array like indexing etc.

#[test]
fn example() {
	let input = "AȜनमस्ते";

	let gcs = GraphemeCluster::graphemes(input);
	assert!(gcs.len() == 6, "length");

	assert_eq!(gcs[0].as_string(), "A");

	assert_eq!(gcs[1].as_string(), "Ȝ");
	assert_eq!(gcs[2].as_string(), "न");
	assert_eq!(gcs[3].as_string(), "म");
	assert_eq!(gcs[4].as_string(), "स्");
	assert_eq!(gcs[5].as_string(), "ते");

	assert_eq!(gcs[0].as_bytes()[..], [65]);
	assert_eq!(gcs[1].as_bytes()[..], [200, 156]);
	assert_eq!(gcs[2].as_bytes()[..], [224, 164, 168]);
	assert_eq!(gcs[3].as_bytes()[..], [224, 164, 174]);
	assert_eq!(gcs[4].as_bytes()[..], [224, 164, 184,	224, 165, 141]);
	assert_eq!(gcs[5].as_bytes()[..], [224, 164, 164,	224, 165, 135]);
}
Commit count: 11

cargo fmt