//Buffers for improved performance (avoid repeated heap allocations)
letmutstarting_consonants_buffer=String::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
forcharacterinenglish.chars().peekable(){
forcharacterinenglish.chars(){
ifin_word{
ifcharacter.is_alphabetic(){
//Save the character to translate once the word ends; we also keep apostrophes so that translate_word_with_style can handle contractions
//As a herustic, we consider Y to be a vowel when it is not at the start of the word
//However, if any word is only one letter long, this takes priority and the word is treated like a vowel
letfirst_letter_was_vowel: bool={
is_vowel(first_letter)//Not including y
||ifletSome(character)=iterator.peek(){!character.is_alphabetic()}else{true}//Non-alphabetic character after the first letter, or the word ends after the first letter
};
letfirst_letter_was_vowel: bool=is_vowel(first_letter);//Not including y
//Clear the starting_consonants buffer we were given
//As a herustic, we consider Y to be a vowel when it is not at the start of the word
//However, if any word is only one letter long, this takes priority and the word is treated like a vowel
letfirst_letter_was_vowel: bool={
is_vowel(first_letter)//Not including y
||ifletSome(character)=iterator.peek(){!character.is_alphabetic()}else{true}//Non-alphabetic character after the first letter, or the word ends after the first letter
};
letfirst_letter_was_vowel: bool=is_vowel(first_letter);//Not including y
//Clear the starting_consonants buffer we were given