mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-25 11:48:06 +00:00
AK: Define a formatter for char16_t
This commit is contained in:
parent
2618956b6f
commit
b6dc5050d2
Notes:
github-actions[bot]
2025-07-03 13:54:20 +00:00
Author: https://github.com/trflynn89
Commit: b6dc5050d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5228
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
2 changed files with 22 additions and 1 deletions
|
@ -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;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue