diff options
author | asynts <asynts@gmail.com> | 2020-12-20 17:00:50 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-29 02:36:32 +0100 |
commit | 620b73b3d5bb6cf9d78d8b5ce456a9d65f2159cc (patch) | |
tree | 65dff56266f1e1767a7b51e20082558526330208 /AK/Format.h | |
parent | cbe0a8b40322755d22f9623c7eb2b46ed9916244 (diff) | |
download | serenity-620b73b3d5bb6cf9d78d8b5ce456a9d65f2159cc.zip |
AK+Format: Accept unsigned long in replacement fields.
I ran into this exact but at least twenty times in Serenity alone. The
C++ Standard dictates that 'unsigned long' and 'unsigned long long' are
distinct types even though on most platforms they are usually both 64
bit integers.
Also it wasn't possible to evaluate IsIntegral<T> for types that were
not integers since it used MakeUnsigned<T> internally.
Diffstat (limited to 'AK/Format.h')
-rw-r--r-- | AK/Format.h | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/AK/Format.h b/AK/Format.h index 9ff0fa7077..b269d70ac6 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -60,25 +60,36 @@ struct TypeErasedParameter { Custom }; + static Type get_type_from_size(size_t size, bool is_unsigned) + { + if (is_unsigned) { + if (size == 1) + return Type::UInt8; + if (size == 2) + return Type::UInt16; + if (size == 4) + return Type::UInt32; + if (size == 8) + return Type::UInt64; + } else { + if (size == 1) + return Type::Int8; + if (size == 2) + return Type::Int16; + if (size == 4) + return Type::Int32; + if (size == 8) + return Type::Int64; + } + + ASSERT_NOT_REACHED(); + } + template<typename T> static Type get_type() { - if (IsSame<T, u8>::value) - return Type::UInt8; - if (IsSame<T, u16>::value) - return Type::UInt16; - if (IsSame<T, u32>::value) - return Type::UInt32; - if (IsSame<T, u64>::value) - return Type::UInt64; - if (IsSame<T, i8>::value) - return Type::Int8; - if (IsSame<T, i16>::value) - return Type::Int16; - if (IsSame<T, i32>::value) - return Type::Int32; - if (IsSame<T, i64>::value) - return Type::Int64; + if (IsIntegral<T>::value) + return get_type_from_size(sizeof(T), IsUnsigned<T>::value); return Type::Custom; } |