From 402f90b5dfbece40b3b011f0b23aab8f24fd65a2 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 21 Aug 2013 15:21:16 +0200 Subject: [PATCH] JSon response is UTF-8 and it must be converted to wchar_t right away --- wordref/src/HttpReader.cpp | 6 ++++++ wordref/src/HttpReader.hpp | 1 + wordref/src/WordReference.cpp | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wordref/src/HttpReader.cpp b/wordref/src/HttpReader.cpp index 3e0249e..8485a8a 100644 --- a/wordref/src/HttpReader.cpp +++ b/wordref/src/HttpReader.cpp @@ -105,6 +105,12 @@ std::string HttpReader::GetPage (const std::string& parAddress) const { return localString; } +///----------------------------------------------------------------------------- +///----------------------------------------------------------------------------- +std::wstring HttpReader::GetPageW (const std::string& parAddress) const { + return cconv::MultibyteToWide(this->GetPage(parAddress)); +} + ///----------------------------------------------------------------------------- ///----------------------------------------------------------------------------- std::string HttpReader::UrlEncode (const wchar_t* parWord) { diff --git a/wordref/src/HttpReader.hpp b/wordref/src/HttpReader.hpp index 41b1057..5fca5f1 100644 --- a/wordref/src/HttpReader.hpp +++ b/wordref/src/HttpReader.hpp @@ -7,6 +7,7 @@ public: ~HttpReader ( void ) noexcept; std::string GetPage ( const std::string& parAddress ) const; + std::wstring GetPageW ( const std::string& parAddress ) const; std::string UrlEncode ( const wchar_t* parWord ) __attribute__((pure)); std::string UrlEncode ( const std::wstring& parWord ) __attribute__((pure)); diff --git a/wordref/src/WordReference.cpp b/wordref/src/WordReference.cpp index c639f29..9e441a2 100644 --- a/wordref/src/WordReference.cpp +++ b/wordref/src/WordReference.cpp @@ -50,7 +50,7 @@ namespace { oss << "http://api.wordreference.com/" << ApiVersion << "/" << parKey << "/json/" << parFrom << parTo << "/" << parHttp.UrlEncode(parWord); - std::string jsonResponse(parHttp.GetPage(oss.str())); + std::wstring jsonResponse(parHttp.GetPageW(oss.str())); return libjson::parse(libjson::to_json_string(jsonResponse)); }