mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
AK+Format: Make it possible to format characters as integers.
This commit is contained in:
parent
2217d6b560
commit
d546d31a53
2 changed files with 13 additions and 6 deletions
|
@ -549,6 +549,17 @@ void Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeEra
|
||||||
builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, width, m_fill, m_sign_mode);
|
builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, width, m_fill, m_sign_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Formatter<char>::format(TypeErasedFormatParams& params, FormatBuilder& builder, char 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) {
|
||||||
|
// Trick: signed char != char. (Sometimes weird features are actually helpful.)
|
||||||
|
Formatter<signed char> formatter { *this };
|
||||||
|
return formatter.format(params, builder, static_cast<signed char>(value));
|
||||||
|
} else {
|
||||||
|
Formatter<StringView> formatter { *this };
|
||||||
|
return formatter.format(params, builder, { &value, 1 });
|
||||||
|
}
|
||||||
|
}
|
||||||
void Formatter<bool>::format(TypeErasedFormatParams& params, FormatBuilder& builder, bool value)
|
void Formatter<bool>::format(TypeErasedFormatParams& params, 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) {
|
||||||
|
|
|
@ -295,13 +295,9 @@ struct Formatter<T*> : StandardFormatter {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<char> : Formatter<StringView> {
|
struct Formatter<char> : StandardFormatter {
|
||||||
void format(TypeErasedFormatParams& params, FormatBuilder& builder, char value)
|
void format(TypeErasedFormatParams&, FormatBuilder&, char value);
|
||||||
{
|
|
||||||
Formatter<StringView>::format(params, builder, { &value, 1 });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<bool> : StandardFormatter {
|
struct Formatter<bool> : StandardFormatter {
|
||||||
void format(TypeErasedFormatParams&, FormatBuilder&, bool value);
|
void format(TypeErasedFormatParams&, FormatBuilder&, bool value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue