1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

AK: Add formatter for boolean values.

This commit is contained in:
asynts 2020-09-30 13:26:24 +02:00 committed by Andreas Kling
parent 7e9cd8a860
commit ebafc5b4d2
3 changed files with 39 additions and 0 deletions

View file

@ -460,6 +460,17 @@ void Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(StringB
PrintfImplementation::convert_signed_to_string(value, builder, base, m_alternative_form, upper_case, m_zero_pad, align, width, m_fill, sign_mode);
}
void Formatter<bool>::format(StringBuilder& builder, bool value, FormatterContext& context)
{
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<u8> formatter { *this };
return formatter.format(builder, static_cast<u8>(value), context);
} else {
Formatter<StringView> formatter { *this };
formatter.format(builder, value ? "true" : "false", context);
}
}
template struct Formatter<unsigned char, void>;
template struct Formatter<unsigned short, void>;
template struct Formatter<unsigned int, void>;