diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 49ac95864..585396c8c 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -21,6 +21,7 @@ #include "thread/Mutex.hxx" #include "thread/Cond.hxx" #include "util/ASCII.hxx" +#include "util/NumberParser.hxx" #include "util/SpanCast.hxx" #include "util/StringCompare.hxx" #include "util/StringSplit.hxx" @@ -158,23 +159,20 @@ struct DavResponse { } }; -[[gnu::pure]] -static unsigned -ParseStatus(const char *s) noexcept -{ - /* skip the "HTTP/1.1" prefix */ - const char *space = std::strchr(s, ' '); - if (space == nullptr) - return 0; - - return strtoul(space + 1, nullptr, 10); -} - [[gnu::pure]] static unsigned ParseStatus(std::string_view s) noexcept { - return ParseStatus(std::string{s}.c_str()); + /* skip the "HTTP/1.1" prefix */ + const auto [http_1_1, rest] = Split(s, ' '); + + /* skip the string suffix */ + const auto [status_string, _] = Split(rest, ' '); + + if (const auto status = ParseInteger(status_string)) + return *status; + + return 0; } [[gnu::pure]] @@ -191,18 +189,14 @@ ParseTimeStamp(std::string_view s) noexcept return ParseTimeStamp(std::string{s}.c_str()); } -[[gnu::pure]] -static uint64_t -ParseU64(const char *s) noexcept -{ - return strtoull(s, nullptr, 10); -} - [[gnu::pure]] static uint64_t ParseU64(std::string_view s) noexcept { - return ParseU64(std::string{s}.c_str()); + if (const auto i = ParseInteger(s)) + return *i; + + return 0; } [[gnu::pure]]