diff --git a/build.rs b/build.rs index 83d163e..1dc33cb 100644 --- a/build.rs +++ b/build.rs @@ -82,24 +82,7 @@ fn main() { let chars_array = format!( "const VALID_EXTRA_CHARS: [char; {}] = {};", filtered_chars.len(), - [ - "[", - &filtered_chars - .iter() - .map(|c| format!("'{}'", c.escape_unicode())) - .enumerate() - .map(|(i, x)| { - // Add comma and space if needed - match filtered_chars.len() > i + 1 { - true => x + ", ", - false => x, - } - }) - .collect::>() - .concat(), - "]", - ] - .concat() + to_chars_array(filtered_chars), ); let path = Path::new(&env::var("OUT_DIR").unwrap()).join("valid_chars.rs"); let mut file = BufWriter::new(File::create(&path).expect("Could not save compressed_data")); diff --git a/src/lib.rs b/src/lib.rs index 9bdbf05..0f73bcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ pub use crate::{ step_helper, EguiHelper, }, - unicode_helper::to_unicode_hash, + unicode_helper::{to_chars_array, to_unicode_hash}, }; cfg_if::cfg_if! { diff --git a/src/unicode_helper.rs b/src/unicode_helper.rs index a49caea..e5a2dea 100644 --- a/src/unicode_helper.rs +++ b/src/unicode_helper.rs @@ -7,3 +7,25 @@ pub fn to_unicode_hash(c: char) -> String { .replace('}', "") .to_uppercase() } + +#[allow(dead_code)] +pub fn to_chars_array(chars: Vec) -> String { + [ + "[", + &chars + .iter() + .map(|c| format!("'{}'", c.escape_unicode())) + .enumerate() + .map(|(i, x)| { + // Add comma and space if needed + match chars.len() > i + 1 { + true => x + ", ", + false => x, + } + }) + .collect::>() + .concat(), + "]", + ] + .concat() +} diff --git a/tests/misc.rs b/tests/misc.rs index 7be3862..c8a5323 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -201,3 +201,12 @@ fn to_unicode_hash() { use ytbn_graphing_software::to_unicode_hash; assert_eq!(to_unicode_hash('\u{1f31e}'), "\\U1F31E"); } + +#[test] +fn to_chars_array() { + use ytbn_graphing_software::to_chars_array; + assert_eq!( + to_chars_array(vec!['\u{1f31e}', '\u{2d12c}']), + r#"['\u{1f31e}', '\u{2d12c}']"# + ); +}