mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Use format in String::number.
This commit is contained in:
parent
90536a1558
commit
eaeb793454
Notes:
sideshowbarker
2024-07-19 02:17:03 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/eaeb793454f Pull-request: https://github.com/SerenityOS/serenity/pull/3580
2 changed files with 18 additions and 47 deletions
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/FlyString.h>
|
#include <AK/FlyString.h>
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/Memory.h>
|
#include <AK/Memory.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
@ -214,49 +215,22 @@ Optional<unsigned> String::to_uint() const
|
||||||
return StringUtils::convert_to_uint(view());
|
return StringUtils::convert_to_uint(view());
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::number(unsigned long long value)
|
template<typename T>
|
||||||
{
|
String String::number(T value) { return AK::format("{}", value); }
|
||||||
int size;
|
|
||||||
char buffer[32];
|
|
||||||
size = snprintf(buffer, sizeof(buffer), "%llu", value);
|
|
||||||
return String(buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
String String::number(unsigned long value)
|
template String String::number(unsigned char);
|
||||||
{
|
template String String::number(unsigned short);
|
||||||
int size;
|
template String String::number(unsigned int);
|
||||||
char buffer[32];
|
template String String::number(unsigned long);
|
||||||
size = snprintf(buffer, sizeof(buffer), "%lu", value);
|
template String String::number(unsigned long long);
|
||||||
return String(buffer, size);
|
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)
|
// C++ is weird.
|
||||||
{
|
template String String::number(signed char);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
String String::format(const char* fmt, ...)
|
String String::format(const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -238,12 +238,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static String format(const char*, ...);
|
static String format(const char*, ...);
|
||||||
static String number(unsigned);
|
|
||||||
static String number(unsigned long);
|
template<typename T>
|
||||||
static String number(unsigned long long);
|
static String number(T);
|
||||||
static String number(int);
|
|
||||||
static String number(long);
|
|
||||||
static String number(long long);
|
|
||||||
|
|
||||||
StringView view() const;
|
StringView view() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue