diff options
Diffstat (limited to 'src/utils.cpp')
-rw-r--r-- | src/utils.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/utils.cpp b/src/utils.cpp index 8ca5cdb5..017ac48e 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -17,6 +17,8 @@ #include <curl/curl.h> +#include <stfl.h> + namespace newsbeuter { std::vector<std::string> utils::tokenize_quoted(const std::string& str, std::string delimiters) { @@ -490,6 +492,13 @@ std::string utils::replace_all(std::string str, const std::string& from, const s return str; } +std::wstring utils::utf8str2wstr(const std::string& utf8str) { + stfl_ipool * pool = stfl_ipool_create("utf-8"); + std::wstring wstr(stfl_ipool_towc(pool, utf8str.c_str())); + stfl_ipool_destroy(pool); + return wstr; +} + std::wstring utils::str2wstr(const std::string& str) { const char* pszExt = str.c_str(); wchar_t pwszInt [str.length()+1]; @@ -498,15 +507,15 @@ std::wstring utils::str2wstr(const std::string& str) { const char* pszNext; wchar_t* pwszNext; mbstate_t state = {0}; - GetLogger().log(LOG_DEBUG, "utils::str2wstr: current locale: %s", setlocale(LC_MESSAGES, NULL)); + GetLogger().log(LOG_DEBUG, "utils::str2wstr: current locale: %s", setlocale(LC_CTYPE, NULL)); #ifdef __APPLE__ std::locale loc; #else - std::locale loc(setlocale(LC_MESSAGES, NULL)); + std::locale loc(setlocale(LC_CTYPE, NULL)); #endif int res = std::use_facet<std::codecvt<wchar_t, char, mbstate_t> > ( loc ).in( state, pszExt, &pszExt[strlen(pszExt)], pszNext, pwszInt, &pwszInt[strlen(pszExt)], pwszNext ); if (res == std::codecvt_base::error) { - GetLogger().log(LOG_ERROR, "utils::str2wstr: conversion of `%s' failed (locale = %s).", str.c_str(), setlocale(LC_MESSAGES, NULL)); + GetLogger().log(LOG_ERROR, "utils::str2wstr: conversion of `%s' failed (locale = %s).", str.c_str(), setlocale(LC_CTYPE, NULL)); throw "utils::str2wstr: conversion failed"; } // pwszInt[strlen(pszExt)] = 0; @@ -520,11 +529,11 @@ std::string utils::wstr2str(const std::wstring& wstr) { char* pszNext; const wchar_t* pwszNext; mbstate_t state = {0}; - GetLogger().log(LOG_DEBUG, "utils::wstr2str: locale = %s input = `%ls'", setlocale(LC_MESSAGES, NULL), wstr.c_str()); + GetLogger().log(LOG_DEBUG, "utils::wstr2str: locale = %s input = `%ls'", setlocale(LC_CTYPE, NULL), wstr.c_str()); #ifdef __APPLE__ std::locale loc; #else - std::locale loc(setlocale(LC_MESSAGES, NULL)); + std::locale loc(setlocale(LC_CTYPE, NULL)); #endif int res = std::use_facet<std::codecvt<wchar_t, char, mbstate_t> > (loc).out(state, pwszInt, &pwszInt[wcslen(pwszInt)], pwszNext, pszExt, pszExt + sizeof(pszExt), pszNext); if (res == std::codecvt_base::error) { |