Commit 9067da2d authored by Max Kellermann's avatar Max Kellermann

Mapper: map_fs_to_utf8() returns std::string

Avoid the conversion to an allocated char*, let the caller decide.
parent 8cf2f52f
...@@ -248,7 +248,7 @@ map_song_fs(const Song *song) ...@@ -248,7 +248,7 @@ map_song_fs(const Song *song)
return Path::FromUTF8(song->uri); return Path::FromUTF8(song->uri);
} }
char * std::string
map_fs_to_utf8(const char *path_fs) map_fs_to_utf8(const char *path_fs)
{ {
if (!music_dir_fs.IsNull() && if (!music_dir_fs.IsNull() &&
...@@ -263,11 +263,7 @@ map_fs_to_utf8(const char *path_fs) ...@@ -263,11 +263,7 @@ map_fs_to_utf8(const char *path_fs)
while (path_fs[0] == G_DIR_SEPARATOR) while (path_fs[0] == G_DIR_SEPARATOR)
++path_fs; ++path_fs;
const std::string path_utf8 = Path::ToUTF8(path_fs); return Path::ToUTF8(path_fs);
if (path_utf8.empty())
return nullptr;
return g_strdup(path_utf8.c_str());
} }
const Path & const Path &
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#ifndef MPD_MAPPER_HXX #ifndef MPD_MAPPER_HXX
#define MPD_MAPPER_HXX #define MPD_MAPPER_HXX
#include <string>
#include "gcc.h" #include "gcc.h"
#define PLAYLIST_FILE_SUFFIX ".m3u" #define PLAYLIST_FILE_SUFFIX ".m3u"
...@@ -118,10 +120,11 @@ map_song_fs(const Song *song); ...@@ -118,10 +120,11 @@ map_song_fs(const Song *song);
* absolute) to a relative path in UTF-8 encoding. * absolute) to a relative path in UTF-8 encoding.
* *
* @param path_fs a path in file system encoding * @param path_fs a path in file system encoding
* @return the relative path in UTF-8, or nullptr if mapping failed * @return the relative path in UTF-8, or an empty string if mapping
* failed
*/ */
gcc_malloc gcc_pure
char * std::string
map_fs_to_utf8(const char *path_fs); map_fs_to_utf8(const char *path_fs);
/** /**
......
...@@ -248,13 +248,11 @@ LoadPlaylistFile(const char *utf8path, Error &error) ...@@ -248,13 +248,11 @@ LoadPlaylistFile(const char *utf8path, Error &error)
s = g_strconcat("file://", path.c_str(), NULL); s = g_strconcat("file://", path.c_str(), NULL);
} else if (!uri_has_scheme(s)) { } else if (!uri_has_scheme(s)) {
char *path_utf8; const auto path = map_fs_to_utf8(s);
if (path.empty())
path_utf8 = map_fs_to_utf8(s);
if (path_utf8 == nullptr)
continue; continue;
s = path_utf8; s = g_strdup(path.c_str());
} else { } else {
const auto path = Path::ToUTF8(s); const auto path = Path::ToUTF8(s);
if (path.empty()) if (path.empty())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment