playlist/SoundCloud: use std::string_view
This commit is contained in:
parent
ca90c75c61
commit
c9723ee4b7
@ -66,11 +66,11 @@ soundcloud_init(const ConfigBlock &block)
|
|||||||
* @return Constructed URL. Must be freed with free().
|
* @return Constructed URL. Must be freed with free().
|
||||||
*/
|
*/
|
||||||
static AllocatedString
|
static AllocatedString
|
||||||
soundcloud_resolve(StringView uri) noexcept
|
soundcloud_resolve(std::string_view uri) noexcept
|
||||||
{
|
{
|
||||||
if (uri.StartsWithIgnoreCase("https://")) {
|
if (StringStartsWithIgnoreCase(uri, "https://"sv)) {
|
||||||
return AllocatedString{uri};
|
return AllocatedString{uri};
|
||||||
} else if (uri.StartsWith("soundcloud.com")) {
|
} else if (uri.starts_with("soundcloud.com"sv)) {
|
||||||
return AllocatedString{"https://"sv, uri};
|
return AllocatedString{"https://"sv, uri};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,33 +86,33 @@ soundcloud_resolve(StringView uri) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AllocatedString
|
static AllocatedString
|
||||||
TranslateSoundCloudUri(StringView uri) noexcept
|
TranslateSoundCloudUri(std::string_view uri) noexcept
|
||||||
{
|
{
|
||||||
if (uri.SkipPrefix("track/"sv)) {
|
if (SkipPrefix(uri, "track/"sv)) {
|
||||||
return AllocatedString{
|
return AllocatedString{
|
||||||
"https://api.soundcloud.com/tracks/"sv,
|
"https://api.soundcloud.com/tracks/"sv,
|
||||||
uri, ".json?client_id="sv,
|
uri, ".json?client_id="sv,
|
||||||
soundcloud_config.apikey,
|
soundcloud_config.apikey,
|
||||||
};
|
};
|
||||||
} else if (uri.SkipPrefix("playlist/"sv)) {
|
} else if (SkipPrefix(uri, "playlist/"sv)) {
|
||||||
return AllocatedString{
|
return AllocatedString{
|
||||||
"https://api.soundcloud.com/playlists/"sv,
|
"https://api.soundcloud.com/playlists/"sv,
|
||||||
uri, ".json?client_id="sv,
|
uri, ".json?client_id="sv,
|
||||||
soundcloud_config.apikey,
|
soundcloud_config.apikey,
|
||||||
};
|
};
|
||||||
} else if (uri.SkipPrefix("user/"sv)) {
|
} else if (SkipPrefix(uri, "user/"sv)) {
|
||||||
return AllocatedString{
|
return AllocatedString{
|
||||||
"https://api.soundcloud.com/users/"sv,
|
"https://api.soundcloud.com/users/"sv,
|
||||||
uri, "/tracks.json?client_id="sv,
|
uri, "/tracks.json?client_id="sv,
|
||||||
soundcloud_config.apikey,
|
soundcloud_config.apikey,
|
||||||
};
|
};
|
||||||
} else if (uri.SkipPrefix("search/"sv)) {
|
} else if (SkipPrefix(uri, "search/"sv)) {
|
||||||
return AllocatedString{
|
return AllocatedString{
|
||||||
"https://api.soundcloud.com/tracks.json?q="sv,
|
"https://api.soundcloud.com/tracks.json?q="sv,
|
||||||
uri, "&client_id="sv,
|
uri, "&client_id="sv,
|
||||||
soundcloud_config.apikey,
|
soundcloud_config.apikey,
|
||||||
};
|
};
|
||||||
} else if (uri.SkipPrefix("url/"sv)) {
|
} else if (SkipPrefix(uri, "url/"sv)) {
|
||||||
/* Translate to soundcloud resolver call. libcurl will automatically
|
/* Translate to soundcloud resolver call. libcurl will automatically
|
||||||
follow the redirect to the right resource. */
|
follow the redirect to the right resource. */
|
||||||
return soundcloud_resolve(uri);
|
return soundcloud_resolve(uri);
|
||||||
@ -146,9 +146,9 @@ struct SoundCloudJsonData {
|
|||||||
std::forward_list<DetachedSong> songs;
|
std::forward_list<DetachedSong> songs;
|
||||||
|
|
||||||
bool Integer(long long value) noexcept;
|
bool Integer(long long value) noexcept;
|
||||||
bool String(StringView value) noexcept;
|
bool String(std::string_view value) noexcept;
|
||||||
bool StartMap() noexcept;
|
bool StartMap() noexcept;
|
||||||
bool MapKey(StringView value) noexcept;
|
bool MapKey(std::string_view value) noexcept;
|
||||||
bool EndMap() noexcept;
|
bool EndMap() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,15 +167,15 @@ SoundCloudJsonData::Integer(long long intval) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
SoundCloudJsonData::String(StringView value) noexcept
|
SoundCloudJsonData::String(std::string_view value) noexcept
|
||||||
{
|
{
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case SoundCloudJsonData::Key::TITLE:
|
case SoundCloudJsonData::Key::TITLE:
|
||||||
title.assign(value.data, value.size);
|
title = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SoundCloudJsonData::Key::STREAM_URL:
|
case SoundCloudJsonData::Key::STREAM_URL:
|
||||||
stream_url.assign(value.data, value.size);
|
stream_url = value;
|
||||||
got_url = 1;
|
got_url = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ SoundCloudJsonData::String(StringView value) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
SoundCloudJsonData::MapKey(StringView value) noexcept
|
SoundCloudJsonData::MapKey(std::string_view value) noexcept
|
||||||
{
|
{
|
||||||
const auto *i = key_str;
|
const auto *i = key_str;
|
||||||
while (*i != nullptr && !StringStartsWith(*i, value))
|
while (*i != nullptr && !StringStartsWith(*i, value))
|
||||||
|
Loading…
Reference in New Issue
Block a user