lib/alsa/AllowedFormat: pass std::string_view to constructor

This commit is contained in:
Max Kellermann 2022-06-30 21:05:01 +02:00
parent 9976665cc7
commit ca90c75c61
2 changed files with 8 additions and 8 deletions

View File

@ -21,24 +21,26 @@
#include "pcm/AudioParser.hxx"
#include "util/IterableSplitString.hxx"
#include "util/StringBuffer.hxx"
#include "util/StringCompare.hxx"
#include "config.h"
#include <stdexcept>
using std::string_view_literals::operator""sv;
namespace Alsa {
AllowedFormat::AllowedFormat(StringView s)
AllowedFormat::AllowedFormat(std::string_view s)
{
#ifdef ENABLE_DSD
dop = s.RemoveSuffix("=dop");
dop = RemoveSuffix(s, "=dop"sv);
#endif
char buffer[64];
if (s.size >= sizeof(buffer))
if (s.size() >= sizeof(buffer))
throw std::invalid_argument("Failed to parse audio format");
memcpy(buffer, s.data, s.size);
buffer[s.size] = 0;
*std::copy(s.begin(), s.end(), buffer) = 0;
format = ParseAudioFormat(buffer, true);

View File

@ -26,8 +26,6 @@
#include <forward_list>
#include <string>
struct StringView;
namespace Alsa {
/**
@ -45,7 +43,7 @@ struct AllowedFormat {
*
* Throws std::runtime_error on error.
*/
explicit AllowedFormat(StringView s);
explicit AllowedFormat(std::string_view s);
/**
* Parse a list of formats separated by space.