[PATCH] D51558: [Windows] Convert from UTF-8 to UTF-16 when writing to a Windows console

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 16:12:18 PDT 2018


zturner added inline comments.


================
Comment at: llvm/lib/Support/raw_ostream.cpp:636
+  // Fall back to ::write if it wasn't valid UTF-8.
+  if (auto EC = sys::windows::UTF8ToUTF16(Data, WideText))
+    return false;
----------------
rsmith wrote:
> Just out of curiosity: what's the difference between this and `llvm::convertUTF8ToUTF16String`?
The main difference is that `sys::windows::UTF8ToUTF16` calls a native Windows API to do the conversion.  Documentation for the Windows API claims to produce conformant UTF-16 in all cases, but historically people have still tried to use the Windows API whenever possible because there have been issues in the past where Windows was *almost* UTF-16 but not quite.  I think those days are gone, but people still do it.

The other difference is that `convertUTF8ToUTF16String` returns a `vector<unsigned short>`, whereas all of the windows APIs take `const wchar_t*`.  So we'd need a `reintepret_cast` before calling the actual Windows API, which is a little annoying.  (Incidentally, even *that* function should probably be changed to return a `vector<char16_t>`.


https://reviews.llvm.org/D51558





More information about the llvm-commits mailing list