[libc-commits] [libc] [libc] utf8 to 32 CharacterConverter (PR #143973)

Brooks Moses via libc-commits libc-commits at lists.llvm.org
Fri Jun 13 15:51:23 PDT 2025


================
@@ -29,8 +30,8 @@ class CharacterConverter {
   int push(char8_t utf8_byte);
   int push(char32_t utf32);
 
-  utf_ret<char8_t> pop_utf8();
-  utf_ret<char32_t> pop_utf32();
+  ErrorOr<char8_t> pop_utf8();
+  ErrorOr<char32_t> pop_utf32();
----------------
brooksmoses wrote:

It looks like you've made an API choice that calling pop_utf32 on an incomplete state will not reset the incomplete state, which means that it's valid for a user to do a loop that pushes a byte into the state and then calls pop without checking is_complete, and just uses the error value to determine if it got a new output utf32 character.  If that's intentional, it should be documented here.

(And, if that's not intentional, you should probably reset the state on error-producing pop calls regardless of whether or not the state is complete, so people don't rely on it.)

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


More information about the libc-commits mailing list