2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2019-06-06 13:14:31 +02:00
|
|
|
|
|
|
|
#include "NumberParser.hxx"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2019-08-03 13:10:49 +02:00
|
|
|
#include <iterator>
|
2019-06-06 13:14:31 +02:00
|
|
|
|
|
|
|
int64_t
|
2022-07-01 11:20:29 +02:00
|
|
|
ParseInt64(std::string_view s, const char **endptr_r, int base) noexcept
|
2019-06-06 13:14:31 +02:00
|
|
|
{
|
|
|
|
char buffer[32];
|
2022-07-01 11:20:29 +02:00
|
|
|
*std::copy_n(s.data(), std::min(s.size(), std::size(buffer) - 1),
|
2019-06-06 13:14:31 +02:00
|
|
|
buffer) = 0;
|
|
|
|
|
|
|
|
char *endptr;
|
|
|
|
const auto result = ParseInt64(buffer, &endptr, base);
|
|
|
|
if (endptr_r != nullptr)
|
2022-07-01 11:20:29 +02:00
|
|
|
*endptr_r = s.data() + (endptr - buffer);
|
2019-06-06 13:14:31 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|