Add another helper function

main
John Zacarias Jekel 1 year ago
parent 9ebeb071da
commit 4d9a89dec2
  1. BIN
      src/.helpers.rs.kate-swp
  2. 12
      src/helpers.rs
  3. 1
      src/lib.rs
  4. 3
      src/translate_words.rs

Binary file not shown.

@ -54,6 +54,18 @@ pub(crate) fn push_slice_to_vector<T: Clone>(vec: &mut Vec<T>, slice: &[T]) {
}
}
//Capitalizes an ASCII/byte string at compile time
#[cfg(feature = "nightly-features")]//Not unstable on it's own, but only needed by things enabled by nightly-features
pub(crate) const fn capitalize_ascii<const LEN: usize>(word: &[u8; LEN]) -> [u8; LEN] {
let mut capitalized = [0u8; LEN];
let mut i: usize = 0;
while i < LEN {
capitalized[i] = (word[i] as char).to_ascii_uppercase() as u8;
i += 1;
}
return capitalized;
}
/* Tests */
#[cfg(test)]

@ -74,6 +74,7 @@
//Only enabled if the relevant Cargo feature is
#![cfg_attr(feature = "nightly-features", feature(test))]
#![cfg_attr(feature = "nightly-features", feature(adt_const_params))]
#![cfg_attr(feature = "nightly-features", feature(generic_const_exprs))]
/* Imports */

@ -411,10 +411,13 @@ mod tests {
> (
english_word: &str
) -> String {
use crate::helpers::capitalize_ascii;
let mut pig_latin_word = Vec::<u8>::with_capacity(64 * 2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
let mut starting_consonants_buffer = Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
translate_word_with_style_reuse_buffers_ascii_generic::<
//Almost works, but it can't infer the length
//SUFFIX_LOWER, SPECIAL_CASE_SUFFIX_LOWER, { &capitalize_ascii(SUFFIX_LOWER.try_into().unwrap()) }, { &capitalize_ascii(SPECIAL_CASE_SUFFIX_LOWER.try_into().unwrap()) },
SUFFIX_LOWER, SPECIAL_CASE_SUFFIX_LOWER, SUFFIX_UPPER, SPECIAL_CASE_SUFFIX_UPPER,
> (
english_word.as_bytes(),

Loading…
Cancel
Save