From c073ed8f702e98ec56ed05e0c02167e355e6ee31 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 24 Mar 2020 01:34:52 +0300 Subject: switch to Boost.Nowide everywhere --- src/error.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/error.cpp') diff --git a/src/error.cpp b/src/error.cpp index 16512b3..d305e88 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -5,6 +5,8 @@ #include "pdb/all.hpp" +#include + #include #include @@ -13,9 +15,9 @@ namespace pdb { namespace error { namespace { -std::string trim_trailing_newline(const std::string& s) { - const auto last_pos = s.find_last_not_of("\r\n"); - if (std::string::npos == last_pos) +std::wstring trim_trailing_newline(const std::wstring& s) { + const auto last_pos = s.find_last_not_of(L"\r\n"); + if (std::wstring::npos == last_pos) return {}; return s.substr(0, last_pos + 1); } @@ -23,25 +25,25 @@ std::string trim_trailing_newline(const std::string& s) { } // namespace std::string CategoryWindows::message(int code) const { - char* buf; + wchar_t* buf; - const auto nbwritten = FormatMessageA( + const auto len = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&buf), + reinterpret_cast(&buf), 0, NULL); - if (0 == nbwritten) { + if (0 == len) { LocalFree(buf); return "Couldn't format the error message"; } - std::string msg{buf, nbwritten}; + std::wstring msg{buf, len}; LocalFree(buf); - return trim_trailing_newline(msg); + return boost::nowide::narrow(trim_trailing_newline(msg)); } } // namespace error -- cgit v1.2.3