input/qobuz: use std::string_view

This commit is contained in:
Max Kellermann 2022-07-01 11:02:10 +02:00
parent c9723ee4b7
commit c05d4cddfb
5 changed files with 46 additions and 36 deletions

View File

@ -22,6 +22,9 @@
#include "util/ConstBuffer.hxx"
#include "util/RuntimeError.hxx"
using std::string_view_literals::operator""sv;
using Wrapper = Yajl::CallbacksWrapper<QobuzErrorParser>;
static constexpr yajl_callbacks qobuz_error_parser_callbacks = {
nullptr,
@ -60,14 +63,14 @@ QobuzErrorParser::OnEnd()
}
inline bool
QobuzErrorParser::String(StringView value) noexcept
QobuzErrorParser::String(std::string_view value) noexcept
{
switch (state) {
case State::NONE:
break;
case State::MESSAGE:
message.assign(value.data, value.size);
message = value;
break;
}
@ -75,9 +78,9 @@ QobuzErrorParser::String(StringView value) noexcept
}
inline bool
QobuzErrorParser::MapKey(StringView value) noexcept
QobuzErrorParser::MapKey(std::string_view value) noexcept
{
if (value.Equals("message"))
if (value == "message"sv)
state = State::MESSAGE;
else
state = State::NONE;

View File

@ -23,8 +23,9 @@
#include "lib/curl/Headers.hxx"
#include "lib/yajl/ResponseParser.hxx"
#include <string_view>
template<typename T> struct ConstBuffer;
struct StringView;
/**
* Parse an error JSON response.
@ -53,8 +54,8 @@ protected:
public:
/* yajl callbacks */
bool String(StringView value) noexcept;
bool MapKey(StringView value) noexcept;
bool String(std::string_view value) noexcept;
bool MapKey(std::string_view value) noexcept;
bool EndMap() noexcept;
};

View File

@ -25,6 +25,8 @@
#include <cassert>
using std::string_view_literals::operator""sv;
using Wrapper = Yajl::CallbacksWrapper<QobuzLoginRequest::ResponseParser>;
static constexpr yajl_callbacks parse_callbacks = {
nullptr,
@ -59,9 +61,9 @@ public:
QobuzSession &&GetSession();
/* yajl callbacks */
bool String(StringView value) noexcept;
bool String(std::string_view value) noexcept;
bool StartMap() noexcept;
bool MapKey(StringView value) noexcept;
bool MapKey(std::string_view value) noexcept;
bool EndMap() noexcept;
};
@ -161,7 +163,7 @@ QobuzLoginRequest::OnError(std::exception_ptr e) noexcept
}
inline bool
QobuzLoginRequest::ResponseParser::String(StringView value) noexcept
QobuzLoginRequest::ResponseParser::String(std::string_view value) noexcept
{
switch (state) {
case State::NONE:
@ -169,11 +171,11 @@ QobuzLoginRequest::ResponseParser::String(StringView value) noexcept
break;
case State::DEVICE_ID:
session.device_id.assign(value.data, value.size);
session.device_id = value;
break;
case State::USER_AUTH_TOKEN:
session.user_auth_token.assign(value.data, value.size);
session.user_auth_token = value;
break;
}
@ -200,13 +202,13 @@ QobuzLoginRequest::ResponseParser::StartMap() noexcept
}
inline bool
QobuzLoginRequest::ResponseParser::MapKey(StringView value) noexcept
QobuzLoginRequest::ResponseParser::MapKey(std::string_view value) noexcept
{
switch (state) {
case State::NONE:
if (value.Equals("user_auth_token"))
if (value == "user_auth_token"sv)
state = State::USER_AUTH_TOKEN;
else if (value.Equals("device")) {
else if (value == "device"sv) {
state = State::DEVICE;
map_depth = 0;
}
@ -214,7 +216,7 @@ QobuzLoginRequest::ResponseParser::MapKey(StringView value) noexcept
break;
case State::DEVICE:
if (value.Equals("id"))
if (value == "id"sv)
state = State::DEVICE_ID;
break;

View File

@ -24,6 +24,8 @@
#include "tag/Builder.hxx"
#include "tag/Tag.hxx"
using std::string_view_literals::operator""sv;
using Wrapper = Yajl::CallbacksWrapper<QobuzTagScanner::ResponseParser>;
static constexpr yajl_callbacks parse_callbacks = {
nullptr,
@ -68,9 +70,9 @@ public:
/* yajl callbacks */
bool Integer(long long value) noexcept;
bool String(StringView value) noexcept;
bool String(std::string_view value) noexcept;
bool StartMap() noexcept;
bool MapKey(StringView value) noexcept;
bool MapKey(std::string_view value) noexcept;
bool EndMap() noexcept;
};
@ -142,7 +144,7 @@ QobuzTagScanner::ResponseParser::Integer(long long value) noexcept
}
inline bool
QobuzTagScanner::ResponseParser::String(StringView value) noexcept
QobuzTagScanner::ResponseParser::String(std::string_view value) noexcept
{
switch (state) {
case State::TITLE:
@ -185,19 +187,19 @@ QobuzTagScanner::ResponseParser::StartMap() noexcept
}
inline bool
QobuzTagScanner::ResponseParser::MapKey(StringView value) noexcept
QobuzTagScanner::ResponseParser::MapKey(std::string_view value) noexcept
{
switch (map_depth) {
case 1:
if (value.Equals("composer"))
if (value == "composer"sv)
state = State::COMPOSER;
else if (value.Equals("duration"))
else if (value == "duration"sv)
state = State::DURATION;
else if (value.Equals("title"))
else if (value == "title"sv)
state = State::TITLE;
else if (value.Equals("album"))
else if (value == "album"sv)
state = State::ALBUM;
else if (value.Equals("performer"))
else if (value == "performer"sv)
state = State::PERFORMER;
else
state = State::NONE;
@ -212,7 +214,7 @@ QobuzTagScanner::ResponseParser::MapKey(StringView value) noexcept
case State::COMPOSER:
case State::COMPOSER_NAME:
if (value.Equals("name"))
if (value == "name"sv)
state = State::COMPOSER_NAME;
else
state = State::COMPOSER;
@ -222,9 +224,9 @@ QobuzTagScanner::ResponseParser::MapKey(StringView value) noexcept
case State::ALBUM_TITLE:
case State::ALBUM_ARTIST:
case State::ALBUM_ARTIST_NAME:
if (value.Equals("title"))
if (value == "title"sv)
state = State::ALBUM_TITLE;
else if (value.Equals("artist"))
else if (value == "artist"sv)
state = State::ALBUM_ARTIST;
else
state = State::ALBUM;
@ -232,7 +234,7 @@ QobuzTagScanner::ResponseParser::MapKey(StringView value) noexcept
case State::PERFORMER:
case State::PERFORMER_NAME:
if (value.Equals("name"))
if (value == "name"sv)
state = State::PERFORMER_NAME;
else
state = State::PERFORMER;
@ -247,7 +249,7 @@ QobuzTagScanner::ResponseParser::MapKey(StringView value) noexcept
switch (state) {
case State::ALBUM_ARTIST:
case State::ALBUM_ARTIST_NAME:
if (value.Equals("name"))
if (value == "name"sv)
state = State::ALBUM_ARTIST_NAME;
else
state = State::ALBUM_ARTIST;

View File

@ -22,6 +22,8 @@
#include "QobuzClient.hxx"
#include "lib/yajl/Callbacks.hxx"
using std::string_view_literals::operator""sv;
using Wrapper = Yajl::CallbacksWrapper<QobuzTrackRequest::ResponseParser>;
static constexpr yajl_callbacks parse_callbacks = {
nullptr,
@ -57,8 +59,8 @@ public:
}
/* yajl callbacks */
bool String(StringView value) noexcept;
bool MapKey(StringView value) noexcept;
bool String(std::string_view value) noexcept;
bool MapKey(std::string_view value) noexcept;
bool EndMap() noexcept;
};
@ -120,14 +122,14 @@ QobuzTrackRequest::OnError(std::exception_ptr e) noexcept
}
inline bool
QobuzTrackRequest::ResponseParser::String(StringView value) noexcept
QobuzTrackRequest::ResponseParser::String(std::string_view value) noexcept
{
switch (state) {
case State::NONE:
break;
case State::URL:
url.assign(value.data, value.size);
url = value;
break;
}
@ -135,9 +137,9 @@ QobuzTrackRequest::ResponseParser::String(StringView value) noexcept
}
inline bool
QobuzTrackRequest::ResponseParser::MapKey(StringView value) noexcept
QobuzTrackRequest::ResponseParser::MapKey(std::string_view value) noexcept
{
if (value.Equals("url"))
if (value == "url"sv)
state = State::URL;
else
state = State::NONE;