playlist/PlaylistSong: pass std::string_view
This commit is contained in:
parent
a885bdba4c
commit
cefc773992
@ -65,15 +65,15 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
playlist_check_translate_song(DetachedSong &song, const char *base_uri,
|
playlist_check_translate_song(DetachedSong &song, std::string_view base_uri,
|
||||||
const SongLoader &loader) noexcept
|
const SongLoader &loader) noexcept
|
||||||
{
|
{
|
||||||
if (base_uri != nullptr && strcmp(base_uri, ".") == 0)
|
if (base_uri.compare(".") == 0)
|
||||||
/* PathTraitsUTF8::GetParent() returns "." when there
|
/* PathTraitsUTF8::GetParent() returns "." when there
|
||||||
is no directory name in the given path; clear that
|
is no directory name in the given path; clear that
|
||||||
now, because it would break the database lookup
|
now, because it would break the database lookup
|
||||||
functions */
|
functions */
|
||||||
base_uri = nullptr;
|
base_uri = {};
|
||||||
|
|
||||||
const char *uri = song.GetURI();
|
const char *uri = song.GetURI();
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ playlist_check_translate_song(DetachedSong &song, const char *base_uri,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (base_uri != nullptr && !uri_has_scheme(uri) &&
|
if (base_uri.data() != nullptr && !uri_has_scheme(uri) &&
|
||||||
!PathTraitsUTF8::IsAbsolute(uri))
|
!PathTraitsUTF8::IsAbsolute(uri))
|
||||||
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
|
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef MPD_PLAYLIST_SONG_HXX
|
#ifndef MPD_PLAYLIST_SONG_HXX
|
||||||
#define MPD_PLAYLIST_SONG_HXX
|
#define MPD_PLAYLIST_SONG_HXX
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
class SongLoader;
|
class SongLoader;
|
||||||
class DetachedSong;
|
class DetachedSong;
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ class DetachedSong;
|
|||||||
* @return true on success, false if the song should not be used
|
* @return true on success, false if the song should not be used
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
playlist_check_translate_song(DetachedSong &song, const char *base_uri,
|
playlist_check_translate_song(DetachedSong &song, std::string_view base_uri,
|
||||||
const SongLoader &loader) noexcept;
|
const SongLoader &loader) noexcept;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -112,7 +112,7 @@ queue_load_song(TextFile &file, const SongLoader &loader,
|
|||||||
|
|
||||||
auto song = LoadQueueSong(file, line);
|
auto song = LoadQueueSong(file, line);
|
||||||
|
|
||||||
if (!playlist_check_translate_song(song, nullptr, loader))
|
if (!playlist_check_translate_song(song, {}, loader))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
queue.Append(std::move(song), priority);
|
queue.Append(std::move(song), priority);
|
||||||
|
@ -200,7 +200,7 @@ TEST_F(TranslateSongTest, Insecure)
|
|||||||
/* illegal because secure=false */
|
/* illegal because secure=false */
|
||||||
DetachedSong song1 (uri1);
|
DetachedSong song1 (uri1);
|
||||||
const SongLoader loader(*reinterpret_cast<const Client *>(1));
|
const SongLoader loader(*reinterpret_cast<const Client *>(1));
|
||||||
EXPECT_FALSE(playlist_check_translate_song(song1, nullptr,
|
EXPECT_FALSE(playlist_check_translate_song(song1, {},
|
||||||
loader));
|
loader));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,18 +221,18 @@ TEST_F(TranslateSongTest, InDatabase)
|
|||||||
storage);
|
storage);
|
||||||
|
|
||||||
DetachedSong song1("doesntexist");
|
DetachedSong song1("doesntexist");
|
||||||
EXPECT_FALSE(playlist_check_translate_song(song1, nullptr,
|
EXPECT_FALSE(playlist_check_translate_song(song1, {},
|
||||||
loader));
|
loader));
|
||||||
|
|
||||||
DetachedSong song2(uri2, MakeTag2b());
|
DetachedSong song2(uri2, MakeTag2b());
|
||||||
auto se = ToString(DetachedSong(uri2, MakeTag2c()));
|
auto se = ToString(DetachedSong(uri2, MakeTag2c()));
|
||||||
EXPECT_TRUE(playlist_check_translate_song(song2, nullptr,
|
EXPECT_TRUE(playlist_check_translate_song(song2, {},
|
||||||
loader));
|
loader));
|
||||||
EXPECT_EQ(se, ToString(song2));
|
EXPECT_EQ(se, ToString(song2));
|
||||||
|
|
||||||
DetachedSong song3("/music/foo/bar.ogg", MakeTag2b());
|
DetachedSong song3("/music/foo/bar.ogg", MakeTag2b());
|
||||||
se = ToString(DetachedSong(uri2, MakeTag2c()));
|
se = ToString(DetachedSong(uri2, MakeTag2c()));
|
||||||
EXPECT_TRUE(playlist_check_translate_song(song3, nullptr,
|
EXPECT_TRUE(playlist_check_translate_song(song3, {},
|
||||||
loader));
|
loader));
|
||||||
EXPECT_EQ(se, ToString(song3));
|
EXPECT_EQ(se, ToString(song3));
|
||||||
}
|
}
|
||||||
@ -281,12 +281,12 @@ TEST_F(TranslateSongTest, Backslash)
|
|||||||
/* on Windows, all backslashes are converted to slashes in
|
/* on Windows, all backslashes are converted to slashes in
|
||||||
relative paths from playlists */
|
relative paths from playlists */
|
||||||
auto se = ToString(DetachedSong(uri2, MakeTag2c()));
|
auto se = ToString(DetachedSong(uri2, MakeTag2c()));
|
||||||
EXPECT_TRUE(playlist_check_translate_song(song1, nullptr,
|
EXPECT_TRUE(playlist_check_translate_song(song1, {},
|
||||||
loader));
|
loader));
|
||||||
EXPECT_EQ(se, ToString(song1));
|
EXPECT_EQ(se, ToString(song1));
|
||||||
#else
|
#else
|
||||||
/* backslash only supported on Windows */
|
/* backslash only supported on Windows */
|
||||||
EXPECT_FALSE(playlist_check_translate_song(song1, nullptr,
|
EXPECT_FALSE(playlist_check_translate_song(song1, {},
|
||||||
loader));
|
loader));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user