Untitled
unknown
c_cpp
3 years ago
1.5 kB
12
Indexable
#include <iostream>
#include <string>
#include "functions.hpp"
#include <map>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Usage: ./bin/exec word" << std::endl;
return 1;
}
std::string word = argv[1];
std::string phonetics;
std::map<std::string, std::string> wordmap = {{"a", "ah"}, {"e", "eh"}, {"i", "ee"}, {"o", "oh"}, {"u", "oo"}, {"ai", "eye"}, {"ae", "eye"}, {"ao", "ow"}, {"au", "ow"}, {"ei", "ay"}, {"eu", "eh-oo"}, {"iu", "ew"}, {"oi", "oy"}, {"ou", "ow"}, {"ui", "ooey"}, {"iw", "ee-v"}, {"ew", "eh-v"}};
while (word.length() > 0) {
char letter = (char) std::tolower(word[0]);
char next_letter = word.length() >= 2 ? (char) std::tolower(word[1]): '\0';
if (!IsValidLetter(letter)) {
phonetics = word + " contains a character not a part of the Hawaiian language.";
break;
}
if (!IsVowel(letter)) {
phonetics += letter;
word = word.substr(1);
} else {
std::string letter_as_string{letter};
if (word.length() > 1 && (IsVowel(next_letter) || next_letter == 'w') && wordmap.count(letter_as_string + next_letter) > 0) {
phonetics += wordmap[letter_as_string + next_letter];
word = word.substr(2);
} else {
phonetics += wordmap[letter_as_string];
word = word.substr(1);
}
if (word.length() != 0 && word[0] != ' ' && word[0] != '\'' && phonetics[phonetics.length()-1] != 'v') phonetics += '-';
}
}
std::cout << phonetics << std::endl;
}Editor is loading...