1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:47:45 +00:00

AK: Add a basic formatter for wchar_t

This commit is contained in:
Tim Schumacher 2021-09-21 23:07:03 +02:00 committed by Brian Gianforcaro
parent 4ef3ed4ba3
commit 67a579aab0
3 changed files with 31 additions and 0 deletions

View file

@ -688,6 +688,19 @@ void Formatter<char>::format(FormatBuilder& builder, char value)
return formatter.format(builder, { &value, 1 });
}
}
void Formatter<wchar_t>::format(FormatBuilder& builder, wchar_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));
} else {
StringBuilder codepoint;
codepoint.append_code_point(value);
Formatter<StringView> formatter { *this };
return formatter.format(builder, codepoint.to_string());
}
}
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) {

View file

@ -423,6 +423,10 @@ struct Formatter<char> : StandardFormatter {
void format(FormatBuilder&, char value);
};
template<>
struct Formatter<wchar_t> : StandardFormatter {
void format(FormatBuilder& builder, wchar_t value);
};
template<>
struct Formatter<bool> : StandardFormatter {
void format(FormatBuilder&, bool value);
};