58 #ifndef ANSLATORTRAY_HPP 59 #define ANSLATORTRAY_HPP 61 #define ANSLATORTRAY_VERSION 0.3.1 64 #if __cplusplus >= 201103L//supports C++11 and later for now 98 inline std::string
translate(
const std::string &englishText);
108 inline std::string
wordToPig(
const std::string &englishWord);
117 inline std::string
wordsToPig(
const std::string &englishWords);
127 inline std::string
attemptWordToEnglish(
const std::string &pig, std::uint64_t numBeginningConosoants = 1);
141 constexpr
char ALL[] {
"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"};
148 constexpr
char Y[] {
"yY"};
165 inline std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word));
178 if (wordEndIndex == std::string::npos)
183 std::string actualWord {};
184 if (wordStartIndex != std::string::npos && wordEndIndex != std::string::npos)
185 actualWord = {englishWord.substr(wordStartIndex, wordEndIndex - wordStartIndex)};
193 if (std::all_of(std::begin(actualWord), std::end(actualWord), isupper) && actualWord !=
"I")
194 std::transform(std::begin(pig), std::end(pig), std::begin(pig), toupper);
197 std::transform(std::begin(pig), std::end(pig), std::begin(pig), tolower);
199 if (std::isupper(actualWord[0]))
200 pig[0] = {
static_cast<char> (std::toupper(pig[0]))};
205 std::string result {englishWord.substr(0, wordStartIndex)};
207 result += {englishWord.substr(wordEndIndex)};
220 if (firstVowel != std::string::npos)
227 std::string result {englishWord.substr(firstVowel)};
228 result += englishWord.substr(0, firstVowel);
245 std::string noAy {pig.substr(0, pig.size() - 2)};
247 std::string withoutBeginningConosoants {noAy.substr(0, noAy.size() - numBeginningConosoants)};
248 std::string beginningConosoants {noAy.substr(noAy.size() - numBeginningConosoants)};
250 return beginningConosoants + withoutBeginningConosoants;
253 std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word))
255 std::string newWords {
""};
256 std::string word {
""};
261 while (tokenStartIndex != std::string::npos)
264 if (tokenEndIndex == std::string::npos)
265 word = {words.substr(tokenStartIndex)};
267 word = {words.substr(tokenStartIndex, tokenEndIndex)};
271 newWords += {wordChanger(word)};
288 #error Sorry, but for the moment, Anslatortray only supports for C++11 and later. For now, please change your compiliation flags accordinaly 291 #endif //ANSLATORTRAY_HPP constexpr char WHITESPACE[]
Array containing diffrent types of whitespace (internal use)
Definition: anslatortray.hpp:154
constexpr char ALL[]
Array containing all upper and lower case letters (internal use)
Definition: anslatortray.hpp:141
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:238
constexpr char VOWELS_WITH_Y[]
Array containing all upper and lower case vowels (including y) (internal use)
Definition: anslatortray.hpp:146
std::string wordToPig(const std::string &englishWord)
Translates a single English word to Pig Latin.
Definition: anslatortray.hpp:216
std::string changeWords(const std::string &words, std::string wordChanger(const std::string &word))
Helper function to perform an operation on all whitespace-seperated words (tokens) given to it...
Definition: anslatortray.hpp:253
constexpr char Y[]
Array containing upper and lower case y (internal use)
Definition: anslatortray.hpp:148
std::string smartWordToPig(const std::string &englishWord)
Translates a single complex English word to Pig Latin. (more robust)
Definition: anslatortray.hpp:172
Namespace containing functions to translate from English to Pig Latin.
constexpr char VOWELS[]
Array containing all upper and lower case vowels (except for y) (internal use)
Definition: anslatortray.hpp:144
constexpr char VOWEL_START_STYLE[]
Ending to use if word to translate starts with a vowel.
Definition: anslatortray.hpp:130
constexpr char APOSTROPHE[]
Array containing diffrent apostrophes (internal use)
Definition: anslatortray.hpp:152
std::string attemptWordToEnglish(const std::string &pig, std::uint64_t numBeginningConosoants=1)
Tries to translate a word in Pig Latin back to english.
Definition: anslatortray.hpp:243
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:211