Redesign of `to_utf8()`
authorAndrey Okoshkin <a.okoshkin@samsung.com>
Wed, 7 Feb 2018 10:19:53 +0000 (13:19 +0300)
committerAndrey Okoshkin <a.okoshkin@samsung.com>
Wed, 7 Feb 2018 16:02:03 +0000 (19:02 +0300)
* String length is not passed any more due to it's buggy implementation.
* New overloaded version for a single wide-char is added.
* `WCHAR` is not necessary to use in this header as `char16_t` has been already
passed to the `std::codecvt_utf8_utf16` template.

src/debug/netcoredbg/cputil.h
src/debug/netcoredbg/valueprint.cpp

index b2563ef1c9b0a35dc37bba4d5a665e1c851e06f9..c4b1e7f8d59e0a42cf82617dd4a8fc9806cf42c0 100644 (file)
@@ -8,11 +8,12 @@
 
 static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
 
-static inline std::string to_utf8(const WCHAR *wstr, int len = -1)
+static inline std::string to_utf8(const char16_t *wstr)
 {
-    if (len == -1)
-        return convert.to_bytes(wstr);
-    if (len == 0)
-        return std::string();
-    return convert.to_bytes(wstr, wstr + len);
+    return convert.to_bytes(wstr);
+}
+
+static inline std::string to_utf8(char16_t wch)
+{
+    return convert.to_bytes(wch);
 }
index 67b34945fee651ea764f47169ff2b45c1b4b5d5e..46c378a5a6ac10b2b8148978ae881f137df8c5f3 100644 (file)
@@ -620,7 +620,7 @@ HRESULT PrintValue(ICorDebugValue *pInputValue, std::string &output, bool escape
     case ELEMENT_TYPE_CHAR:
         {
             WCHAR wc = * (WCHAR *) &(rgbValue[0]);
-            std::string printableVal = to_utf8(&wc, 1);
+            std::string printableVal = to_utf8(wc);
             if (!escape)
             {
                 output = printableVal;