AK: Use format in String::number.

This commit is contained in:
asynts 2020-09-22 13:27:40 +02:00 committed by Andreas Kling
parent 90536a1558
commit eaeb793454
Notes: sideshowbarker 2024-07-19 02:17:03 +09:00
2 changed files with 18 additions and 47 deletions

View file

@ -25,6 +25,7 @@
*/
#include <AK/FlyString.h>
#include <AK/Format.h>
#include <AK/Memory.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
@ -214,49 +215,22 @@ Optional<unsigned> String::to_uint() const
return StringUtils::convert_to_uint(view());
}
String String::number(unsigned long long value)
{
int size;
char buffer[32];
size = snprintf(buffer, sizeof(buffer), "%llu", value);
return String(buffer, size);
}
template<typename T>
String String::number(T value) { return AK::format("{}", value); }
String String::number(unsigned long value)
{
int size;
char buffer[32];
size = snprintf(buffer, sizeof(buffer), "%lu", value);
return String(buffer, size);
}
template String String::number(unsigned char);
template String String::number(unsigned short);
template String String::number(unsigned int);
template String String::number(unsigned long);
template String String::number(unsigned long long);
template String String::number(char);
template String String::number(short);
template String String::number(int);
template String String::number(long);
template String String::number(long long);
String String::number(unsigned value)
{
char buffer[32];
int size = snprintf(buffer, sizeof(buffer), "%u", value);
return String(buffer, size);
}
String String::number(long long value)
{
char buffer[32];
int size = snprintf(buffer, sizeof(buffer), "%lld", value);
return String(buffer, size);
}
String String::number(long value)
{
char buffer[32];
int size = snprintf(buffer, sizeof(buffer), "%ld", value);
return String(buffer, size);
}
String String::number(int value)
{
char buffer[32];
int size = snprintf(buffer, sizeof(buffer), "%d", value);
return String(buffer, size);
}
// C++ is weird.
template String String::number(signed char);
String String::format(const char* fmt, ...)
{

View file

@ -238,12 +238,9 @@ public:
}
static String format(const char*, ...);
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);
template<typename T>
static String number(T);
StringView view() const;