AK: Add longer human readable size to string helper function

Wraps the existing AK::human_readable_size function but will always
display the bytes in the base unit as well as the shorter string with
one decimal. E.g. "14 KiB (14396 bytes)".
This commit is contained in:
David Isaksson 2021-03-24 21:06:08 +01:00 committed by Andreas Kling
parent d3630a7b1f
commit 17c0349d23

View file

@ -54,6 +54,15 @@ static inline String human_readable_size(u64 size)
return number_string_with_one_decimal(size, EiB, "EiB");
}
static inline String human_readable_size_long(u64 size)
{
if (size < 1 * KiB)
return String::formatted("{} bytes", size);
else
return String::formatted("{} ({} bytes)", human_readable_size(size), size);
}
}
using AK::human_readable_size;
using AK::human_readable_size_long;