Character conversion code put into a file on its own.
Character conversion relies on the setlocale(LC_TYPE, "") in main(), but maybe there are better ways of doing this.
This commit is contained in:
parent
2299247e77
commit
21476e0a5d
9 changed files with 144 additions and 17 deletions
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include "main.hpp"
|
||||
#include "WordReference.hpp"
|
||||
#include "CharConv.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/program_options/cmdline.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
|
@ -51,9 +52,9 @@ namespace {
|
|||
oss << "Usage is " << GetBaseName(parArgv[0]) << " [options] <from language> <to language> <search term>; parameters";
|
||||
boost::program_options::options_description desc(oss.str());
|
||||
boost::program_options::positional_options_description positionals;
|
||||
positionals.add("source-lang", 0);
|
||||
positionals.add("source-lang", 1);
|
||||
positionals.add("dest-lang", 1);
|
||||
positionals.add("word", 2);
|
||||
positionals.add("word", -1);
|
||||
|
||||
boost::program_options::options_description hidden("hidden options");
|
||||
hidden.add_options()
|
||||
|
@ -72,7 +73,8 @@ namespace {
|
|||
boost::program_options::store(boost::program_options::command_line_parser(parArgc, parArgv).options(commandLine).positional(positionals).run(), parVarMap);
|
||||
boost::program_options::notify(parVarMap);
|
||||
bool shownSomething = false;
|
||||
if (parVarMap.count("help")) {
|
||||
if (parVarMap.count("help") or parVarMap.count("source-lang") != 1 or
|
||||
parVarMap.count("dest-lang") != 1 or parVarMap.count("word") == 0) {
|
||||
std::cout << desc << "\n";
|
||||
shownSomething = true;
|
||||
}
|
||||
|
@ -83,6 +85,8 @@ namespace {
|
|||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
int main (int parArgc, const char* const parArgv[]) {
|
||||
//std::setlocale(LC_CTYPE, "UTF-8");
|
||||
std::setlocale(LC_CTYPE, "");
|
||||
boost::program_options::variables_map vm;
|
||||
if (GetCommandLine(vm, parArgc, parArgv))
|
||||
return 0;
|
||||
|
@ -101,10 +105,16 @@ int main (int parArgc, const char* const parArgv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
WordReference wref("en", "it", DefApiKey);
|
||||
wref.Translate(L"house", std::wcout);
|
||||
{
|
||||
const std::string langFrom(vm["source-lang"].as<std::string>());
|
||||
const std::string langTo(vm["dest-lang"].as<std::string>());
|
||||
const std::wstring searchWord(cconv::MultibyteToWide(vm["word"].as<std::string>()));
|
||||
|
||||
std::cout << wref.GetHttpLink(L"north face") << "\n";
|
||||
WordReference wref(langFrom, langTo, DefApiKey);
|
||||
wref.Translate(searchWord, std::wcout);
|
||||
|
||||
std::cout << wref.GetHttpLink(searchWord) << "\n";
|
||||
}
|
||||
std::wcout << L"Written by King_DuckZ; © WordReference.com" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue