Translation finally added to the output

This commit is contained in:
King_DuckZ 2013-08-22 11:13:15 +02:00
parent 3c334595c8
commit a5eb972290
2 changed files with 23 additions and 6 deletions

View file

@ -62,17 +62,34 @@ namespace {
return libjson::parse(libjson::to_json_string(jsonResponse)); return libjson::parse(libjson::to_json_string(jsonResponse));
} }
///-----------------------------------------------------------------------
///-----------------------------------------------------------------------
void PrintSingloNodeIfNotEmpty (std::wostream& parStream, JSONNode::const_iterator parNode, const wchar_t* parName, const wchar_t* parPre, const wchar_t* parPost) {
JSONNode::const_iterator found(parNode->find(parName));
if (found != parNode->end() and not found->as_string().empty())
parStream << parPre << found->as_string() << parPost;
}
///----------------------------------------------------------------------- ///-----------------------------------------------------------------------
///----------------------------------------------------------------------- ///-----------------------------------------------------------------------
void PrintTranslation (std::wostream& parStream, const JSONNode& parNode) { void PrintTranslation (std::wostream& parStream, const JSONNode& parNode) {
for (JSONNode::const_iterator itTr = parNode.begin(), itTrEND = parNode.end(); itTr != itTrEND; ++itTr) { for (JSONNode::const_iterator itTr = parNode.begin(), itTrEND = parNode.end(); itTr != itTrEND; ++itTr) {
JSONNode::const_iterator originalTerm = itTr->find(json_string(L"OriginalTerm")); JSONNode::const_iterator originalTerm = itTr->find(json_string(L"OriginalTerm"));
if (originalTerm != itTr->end()) { if (originalTerm != itTr->end()) {
JSONNode::const_iterator term(originalTerm->find(L"term")),
sense(originalTerm->find(L"sense")); JSONNode::const_iterator term(originalTerm->find(L"term"));
if (term != originalTerm->end() and sense != originalTerm->end()) { if (term != originalTerm->end()) {
parStream << originalTerm->find(L"term")->as_string(); JSONNode::const_iterator firstTranslation = itTr->find(json_string(L"FirstTranslation"));
parStream << L": (" << originalTerm->find(L"sense")->as_string() << L")\n"; parStream << originalTerm->find(L"term")->as_string() << L": ";
PrintSingloNodeIfNotEmpty(parStream, originalTerm, L"POS", L"", L" ");
PrintSingloNodeIfNotEmpty(parStream, originalTerm, L"sense", L"(", L")");
if (firstTranslation != itTr->end()) {
PrintSingloNodeIfNotEmpty(parStream, firstTranslation, L"term", L"\t- ", L"");
PrintSingloNodeIfNotEmpty(parStream, firstTranslation, L"POS", L" ", L"");
}
parStream << L"\n";
PrintSingloNodeIfNotEmpty(parStream, originalTerm, L"usage", L"", L"\n");
PrintSingloNodeIfNotEmpty(parStream, itTr, L"Note", L"Note: ", L"\n");
} }
} }
} }

View file

@ -113,7 +113,7 @@ int main (int parArgc, const char* const parArgv[]) {
WordReference wref(langFrom, langTo, DefApiKey); WordReference wref(langFrom, langTo, DefApiKey);
wref.Translate(searchWord, std::wcout); wref.Translate(searchWord, std::wcout);
std::wcout << wref.GetHttpLinkW(searchWord) << "\n"; std::wcout << L"\n" << wref.GetHttpLinkW(searchWord) << L"\n";
} }
std::wcout << L"Written by King_DuckZ; © WordReference.com" << std::endl; std::wcout << L"Written by King_DuckZ; © WordReference.com" << std::endl;
return 0; return 0;