From 69f781f2d8eed870605b7e8c771e3723b51fab9e Mon Sep 17 00:00:00 2001 From: Igor Kulaychuk Date: Wed, 22 Aug 2018 19:58:27 +0300 Subject: [PATCH] Fix unicode string convertion on Windows --- src/debug/netcoredbg/CMakeLists.txt | 1 + src/debug/netcoredbg/cputil.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/debug/netcoredbg/cputil.h | 25 ++++++++---------------- 3 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 src/debug/netcoredbg/cputil.cpp diff --git a/src/debug/netcoredbg/CMakeLists.txt b/src/debug/netcoredbg/CMakeLists.txt index dd156ee..5eb428a 100644 --- a/src/debug/netcoredbg/CMakeLists.txt +++ b/src/debug/netcoredbg/CMakeLists.txt @@ -39,6 +39,7 @@ set(netcoredbg_SRC vscodeprotocol.cpp frames.cpp jmc.cpp + cputil.cpp expr.cpp) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/src/debug/netcoredbg/cputil.cpp b/src/debug/netcoredbg/cputil.cpp new file mode 100644 index 0000000..676506d --- /dev/null +++ b/src/debug/netcoredbg/cputil.cpp @@ -0,0 +1,39 @@ +#include "cputil.h" + +#include +#include + +#ifdef _MSC_VER + +static std::wstring_convert,wchar_t> convert; + +std::string to_utf8(const wchar_t *wstr) +{ + return convert.to_bytes(wstr); +} + +#else + +static std::wstring_convert,char16_t> convert; + +std::string to_utf8(const char16_t *wstr) +{ + return convert.to_bytes(wstr); +} + +#endif + +std::string to_utf8(char16_t wch) +{ + return convert.to_bytes(wch); +} + +#ifdef _MSC_VER +std::wstring +#else +std::u16string +#endif +to_utf16(const std::string &utf8) +{ + return convert.from_bytes(utf8); +} diff --git a/src/debug/netcoredbg/cputil.h b/src/debug/netcoredbg/cputil.h index 2c6b672..8e6c3f5 100644 --- a/src/debug/netcoredbg/cputil.h +++ b/src/debug/netcoredbg/cputil.h @@ -4,22 +4,13 @@ #pragma once #include -#include -#include -static std::wstring_convert,char16_t> convert; +#ifdef _MSC_VER +std::string to_utf8(const wchar_t *wstr); +std::wstring to_utf16(const std::string &utf8); +#else +std::string to_utf8(const char16_t *wstr); +std::u16string to_utf16(const std::string &utf8); +#endif -static inline std::string to_utf8(const char16_t *wstr) -{ - return convert.to_bytes(wstr); -} - -static inline std::string to_utf8(char16_t wch) -{ - return convert.to_bytes(wch); -} - -static inline std::u16string to_utf16(const std::string &utf8) -{ - return convert.from_bytes(utf8); -} +std::string to_utf8(char16_t wch); -- 2.7.4