mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-06 16:09:30 +00:00
AK: Remove strtoull dependency from format.
This function is not avaliable in the kernel. In the future it would be nice to have some sort of <charconv> header that does this for all integer types and then call it in strtoull and et cetera. The difference would be that this function say 'from_chars' would return an Optional and not just interpret anything invalid as zero.
This commit is contained in:
parent
7ba7b72736
commit
4fcdc19b14
|
@ -71,12 +71,19 @@ static void write_escaped_literal(StringBuilder& builder, StringView literal)
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t parse_number(StringView input)
|
static size_t parse_number(StringView input)
|
||||||
{
|
{
|
||||||
String null_terminated { input };
|
size_t value = 0;
|
||||||
char* endptr;
|
|
||||||
return strtoull(null_terminated.characters(), &endptr, 10);
|
for (char ch : input) {
|
||||||
|
value *= 10;
|
||||||
|
value += ch - '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_format_specifier(StringView input, FormatSpecifier& specifier)
|
static bool parse_format_specifier(StringView input, FormatSpecifier& specifier)
|
||||||
{
|
{
|
||||||
specifier.index = NumericLimits<size_t>::max();
|
specifier.index = NumericLimits<size_t>::max();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,7 @@ set(AK_SOURCES
|
||||||
../AK/StringUtils.cpp
|
../AK/StringUtils.cpp
|
||||||
../AK/StringView.cpp
|
../AK/StringView.cpp
|
||||||
../AK/Time.cpp
|
../AK/Time.cpp
|
||||||
|
../AK/Format.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ELF_SOURCES
|
set(ELF_SOURCES
|
||||||
|
|
Loading…
Reference in a new issue