Mercurial > minori
diff src/core/strings.cc @ 230:2f5a9247e501
torrents: implement download button
erg
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sat, 13 Jan 2024 09:42:02 -0500 |
parents | 53211cb1e7f5 |
children | 69f4768a820c |
line wrap: on
line diff
--- a/src/core/strings.cc Wed Jan 10 21:23:57 2024 -0500 +++ b/src/core/strings.cc Sat Jan 13 09:42:02 2024 -0500 @@ -16,6 +16,7 @@ #include <string> #include <vector> #include <unordered_map> +#include <iostream> namespace Strings { @@ -132,8 +133,15 @@ } std::wstring ToWstring(const std::string& string) { - static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; - return converter.from_bytes(string); + static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L""); + + std::wstring wstr; + try { + wstr = converter.from_bytes(string); + } catch (std::range_error const& ex) { + std::cerr << "Failed to convert UTF-8 to wide string!" << std::endl; + } + return wstr; } std::wstring ToWstring(const QString& string) { @@ -143,7 +151,7 @@ } std::string ToUtf8String(const std::wstring& wstring) { - static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; + static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L""); return converter.to_bytes(wstring); }