config/Path: pass std::string_view to ParsePath()
This commit is contained in:
parent
b2326b9a98
commit
f4f5e94a36
@ -71,32 +71,30 @@ InitPathParser(const ConfigData &config) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
ParsePath(const char *path)
|
ParsePath(std::string_view path)
|
||||||
{
|
{
|
||||||
assert(path != nullptr);
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (path[0] == '~') {
|
if (path.starts_with('~')) {
|
||||||
++path;
|
path.remove_prefix(1);
|
||||||
|
|
||||||
if (*path == '\0')
|
if (path.empty())
|
||||||
return GetConfiguredHome();
|
return GetConfiguredHome();
|
||||||
|
|
||||||
if (*path == '/') {
|
if (path.front() == '/') {
|
||||||
++path;
|
path.remove_prefix(1);
|
||||||
|
|
||||||
return GetConfiguredHome() /
|
return GetConfiguredHome() /
|
||||||
AllocatedPath::FromUTF8Throw(path);
|
AllocatedPath::FromUTF8Throw(path);
|
||||||
} else {
|
} else {
|
||||||
const auto [user, rest] = Split(std::string_view{path}, '/');
|
const auto [user, rest] = Split(path, '/');
|
||||||
|
|
||||||
return GetHome(std::string{user}.c_str())
|
return GetHome(std::string{user}.c_str())
|
||||||
/ AllocatedPath::FromUTF8Throw(rest);
|
/ AllocatedPath::FromUTF8Throw(rest);
|
||||||
}
|
}
|
||||||
} else if (path[0] == '$') {
|
} else if (path.starts_with('$')) {
|
||||||
++path;
|
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);
|
AllocatedPath xdg_path(nullptr);
|
||||||
if (env_var == "HOME"sv) {
|
if (env_var == "HOME"sv) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_CONFIG_PATH_HXX
|
#include <string_view>
|
||||||
#define MPD_CONFIG_PATH_HXX
|
|
||||||
|
|
||||||
struct ConfigData;
|
struct ConfigData;
|
||||||
class AllocatedPath;
|
class AllocatedPath;
|
||||||
@ -14,6 +13,4 @@ InitPathParser(const ConfigData &config) noexcept;
|
|||||||
* Throws #std::runtime_error on error.
|
* Throws #std::runtime_error on error.
|
||||||
*/
|
*/
|
||||||
AllocatedPath
|
AllocatedPath
|
||||||
ParsePath(const char *path);
|
ParsePath(std::string_view path);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user