[libc-commits] [libc] [libc] Support %lc in printf (PR #169983)
Shubh Pachchigar via libc-commits
libc-commits at lists.llvm.org
Wed Dec 24 00:57:04 PST 2025
================
@@ -3487,3 +3493,36 @@ TEST(LlvmLibcSPrintfTest, IndexModeParsing) {
"why would u do this, this is such a pain. %");
}
#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE
+
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+TEST(LlvmLibcSprintfTest, WideCharConversion) {
+ char buff[16];
+ int written;
+
+ // Euro sign is a 3-byte UTF-8 character.
+ written = LIBC_NAMESPACE::sprintf(buff, "%lc", static_cast<wchar_t>(L'€'));
+ EXPECT_EQ(written, 3);
+ ASSERT_STREQ(buff, "€");
+
+ // Euro sign left justified.
+ written = LIBC_NAMESPACE::sprintf(buff, "%-4lc", static_cast<wchar_t>(L'€'));
+ EXPECT_EQ(written, 6);
----------------
shubhe25p wrote:
No, my wchar implementation was wrong as you pointed out, we should only print 4 character with one padding space and three byte for euro sign.
https://github.com/llvm/llvm-project/pull/169983
More information about the libc-commits
mailing list