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

Uzair Nawaz via libc-commits libc-commits at lists.llvm.org
Thu Jun 12 15:12:59 PDT 2025


================
@@ -22,13 +22,64 @@ bool CharacterConverter::isComplete() {
   return state->bytes_processed == state->total_bytes;
 }
 
-int CharacterConverter::push(char8_t utf8_byte) {}
-
-int CharacterConverter::push(char32_t utf32) {}
-
-utf_ret<char8_t> CharacterConverter::pop_utf8() {}
+int CharacterConverter::push(char8_t utf8_byte) {
+  // Checking the first byte if first push
+  if (state->bytes_processed == 0 && state->total_bytes == 0) {
+    // 1 byte total
+    if ((utf8_byte & 128) == 0) {
+      state->total_bytes = 1;
+      state->bytes_processed = 1;
+      state->partial = static_cast<char32_t>(utf8_byte);
+      return 0;
----------------
uzairnawaz wrote:

these lines repeat in each branch, consider moving them to after the entire if/else statement

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


More information about the libc-commits mailing list