use once_cell::sync::Lazy;
use std::collections::HashMap;
use super::custom_graphemes::create_non_standard;
pub static GRAPHEMES: Lazy<HashMap<u16, [u8; 4]>> = Lazy::new(create_graphemes);
fn create_graphemes() -> HashMap<u16, [u8; 4]> {
if cfg!(feature = "custom_graphemes") {
match create_non_standard() {
Ok(g) => g,
Err(e) => {
println!("{e}");
println!("Could not create custom graphemes. Creating standard graphemes");
create_standard_graphemes()
}
}
} else {
create_standard_graphemes()
}
}
fn create_standard_graphemes() -> HashMap<u16, [u8; 4]> {
let mut ind_base10 = 0;
let mut graphemes = HashMap::new();
for i in 48..=57 {
graphemes.insert(ind_base10, [0, 0, 0, i]);
ind_base10 += 1;
}
for i in 65..=90 {
graphemes.insert(ind_base10, [0, 0, 0, i]);
ind_base10 += 1;
}
for i in 194..=223 {
for j in 128..=191 {
graphemes.insert(ind_base10, [0, 0, i, j]);
ind_base10 += 1;
}
}
for i in 160..=191 {
for j in 128..=191 {
graphemes.insert(ind_base10, [0, 224, i, j]);
ind_base10 += 1;
}
}
'out: for i in 225..=238 {
for j in 128..=191 {
for k in 128..=191 {
if (i, j, k) == (237, 160, 128) {
break 'out;
}
graphemes.insert(ind_base10, [0, i, j, k]);
ind_base10 += 1;
}
}
}
graphemes
}