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
|
||||
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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user