From 17c0349d239b17317d5da9d1c3df2eaca83643d6 Mon Sep 17 00:00:00 2001 From: David Isaksson Date: Wed, 24 Mar 2021 21:06:08 +0100 Subject: [PATCH] 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)". --- AK/NumberFormat.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AK/NumberFormat.h b/AK/NumberFormat.h index 480c731975..9e52c98abb 100644 --- a/AK/NumberFormat.h +++ b/AK/NumberFormat.h @@ -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;