PlaylistFile: move memchr() call to class Path

This commit is contained in:
Max Kellermann 2015-03-02 21:48:37 +01:00
parent e9125ef8e4
commit 87a8a3e22f
2 changed files with 14 additions and 2 deletions

View File

@ -169,11 +169,13 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
const Path parent_path_fs, const Path parent_path_fs,
const Path name_fs) const Path name_fs)
{ {
if (name_fs.HasNewline())
return false;
const auto *const name_fs_str = name_fs.c_str(); const auto *const name_fs_str = name_fs.c_str();
const size_t name_length = name_fs.length(); const size_t name_length = name_fs.length();
if (name_length < ARRAY_SIZE(PLAYLIST_FILE_SUFFIX) || if (name_length < ARRAY_SIZE(PLAYLIST_FILE_SUFFIX))
memchr(name_fs_str, '\n', name_length) != nullptr)
return false; return false;
if (!StringEndsWith(name_fs_str, PLAYLIST_FILE_SUFFIX)) if (!StringEndsWith(name_fs_str, PLAYLIST_FILE_SUFFIX))

View File

@ -122,6 +122,16 @@ public:
return value; return value;
} }
/**
* Does the path contain a newline character? (Which is
* usually rejected by MPD because its protocol cannot
* transfer newline characters).
*/
gcc_pure
bool HasNewline() const {
return strchr(value, '\n') != nullptr;
}
/** /**
* Convert the path to UTF-8. * Convert the path to UTF-8.
* Returns empty string on error or if this instance is "nulled" * Returns empty string on error or if this instance is "nulled"