1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
inline std::string capitalize (std::string& word) {
word[0] = std::toupper(word[0]);
return word;
}
inline bool isVowel (char letter) {
static const std::string vowels = "aeiou";
return vowels.find(letter) != std::string::npos;
}
inline std::string aAn (const std::string& word, Capitalized capital) { // capital = NonCapital by default
std::string result = isVowel(word[0]) ? "an" : "a";
return (capital == NonCapital) ? result : capitalize(result);
}
inline std::string aAn (const Entity* entity, Capitalized capital) { // capital = NonCapital by default
return aAn (entity->getName(), capital);
}
inline std::string numToWord (int num, Capitalized capital) { // capital = NonCapital by default
std::string result;
switch (num) {
case 1 : result = "one"; break;
case 2 : result = "two"; break;
case 3 : result = "three"; break;
case 4 : result = "four"; break;
case 5 : result = "five"; break;
case 6 : result = "six"; break;
case 7 : result = "seven"; break;
case 8 : result = "eight"; break;
case 9 : result = "nine"; break;
case 10 : result = "ten"; break;
case 11 : result = "eleven"; break;
case 12 : result = "twelve"; break;
default : return toString(num);
}
return (capital == NonCapital) ? result : capitalize(result);
}
inline std::string ordinal (int num, Capitalized capital) { // capital = NonCapital by default
std::string result;
switch (num) {
case 1 : result = "first"; break;
case 2 : result = "second"; break;
case 3 : result = "third"; break;
case 4 : result = "fourth"; break;
case 5 : result = "fifth"; break;
case 6 : result = "sixth"; break;
case 7 : result = "seventh"; break;
case 8 : result = "eighth"; break;
case 9 : result = "ninth"; break;
case 10 : result = "tenth"; break;
case 11 : result = "eleventh"; break;
case 12 : result = "twelfth"; break;
default : result = toString(num) + "th";
}
return (capital == NonCapital) ? result : capitalize(result);
}
inline std::string firstWord (const std::string& str) {
std::string word;
std::stringstream ss(str);
ss >> word;
return word;
}
inline std::string plural (const std::string& word) {
switch (word[word.length()-1]) {
case 'x': case 'h': case 's': return word + "es";
case 'y': {
const std::size_t secondLast = word.length() - 2;
const char secondLastLetter = word.at(secondLast);
if (isVowel (secondLastLetter))
return word + "s";
return word.substr (0, secondLast) + "ies";
}
default: return word + "s";
}
}
template <typename T> // T = int by default
inline std::string plural (T num, const std::string& word) {
return (num == 1) ? word : plural(word);
}
template <typename T> // T = int by default
inline std::string numObjects (T num, const std::string& object, NumberType numberType) { // numberType = NumAsNum by default
return (numberType == NumAsNum) ? toString(num) + " " + plural(num, object) : numToWord(num) + " " + plural(num, object);
}
inline std::string heShe (const LivingBeing* being, Capitalized capital) { // capital = NonCapital by default
std::string result = ((being->getGender() == Male) ? "he" : (being->getGender() == Female) ? "she" : "it");
return (capital == NonCapital) ? result : capitalize(result);
}
inline std::string heShe (const LivingBeingProxy* being, Capitalized capital) { // capital = NonCapital by default
return heShe (being->getActual(), capital);
}
inline std::string hisHer (const LivingBeing* being, Capitalized capital) { // capital = NonCapital by default
std::string result = ((being->getGender() == Male) ? "his" : (being->getGender() == Female) ? "her" : "its");
return (capital == NonCapital) ? result : capitalize(result);
}
inline std::string hisHer (const LivingBeingProxy* being, Capitalized capital) { // capital = NonCapital by default
return hisHer (being->getActual(), capital);
}
inline std::string himHer (const LivingBeing* being) {
return (being->getGender() == Male) ? "him" : (being->getGender() == Female) ? "her" : "it";
}
inline std::string himHer (const LivingBeingProxy* being) {
return himHer (being->getActual());
}
inline std::string hisHers (const LivingBeing* being) {
return (being->getGender() == Male) ? "his" : (being->getGender() == Female) ? "hers" : "it";
}
inline std::string hisHers (const LivingBeingProxy* being) {
return hisHers (being->getActual());
}
|