Fix unicode string convertion on Windows
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 22 Aug 2018 16:58:27 +0000 (19:58 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Fri, 24 Aug 2018 15:36:22 +0000 (18:36 +0300)
src/debug/netcoredbg/CMakeLists.txt
src/debug/netcoredbg/cputil.cpp [new file with mode: 0644]
src/debug/netcoredbg/cputil.h

index dd156ee..5eb428a 100644 (file)
@@ -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 (file)
index 0000000..676506d
--- /dev/null
@@ -0,0 +1,39 @@
+#include "cputil.h"
+
+#include <codecvt>
+#include <locale>
+
+#ifdef _MSC_VER
+
+static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> convert;
+
+std::string to_utf8(const wchar_t *wstr)
+{
+    return convert.to_bytes(wstr);
+}
+
+#else
+
+static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,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);
+}
index 2c6b672..8e6c3f5 100644 (file)
@@ -4,22 +4,13 @@
 #pragma once
 
 #include <string>
-#include <locale>
-#include <codecvt>
 
-static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,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);