diff --git a/src/config/Path.cxx b/src/config/Path.cxx index ef7039791..b59e35d48 100644 --- a/src/config/Path.cxx +++ b/src/config/Path.cxx @@ -71,32 +71,30 @@ InitPathParser(const ConfigData &config) noexcept } AllocatedPath -ParsePath(const char *path) +ParsePath(std::string_view path) { - assert(path != nullptr); - #ifndef _WIN32 - if (path[0] == '~') { - ++path; + if (path.starts_with('~')) { + path.remove_prefix(1); - if (*path == '\0') + if (path.empty()) return GetConfiguredHome(); - if (*path == '/') { - ++path; + if (path.front() == '/') { + path.remove_prefix(1); return GetConfiguredHome() / AllocatedPath::FromUTF8Throw(path); } else { - const auto [user, rest] = Split(std::string_view{path}, '/'); + const auto [user, rest] = Split(path, '/'); return GetHome(std::string{user}.c_str()) / AllocatedPath::FromUTF8Throw(rest); } - } else if (path[0] == '$') { - ++path; + } else if (path.starts_with('$')) { + path.remove_prefix(1); - const auto [env_var, rest] = Split(std::string_view{path}, '/'); + const auto [env_var, rest] = Split(path, '/'); AllocatedPath xdg_path(nullptr); if (env_var == "HOME"sv) { diff --git a/src/config/Path.hxx b/src/config/Path.hxx index e78ef1ce2..3b2e6958d 100644 --- a/src/config/Path.hxx +++ b/src/config/Path.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_CONFIG_PATH_HXX -#define MPD_CONFIG_PATH_HXX +#include <string_view> struct ConfigData; class AllocatedPath; @@ -14,6 +13,4 @@ InitPathParser(const ConfigData &config) noexcept; * Throws #std::runtime_error on error. */ AllocatedPath -ParsePath(const char *path); - -#endif +ParsePath(std::string_view path);