[libc-commits] [libc] [libc] Character converter skeleton class (PR #143619)

via libc-commits libc-commits at lists.llvm.org
Tue Jun 10 15:39:20 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Uzair Nawaz (uzairnawaz)

<details>
<summary>Changes</summary>

Made CharacterConverter class skeleton


---
Full diff: https://github.com/llvm/llvm-project/pull/143619.diff


5 Files Affected:

- (added) libc/src/__support/wchar/CMakeLists.txt (+24) 
- (added) libc/src/__support/wchar/character_converter.cpp (+2) 
- (added) libc/src/__support/wchar/character_converter.h (+20) 
- (added) libc/src/__support/wchar/mbstate.h (+8) 
- (added) libc/src/__support/wchar/utf_ret.h (+6) 


``````````diff
diff --git a/libc/src/__support/wchar/CMakeLists.txt b/libc/src/__support/wchar/CMakeLists.txt
new file mode 100644
index 0000000000000..c1f402767235f
--- /dev/null
+++ b/libc/src/__support/wchar/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_header_library(
+  mbstate
+  HDRS
+    mbstate.h
+  DEPENDS
+    libc.hdr.types.wchar_t    
+)
+
+add_header_library(
+  character_converter
+  HDRS
+    character_converter.h
+  DEPENDS
+    libc.hdr.types.wchar_t
+    .mbstate
+    .utf_ret
+)
+
+add_header_library(
+  utf_ret
+  HDRS
+    utf_ret.h
+  DEPENDS
+)
diff --git a/libc/src/__support/wchar/character_converter.cpp b/libc/src/__support/wchar/character_converter.cpp
new file mode 100644
index 0000000000000..139597f9cb07c
--- /dev/null
+++ b/libc/src/__support/wchar/character_converter.cpp
@@ -0,0 +1,2 @@
+
+
diff --git a/libc/src/__support/wchar/character_converter.h b/libc/src/__support/wchar/character_converter.h
new file mode 100644
index 0000000000000..1800fe16eb14b
--- /dev/null
+++ b/libc/src/__support/wchar/character_converter.h
@@ -0,0 +1,20 @@
+
+#include "src/__support/wchar/mbstate.h"
+#include "src/__support/wchar/utf_ret.h"
+#include "hdr/types/wchar_t.h"
+
+class CharacterConverter {
+private:
+    mbstate_t* state;
+
+public:
+    CharacterConverter();
+
+    bool isComplete();
+
+    int push(char utf8_byte);
+    int push(wchar_t utf32);
+
+    utf_ret<char> pop_utf8();
+    utf_ret<wchar_t> pop_utf32();
+};
diff --git a/libc/src/__support/wchar/mbstate.h b/libc/src/__support/wchar/mbstate.h
new file mode 100644
index 0000000000000..c0af608c37623
--- /dev/null
+++ b/libc/src/__support/wchar/mbstate.h
@@ -0,0 +1,8 @@
+
+#include "hdr/types/wchar_t.h"
+
+struct mbstate_t {
+    wchar_t partial;
+    unsigned char bits_processed;
+    unsigned char total_bytes;
+};
diff --git a/libc/src/__support/wchar/utf_ret.h b/libc/src/__support/wchar/utf_ret.h
new file mode 100644
index 0000000000000..533f4cb952f4b
--- /dev/null
+++ b/libc/src/__support/wchar/utf_ret.h
@@ -0,0 +1,6 @@
+
+template <typename T>
+struct utf_ret {
+    T out;
+    int error;
+};

``````````

</details>


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


More information about the libc-commits mailing list