<commit_before>#include "PigLatinTranslator.hpp"

PigLatinTranslator::PigLatinTranslator(){
  vowels = "aeiouyAEIOUY";
  punctuation = ".,!?:;()[]{}<>`´\'\"";
}

std::string PigLatinTranslator::translate(const std::string& text) const{

  if( text.empty() ) {
    return "";
  }

  std::vector<std::string> punct_sep_str = separate_punctuation(text);

  std::string transl_word = translate_word(punct_sep_str[1]);

  return punct_sep_str[0] + transl_word + punct_sep_str[2];
}


std::string PigLatinTranslator::translate_word(const std::string& word) const{

  if( word.empty() ) {
    return "";
  }

  std::string translation = word;

  bool isCapitalFirst = is_upper_case(translation[0]);
  if( isCapitalFirst && !is_all_upper_case(translation) ) {
    translation[0] = to_lower_case(translation[0]);
  }

  // Take care of the case when the first letter is a vowel
  int vowelIndex = vowels.find(translation[0]);
  bool isVowel = vowelIndex >= 0 && translation[0] != 'y';
  if( isVowel ) {
    if( isCapitalFirst && !is_upper_case(translation[0]) ) {
      translation[0] = to_upper_case(translation[0]);
    }
    return translation + "way";
  }

  int translationIndex = 1;
  vowelIndex = -1;
  do {
    vowelIndex = vowels.find(translation[translationIndex]);
    translationIndex++;
  } while( translationIndex < translation.size() && vowelIndex < 0 );

  // If The word does not contain any vowels
  if( translationIndex == translation.size() ) {
    if( isCapitalFirst && !is_upper_case(translation[0]) ) {
      translation[0] = to_upper_case(translation[0]);
    }
    return translation + "ay";
  }

  // If The word contain vowels
  translation = translation.substr(translationIndex-1) + translation.substr(0,translationIndex-1);
  if( isCapitalFirst && !is_upper_case(translation[0]) ) {
    translation[0] = to_upper_case(translation[0]);
  }<commit_msg>Fixed words ending with only vowel #17<commit_after>#include "PigLatinTranslator.hpp"

PigLatinTranslator::PigLatinTranslator(){
  vowels = "aeiouyAEIOUY";
  punctuation = ".,!?:;()[]{}<>`´\'\"";
}

std::string PigLatinTranslator::translate(const std::string& text) const{

  if( text.empty() ) {
    return "";
  }

  std::vector<std::string> punct_sep_str = separate_punctuation(text);

  std::string transl_word = translate_word(punct_sep_str[1]);

  return punct_sep_str[0] + transl_word + punct_sep_str[2];
}


std::string PigLatinTranslator::translate_word(const std::string& word) const{

  if( word.empty() ) {
    return "";
  }

  std::string translation = word;

  bool isCapitalFirst = is_upper_case(translation[0]);
  if( isCapitalFirst && !is_all_upper_case(translation) ) {
    translation[0] = to_lower_case(translation[0]);
  }

  // Take care of the case when the first letter is a vowel
  int vowelIndex = vowels.find(translation[0]);
  bool isVowel = vowelIndex >= 0 && translation[0] != 'y';
  if( isVowel ) {
    if( isCapitalFirst && !is_upper_case(translation[0]) ) {
      translation[0] = to_upper_case(translation[0]);
    }
    return translation + "way";
  }

  int translationIndex = 1;
  vowelIndex = -1;
  do {
    vowelIndex = vowels.find(translation[translationIndex]);
    translationIndex++;
  } while( translationIndex < translation.size() && vowelIndex < 0 );

  // If The word does not contain any vowels
  if( translationIndex == translation.size() && vowelIndex < 0 ) {
    if( isCapitalFirst && !is_upper_case(translation[0]) ) {
      translation[0] = to_upper_case(translation[0]);
    }
    return translation + "ay";
  }

  // If The word contain vowels
  translation = translation.substr(translationIndex-1) + translation.substr(0,translationIndex-1);
  if( isCapitalFirst && !is_upper_case(translation[0]) ) {
    translation[0] = to_upper_case(translation[0]);
  }
{'fraction_non_alphanumeric': 0.14697330161247688, 'fraction_numerical': 0.013481363996827915, 'mean_word_length': 4.476121562952243, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3278366', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1269, 'n_words': 250}