Skip to content

[libc] Character converter skeleton class #143619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 11, 2025

Conversation

uzairnawaz
Copy link
Contributor

Made CharacterConverter class skeleton

@llvmbot llvmbot added the libc label Jun 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2025

@llvm/pr-subscribers-libc

Author: Uzair Nawaz (uzairnawaz)

Changes

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 --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;
+};

Copy link

github-actions bot commented Jun 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs some changes

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that if there are no "DEPENDS" you don't need that line in the cmake rule, you still need a header library target

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michaelrj-google michaelrj-google merged commit 52583b3 into llvm:main Jun 11, 2025
13 checks passed
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Made CharacterConverter class skeleton
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
Made CharacterConverter class skeleton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants