#include "main.hpp" #include "WordReference.hpp" #include #include namespace { std::map SupportedLanguages { std::make_pair("ar", "Arabic"), std::make_pair("zh", "Chinese"), std::make_pair("cz", "Czech"), std::make_pair("en", "English"), std::make_pair("fr", "French"), std::make_pair("gr", "Greek"), std::make_pair("it", "Italian"), std::make_pair("ja", "Japanese"), std::make_pair("ko", "Korean"), std::make_pair("pl", "Polish"), std::make_pair("pt", "Portuguese"), std::make_pair("ro", "Romanian"), std::make_pair("es", "Spanish"), std::make_pair("tr", "Turkish") }; std::string GetCleanWord (std::string parWord) __attribute__((pure)); std::string GetCleanWord (std::string parWord) { boost::algorithm::trim_all(parWord); std::replace(parWord.begin(), parWord.end(), ' ', '+'); return parWord; } } //unnamed namespace ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- ErrBadLanguage::ErrBadLanguage (std::string&& parMessage) : std::runtime_error(parMessage) { } ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- WordReference::WordReference (const char* parFrom, const char* parTo) : m_langFrom(parFrom), m_langTo(parTo) { if (SupportedLanguages.find(parFrom) == SupportedLanguages.end()) { std::ostringstream oss; oss << "Invalid source language: \"" << m_langFrom << "\""; throw ErrBadLanguage(oss.str()); } if (SupportedLanguages.find(parTo) == SupportedLanguages.end()) { std::ostringstream oss; oss << "Invalid destination language: \"" << m_langTo << "\""; throw ErrBadLanguage(oss.str()); } } ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- const std::string& WordReference::GetLanguageCode (WordReferenceLangDirection parDir) const { } ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- const std::string& WordReference::GetLanguageName (WordReferenceLangDirection parDir) const { } ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- std::string WordReference::GetHttpLink (const char* parWord) { std::ostringstream oss; oss << "http://www.wordreference.com/redirect/translation.aspx?w="; oss << GetCleanWord(parWord) << "&dict=" << m_langFrom << m_langTo; return oss.str(); } ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- std::string WordReference::GetHttpLink (const std::string& parWord) { std::ostringstream oss; oss << "http://www.wordreference.com/redirect/translation.aspx?w="; oss << GetCleanWord(parWord) << "&dict=" << m_langFrom << m_langTo; return oss.str(); }