1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +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:
asynts 2020-09-22 13:05:40 +02:00 committed by Andreas Kling
parent 7ba7b72736
commit 4fcdc19b14
3 changed files with 12 additions and 3 deletions

View file

@ -71,12 +71,19 @@ static void write_escaped_literal(StringBuilder& builder, StringView literal)
++idx;
}
}
static size_t parse_number(StringView input)
{
String null_terminated { input };
char* endptr;
return strtoull(null_terminated.characters(), &endptr, 10);
size_t value = 0;
for (char ch : input) {
value *= 10;
value += ch - '0';
}
return value;
}
static bool parse_format_specifier(StringView input, FormatSpecifier& specifier)
{
specifier.index = NumericLimits<size_t>::max();