AK: Define a formatter for char16_t

This commit is contained in:
Timothy Flynn 2025-06-13 10:15:08 -04:00 committed by Tim Flynn
commit b6dc5050d2
Notes: github-actions[bot] 2025-07-03 13:54:20 +00:00
2 changed files with 22 additions and 1 deletions

View file

@ -990,6 +990,21 @@ ErrorOr<void> Formatter<char>::format(FormatBuilder& builder, char value)
return formatter.format(builder, { &value, 1 }); return formatter.format(builder, { &value, 1 });
} }
} }
ErrorOr<void> Formatter<char16_t>::format(FormatBuilder& builder, char16_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<u16> formatter { *this };
return formatter.format(builder, value);
} else {
StringBuilder codepoint;
codepoint.append_code_point(value);
Formatter<StringView> formatter { *this };
return formatter.format(builder, codepoint.string_view());
}
}
ErrorOr<void> Formatter<char32_t>::format(FormatBuilder& builder, char32_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) { 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) {
@ -1003,6 +1018,7 @@ ErrorOr<void> Formatter<char32_t>::format(FormatBuilder& builder, char32_t value
return formatter.format(builder, codepoint.string_view()); return formatter.format(builder, codepoint.string_view());
} }
} }
ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value) ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool 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) { 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) {
@ -1015,6 +1031,7 @@ ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value)
return formatter.format(builder, value ? "true"sv : "false"sv); return formatter.format(builder, value ? "true"sv : "false"sv);
} }
} }
ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value) ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value)
{ {
u8 base; u8 base;

View file

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