40 #ifndef ANSLATORTRAY_HPP 41 #define ANSLATORTRAY_HPP 74 inline std::string
translate(
const std::string &englishText);
84 inline std::string
wordToPig(
const std::string &englishWord);
87 #if __cplusplus >= 201703L 88 inline std::string_view wordToPigSV(std::string_view englishWord);
98 inline std::string
wordsToPig(
const std::string &englishWords);
108 inline std::string
attemptWordToEnglish(
const std::string &pig, std::uint64_t beginningVowels = 1);
118 inline std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word));
126 constexpr
char ALL[] {
"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"};
131 constexpr
char Y[] {
"yY"};
144 if (result != std::string::npos)
147 return englishWord +
"way";
151 std::string finished {englishWord.substr(result)};
152 finished += englishWord.substr(0, result);
201 std::string::size_type wordEndIndex {englishWord.find(
'\'')};
202 if (wordEndIndex == std::string::npos)
206 std::string pig {
wordToPig(englishWord.substr(wordStartIndex, wordEndIndex - wordStartIndex))};
207 std::transform(std::begin(pig), std::end(pig), std::begin(pig), tolower);
208 if (std::isupper(englishWord.substr(wordStartIndex, wordEndIndex - wordStartIndex)[0]))
209 pig[0] = {
static_cast<char> (std::toupper(pig[0]))};
213 std::string finished {englishWord.substr(0, wordStartIndex)};
215 finished += englishWord.substr(wordEndIndex);
220 std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word))
222 std::stringstream wordStream {words};
223 std::string pigWords {
""};
227 std::string word {
""};
229 while (wordStream >> word)
231 pigWords += wordChanger(word);
257 std::string noAy {pig.substr(0, pig.size() - 2)};
259 std::string noPrefix {noAy.substr(0, noAy.size() - beginningVowels)};
260 std::string prefix {noAy.substr(noAy.size() - beginningVowels)};
262 return prefix + noPrefix;
265 #if __cplusplus >= 201703L 269 #endif // ANSLATORTRAY_H constexpr char ALL[]
Definition: anslatortray.hpp:126
std::string attemptWordToEnglish(const std::string &pig, std::uint64_t beginningVowels=1)
Tries to translate a word in pig latin back to english.
Definition: anslatortray.hpp:255
std::string wordsToPig(const std::string &englishWords)
Uses wordToPig and changeWords to perform dumb translation from English to pig latin on every word it...
Definition: anslatortray.hpp:245
constexpr char VOWELS_WITH_Y[]
Definition: anslatortray.hpp:133
std::string wordToPig(const std::string &englishWord)
Translates a single English word to pig latin.
Definition: anslatortray.hpp:140
std::string changeWords(const std::string &words, std::string wordChanger(const std::string &word))
Helper function to perform an operation on all whitespace-seperated strings given to it...
Definition: anslatortray.hpp:220
constexpr char Y[]
Definition: anslatortray.hpp:131
std::string smartWordToPig(const std::string &englishWord)
Translates a single complex English word to pig latin. (more robust)
Definition: anslatortray.hpp:197
Namespace containing functions to translate from English to Pig Latin.
constexpr char VOWELS[]
Definition: anslatortray.hpp:129
std::string translate(const std::string &englishText)
Uses smartWordToPig and changeWords to perform translation from English to pig latin on every word it...
Definition: anslatortray.hpp:250