[libc-commits] [libc] [libc] Add support for wchar_t in StringConverter. (PR #211867)

Alex Strelnikov via libc-commits libc-commits at lists.llvm.org
Wed Jul 29 08:52:14 PDT 2026


================
@@ -71,18 +72,19 @@ cpp::string_view describeValue(const cpp::string &Value) { return Value; }
 cpp::string_view describeValue(cpp::string_view Value) { return Value; }
 
 cpp::string describeValue(cpp::wstring_view Value) {
-  // TODO: Print `Value` as UTF-8 once `StringConverter` supports `wchar_t`.
-  if (Value.empty())
-    return "{}";
+  LIBC_NAMESPACE::internal::mbstate State;
+  LIBC_NAMESPACE::internal::StringConverter<wchar_t> StringConv(
+      Value.data(), &State, /* dstlen = */ SIZE_MAX, Value.size());
 
   cpp::string S;
-  S += '{';
-  for (const wchar_t *Iter = Value.begin(); Iter + 1 != Value.end(); ++Iter) {
-    S += cpp::to_string(*Iter);
-    S += ',';
+  for (auto Conv = StringConv.pop<char8_t>(); Conv.has_value();
+       Conv = StringConv.pop<char8_t>()) {
+    S += static_cast<char>(*Conv);
   }
-  S += cpp::to_string(Value.back());
-  S += '}';
+
+  if (S.empty() && !Value.empty())
+    S = cpp::string("<Failed Converstion To UTF-8>");
----------------
strel-12 wrote:

Done, thanks.

https://github.com/llvm/llvm-project/pull/211867


More information about the libc-commits mailing list