Commit 4d9a89de authored by John Zacarias Jekel's avatar John Zacarias Jekel
Browse files

Add another helper function

parent 9ebeb071
Loading
Loading
Loading
Loading

src/.helpers.rs.kate-swp

deleted100644 → 0
−68 B

File deleted.

+12 −0
Original line number Diff line number Diff line
@@ -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)]
+1 −0
Original line number Diff line number Diff line
@@ -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 */

+3 −0
Original line number Diff line number Diff line
@@ -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(),