================ @@ -76,6 +76,46 @@ using namespace lldb_private::line_editor; #endif // #if LLDB_EDITLINE_USE_WCHAR +#if LLDB_EDITLINE_USE_WCHAR +std::string ToBytes(const std::wstring &in) { + static std::locale locale("C.UTF-8"); + static const auto &cvt = + std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(locale); + + const size_t length = in.length(); + std::string output(length + 1, 0x0); ---------------- labath wrote:
This isn't right. A single wide character can take up to four bytes in the utf8 encoding. This works in `CompleteCharacter` as it's only interested in a single character (and it does the conversion in the other direction). We might be able get away with overapproximating the size, given that the inputs here should be fairly small, but adding a loop with partial conversions should not be that hard either. https://github.com/llvm/llvm-project/pull/112582 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits