From 4fcdc19b146f8371f7d3b5b9972db667d3b3d563 Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 22 Sep 2020 13:05:40 +0200 Subject: [PATCH] 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 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. --- AK/Format.cpp | 13 ++++++++++--- AK/Format.h | 1 + Kernel/CMakeLists.txt | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/AK/Format.cpp b/AK/Format.cpp index 4c6d6c1ec1..a4823b8e75 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -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::max(); diff --git a/AK/Format.h b/AK/Format.h index def205f3aa..f71f05ad1f 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -28,6 +28,7 @@ #include #include +#include namespace AK { diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 646cf406d1..0f3000cda2 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -209,6 +209,7 @@ set(AK_SOURCES ../AK/StringUtils.cpp ../AK/StringView.cpp ../AK/Time.cpp + ../AK/Format.cpp ) set(ELF_SOURCES