AK: Replace wchar_t formatting with char32_t
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This makes TestFormat fully cross-platform as we no longer have to
work around the 16 vs 32-bit wide strings
This commit is contained in:
Ashton 2025-05-18 16:05:41 -07:00 committed by Andrew Kaster
commit 5f5ae6bf8b
Notes: github-actions[bot] 2025-05-19 01:19:15 +00:00
3 changed files with 15 additions and 14 deletions

View file

@ -984,11 +984,11 @@ ErrorOr<void> Formatter<char>::format(FormatBuilder& builder, char value)
return formatter.format(builder, { &value, 1 });
}
}
ErrorOr<void> Formatter<wchar_t>::format(FormatBuilder& builder, wchar_t value)
ErrorOr<void> Formatter<char32_t>::format(FormatBuilder& builder, char32_t value)
{
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
Formatter<u32> formatter { *this };
return formatter.format(builder, static_cast<u32>(value));
return formatter.format(builder, value);
} else {
StringBuilder codepoint;
codepoint.append_code_point(value);

View file

@ -514,8 +514,8 @@ struct Formatter<char> : StandardFormatter {
ErrorOr<void> format(FormatBuilder&, char);
};
template<>
struct Formatter<wchar_t> : StandardFormatter {
ErrorOr<void> format(FormatBuilder& builder, wchar_t);
struct Formatter<char32_t> : StandardFormatter {
ErrorOr<void> format(FormatBuilder& builder, char32_t);
};
template<>
struct Formatter<bool> : StandardFormatter {

View file

@ -397,16 +397,17 @@ TEST_CASE(vector_format)
}
}
TEST_CASE(format_wchar)
TEST_CASE(format_utf32)
{
EXPECT_EQ(ByteString::formatted("{}", L'a'), "a");
EXPECT_EQ(ByteString::formatted("{}", L'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(ByteString::formatted("{:x}", L'a'), "61");
EXPECT_EQ(ByteString::formatted("{:x}", L'\U0001F41E'), "1f41e");
EXPECT_EQ(ByteString::formatted("{:d}", L'a'), "97");
EXPECT_EQ(ByteString::formatted("{:d}", L'\U0001F41E'), "128030");
EXPECT_EQ(ByteString::formatted("{}", U'a'), "a");
EXPECT_EQ(ByteString::formatted("{}", U'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(ByteString::formatted("{:x}", U'a'), "61");
EXPECT_EQ(ByteString::formatted("{:x}", U'\U0001F41E'), "1f41e");
EXPECT_EQ(ByteString::formatted("{:6}", L'a'), "a ");
EXPECT_EQ(ByteString::formatted("{:6d}", L'a'), " 97");
EXPECT_EQ(ByteString::formatted("{:#x}", L'\U0001F41E'), "0x1f41e");
EXPECT_EQ(ByteString::formatted("{:d}", U'a'), "97");
EXPECT_EQ(ByteString::formatted("{:d}", U'\U0001F41E'), "128030");
EXPECT_EQ(ByteString::formatted("{:6}", U'a'), "a ");
EXPECT_EQ(ByteString::formatted("{:6d}", U'a'), " 97");
EXPECT_EQ(ByteString::formatted("{:#x}", U'\U0001F41E'), "0x1f41e");
}