58 #ifndef ANSLATORTRAY_HPP 59 #define ANSLATORTRAY_HPP 61 #if __cplusplus >= 201103L//supports C++11 and later for now 73 #define ANSLATORTRAY_VERSION 0.3.3 107 inline std::string
smartWordToPig(
const std::string &englishWord);
116 inline std::string
translate(
const std::string &englishText);
126 inline std::string
wordToPig(
const std::string &englishWord);
128 #ifndef ANSLATORTRAY_TINY_TRANSLATOR 137 inline std::string
wordsToPig(
const std::string &englishWords);
140 #ifndef ANSLATORTRAY_TINY_TRANSLATOR 150 inline std::string
attemptWordToEnglish(
const std::string &pig, std::uint64_t numBeginningConosoants = 1);
162 constexpr
char ALL[] {
"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"};
167 #ifndef ANSLATORTRAY_TINY_TRANSLATOR 171 constexpr
char Y[] {
"yY"};
189 inline std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word));
202 if (wordEndIndex == std::string::npos)
207 #ifndef ANSLATORTRAY_SKIP_SANITY_CHECKS 208 if (wordStartIndex == std::string::npos || wordEndIndex == std::string::npos)
214 std::string actualWord {englishWord.substr(wordStartIndex, wordEndIndex - wordStartIndex)};
219 #ifndef ANSLATORTRAY_IGNORE_CAPS 220 if (std::all_of(std::begin(actualWord), std::end(actualWord), isupper) && actualWord !=
"I")
221 std::transform(std::begin(pig), std::end(pig), std::begin(pig), toupper);
224 std::transform(std::begin(pig), std::end(pig), std::begin(pig), tolower);
226 if (std::isupper(actualWord[0]))
227 pig[0] = {
static_cast<char> (std::toupper(pig[0]))};
232 std::string result {englishWord.substr(0, wordStartIndex)};
234 result += {englishWord.substr(wordEndIndex)};
247 #ifndef ANSLATORTRAY_SKIP_SANITY_CHECKS 248 if (firstVowel == std::string::npos)
258 std::string result {englishWord.substr(firstVowel)};
259 result += {englishWord.substr(0, firstVowel)};
266 #ifndef ANSLATORTRAY_TINY_TRANSLATOR 273 #ifndef ANSLATORTRAY_TINY_TRANSLATOR 276 std::string noAy {pig.substr(0, pig.size() - 2)};
278 std::string withoutBeginningConosoants {noAy.substr(0, noAy.size() - numBeginningConosoants)};
279 std::string beginningConosoants {noAy.substr(noAy.size() - numBeginningConosoants)};
281 return beginningConosoants + withoutBeginningConosoants;
285 std::string
changeWords(
const std::string &words, std::string wordChanger (
const std::string &word))
287 std::string newWords {};
293 while (tokenStartIndex != std::string::npos)
296 if (tokenEndIndex == std::string::npos)
297 word = {words.substr(tokenStartIndex)};
299 word = {words.substr(tokenStartIndex, tokenEndIndex - tokenStartIndex)};
303 newWords += {wordChanger(word)};
320 #error Sorry, but for the moment, Anslatortray only supports for C++11 and later. For now, please change your compiliation flags accordinaly 323 #endif //ANSLATORTRAY_HPP constexpr char WHITESPACE[]
Array containing diffrent types of whitespace (internal use)
Definition: anslatortray.hpp:178
constexpr char ALL[]
Array containing all upper and lower case letters (internal use)
Definition: anslatortray.hpp:162
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:267
constexpr char VOWELS_WITH_Y[]
Array containing all upper and lower case vowels (including y) (internal use)
Definition: anslatortray.hpp:169
std::string wordToPig(const std::string &englishWord)
Translates a single English word to Pig Latin.
Definition: anslatortray.hpp:243
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:285
constexpr char Y[]
Array containing upper and lower case y (internal use)
Definition: anslatortray.hpp:171
std::string smartWordToPig(const std::string &englishWord)
Translates a single complex English word to Pig Latin. (more robust)
Definition: anslatortray.hpp:196
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:165
constexpr char VOWEL_START_STYLE[]
Ending to use if word to translate starts with a vowel.
Definition: anslatortray.hpp:95
constexpr char APOSTROPHE[]
Array containing diffrent apostrophes (internal use)
Definition: anslatortray.hpp:176
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:274
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:238