[libc-commits] [libc] [libc] Add support for wchar_t in StringConverter. (PR #211867)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Wed Jul 29 07:31:43 PDT 2026
================
@@ -185,22 +211,59 @@ LIBC_INLINE ErrorOr<char8_t> CharacterConverter::pop_utf8() {
return static_cast<char8_t>(output);
}
+LIBC_INLINE ErrorOr<wchar_t> CharacterConverter::pop_wchar() {
+#if defined(LIBC_TYPES_WCHAR_T_IS_UTF32)
+ ErrorOr<char32_t> Result = pop_utf32();
+ return Result ? ErrorOr<wchar_t>(static_cast<wchar_t>(*Result))
----------------
kaladron wrote:
I'm curious if you could do this and have fewer casts for easier reading:
```c++
LIBC_INLINE ErrorOr<wchar_t> CharacterConverter::pop_wchar() {
#if defined(LIBC_TYPES_WCHAR_T_IS_UTF32)
ErrorOr<char32_t> res = pop_utf32();
if (!res)
return Error(res.error());
return static_cast<wchar_t>(*res);
#elif defined(LIBC_TYPES_WCHAR_T_IS_UTF16)
ErrorOr<char16_t> res = pop_utf16();
if (!res)
return Error(res.error());
return static_cast<wchar_t>(*res);
#else
return Error(-1);
#endif
}
```
(and the one below)
https://github.com/llvm/llvm-project/pull/211867
More information about the libc-commits
mailing list