input/cdio: pass std::string_view to parse_cdio_uri()
This commit is contained in:
parent
459390cd56
commit
aee49d1c1c
@ -10,11 +10,12 @@
|
|||||||
#include "lib/fmt/RuntimeError.hxx"
|
#include "lib/fmt/RuntimeError.hxx"
|
||||||
#include "../InputStream.hxx"
|
#include "../InputStream.hxx"
|
||||||
#include "../InputPlugin.hxx"
|
#include "../InputPlugin.hxx"
|
||||||
#include "util/TruncateString.hxx"
|
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/ByteOrder.hxx"
|
#include "util/ByteOrder.hxx"
|
||||||
|
#include "util/NumberParser.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
|
#include "util/StringSplit.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "config/Block.hxx"
|
#include "config/Block.hxx"
|
||||||
@ -23,12 +24,10 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <cdio/cd_types.h>
|
#include <cdio/cd_types.h>
|
||||||
|
|
||||||
|
using std::string_view_literals::operator""sv;
|
||||||
|
|
||||||
static constexpr Domain cdio_domain("cdio");
|
static constexpr Domain cdio_domain("cdio");
|
||||||
|
|
||||||
static bool default_reverse_endian;
|
static bool default_reverse_endian;
|
||||||
@ -130,40 +129,25 @@ struct CdioUri {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static CdioUri
|
static CdioUri
|
||||||
parse_cdio_uri(const char *src)
|
parse_cdio_uri(std::string_view src)
|
||||||
{
|
{
|
||||||
CdioUri dest;
|
CdioUri dest;
|
||||||
|
|
||||||
if (*src == 0) {
|
src = StringAfterPrefixIgnoreCase(src, "cdda://"sv);
|
||||||
/* play the whole CD in the default drive */
|
|
||||||
dest.device[0] = 0;
|
|
||||||
dest.track = -1;
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *slash = std::strrchr(src, '/');
|
const auto [device, track] = Split(src, '/');
|
||||||
if (slash == nullptr) {
|
if (device.size() >= sizeof(dest.device))
|
||||||
/* play the whole CD in the specified drive */
|
throw std::invalid_argument{"Device name is too long"};
|
||||||
CopyTruncateString(dest.device, src, sizeof(dest.device));
|
|
||||||
dest.track = -1;
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t device_length = slash - src;
|
*std::copy(device.begin(), device.end(), dest.device) = '\0';
|
||||||
if (device_length >= sizeof(dest.device))
|
|
||||||
device_length = sizeof(dest.device) - 1;
|
|
||||||
|
|
||||||
memcpy(dest.device, src, device_length);
|
if (!track.empty()) {
|
||||||
dest.device[device_length] = 0;
|
auto value = ParseInteger<uint_least16_t>(track);
|
||||||
|
if (!value)
|
||||||
|
throw std::invalid_argument{"Bad track number"};
|
||||||
|
|
||||||
const char *track = slash + 1;
|
dest.track = *value;
|
||||||
|
} else
|
||||||
char *endptr;
|
|
||||||
dest.track = strtoul(track, &endptr, 10);
|
|
||||||
if (*endptr != 0)
|
|
||||||
throw std::runtime_error("Malformed track number");
|
|
||||||
|
|
||||||
if (endptr == track)
|
|
||||||
/* play the whole CD */
|
/* play the whole CD */
|
||||||
dest.track = -1;
|
dest.track = -1;
|
||||||
|
|
||||||
@ -190,9 +174,6 @@ static InputStreamPtr
|
|||||||
input_cdio_open(const char *uri,
|
input_cdio_open(const char *uri,
|
||||||
Mutex &mutex)
|
Mutex &mutex)
|
||||||
{
|
{
|
||||||
uri = StringAfterPrefixIgnoreCase(uri, "cdda://");
|
|
||||||
assert(uri != nullptr);
|
|
||||||
|
|
||||||
const auto parsed_uri = parse_cdio_uri(uri);
|
const auto parsed_uri = parse_cdio_uri(uri);
|
||||||
|
|
||||||
/* get list of CD's supporting CD-DA */
|
/* get list of CD's supporting CD-DA */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user