util/NumberParser: use std::string_view
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2009-2022 Max Kellermann <max.kellermann@gmail.com>
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -29,22 +29,21 @@
|
||||
*/
|
||||
|
||||
#include "NumberParser.hxx"
|
||||
#include "StringView.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
int64_t
|
||||
ParseInt64(StringView s, const char **endptr_r, int base) noexcept
|
||||
ParseInt64(std::string_view s, const char **endptr_r, int base) noexcept
|
||||
{
|
||||
char buffer[32];
|
||||
*std::copy_n(s.data, std::min(s.size, std::size(buffer) - 1),
|
||||
*std::copy_n(s.data(), std::min(s.size(), std::size(buffer) - 1),
|
||||
buffer) = 0;
|
||||
|
||||
char *endptr;
|
||||
const auto result = ParseInt64(buffer, &endptr, base);
|
||||
if (endptr_r != nullptr)
|
||||
*endptr_r = s.data + (endptr - buffer);
|
||||
*endptr_r = s.data() + (endptr - buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user