summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-05 19:07:53 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-05 19:13:44 +0100
commit90b1dafeff14cbafd3af2300fc1862e5347ef386 (patch)
treedf8d299dadba6a5c99d131154dd26ff5d2d13dd8 /AK
parent5b7924b9e786d449d12e0df4630f710447b25592 (diff)
downloadserenity-90b1dafeff14cbafd3af2300fc1862e5347ef386.zip
AK: Break String::number() overloads into i/l/ll and u/ul/ull
Now that we're trying to be more portable, we can't only rely on using i32/u32 and i64/u64 since different systems have different combinations of int/long/long long and unsigned/unsigned long/unsigned long long.
Diffstat (limited to 'AK')
-rw-r--r--AK/String.cpp32
-rw-r--r--AK/String.h19
2 files changed, 31 insertions, 20 deletions
diff --git a/AK/String.cpp b/AK/String.cpp
index 8922a2a543..3ad0ba0a33 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -230,26 +230,44 @@ unsigned String::to_uint(bool& ok) const
return value;
}
-String String::number(u64 value)
+String String::number(unsigned long long value)
{
int size;
char buffer[32];
-#ifdef __serenity__
size = sprintf(buffer, "%llu", value);
-#else
- size = sprintf(buffer, "%" PRIu64, value);
-#endif
return String(buffer, size);
}
-String String::number(u32 value)
+String String::number(unsigned long value)
+{
+ int size;
+ char buffer[32];
+ size = sprintf(buffer, "%lu", value);
+ return String(buffer, size);
+}
+
+String String::number(unsigned value)
{
char buffer[32];
int size = sprintf(buffer, "%u", value);
return String(buffer, size);
}
-String String::number(i32 value)
+String String::number(long long value)
+{
+ char buffer[32];
+ int size = sprintf(buffer, "%lld", value);
+ return String(buffer, size);
+}
+
+String String::number(long value)
+{
+ char buffer[32];
+ int size = sprintf(buffer, "%ld", value);
+ return String(buffer, size);
+}
+
+String String::number(int value)
{
char buffer[32];
int size = sprintf(buffer, "%d", value);
diff --git a/AK/String.h b/AK/String.h
index a4f1593a76..74ac6a885d 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -231,19 +231,12 @@ public:
}
static String format(const char*, ...);
- static String number(u64);
- static String number(u32);
- static String number(i32);
- static String number(i64);
-
- static String number(size_t n)
- {
- if constexpr(sizeof(size_t) == 4)
- return number((u32)n);
- else if constexpr(sizeof(size_t) == 8)
- return number((u64)n);
- ASSERT_NOT_REACHED();
- }
+ static String number(unsigned);
+ static String number(unsigned long);
+ static String number(unsigned long long);
+ static String number(int);
+ static String number(long);
+ static String number(long long);
StringView view() const
{