Skip to content

Commit

Permalink
AK: Fix {:c} formatter for big-endian
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffect42 authored and timschumi committed Aug 6, 2024
1 parent 0b54579 commit b367479
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions AK/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,13 +879,17 @@ template<Integral T>
ErrorOr<void> Formatter<T>::format(FormatBuilder& builder, T value)
{
if (m_mode == Mode::Character) {
// FIXME: We just support ASCII for now, in the future maybe unicode?
// VERIFY(value >= 0 && value <= 127);

m_mode = Mode::String;

Formatter<StringView> formatter { *this };
return formatter.format(builder, StringView { reinterpret_cast<char const*>(&value), 1 });

// FIXME: We just support ASCII for now, in the future maybe unicode?
VERIFY(value >= 0 && value <= 127);

// Convert value to a single byte. This is important for big-endian systems, because the LSB is stored in the last byte.
char const c = (value & 0x7f);

return formatter.format(builder, StringView { &c, 1 });
}

if (m_precision.has_value())
Expand Down

0 comments on commit b367479

Please sign in to comment.