config/Path: use StringView::Split()
This commit is contained in:
parent
109159e0f7
commit
dcd19c0592
@ -23,11 +23,10 @@
|
|||||||
#include "fs/Traits.hxx"
|
#include "fs/Traits.hxx"
|
||||||
#include "fs/StandardDirectory.hxx"
|
#include "fs/StandardDirectory.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
@ -96,30 +95,18 @@ ParsePath(const char *path)
|
|||||||
if (*path == '\0')
|
if (*path == '\0')
|
||||||
return GetConfiguredHome();
|
return GetConfiguredHome();
|
||||||
|
|
||||||
AllocatedPath home = nullptr;
|
|
||||||
|
|
||||||
if (*path == '/') {
|
if (*path == '/') {
|
||||||
home = GetConfiguredHome();
|
|
||||||
|
|
||||||
++path;
|
++path;
|
||||||
|
|
||||||
|
return GetConfiguredHome() /
|
||||||
|
AllocatedPath::FromUTF8Throw(path);
|
||||||
} else {
|
} else {
|
||||||
const char *slash = std::strchr(path, '/');
|
const auto [user, rest] =
|
||||||
const char *end = slash == nullptr
|
StringView{path}.Split('/');
|
||||||
? path + strlen(path)
|
|
||||||
: slash;
|
|
||||||
const std::string user(path, end);
|
|
||||||
home = GetHome(user.c_str());
|
|
||||||
|
|
||||||
if (slash == nullptr)
|
return GetHome(std::string{user}.c_str())
|
||||||
return home;
|
/ AllocatedPath::FromUTF8Throw(rest);
|
||||||
|
|
||||||
path = slash + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (home.IsNull())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return home / AllocatedPath::FromUTF8Throw(path);
|
|
||||||
} else if (!PathTraitsUTF8::IsAbsolute(path)) {
|
} else if (!PathTraitsUTF8::IsAbsolute(path)) {
|
||||||
throw FormatRuntimeError("not an absolute path: %s", path);
|
throw FormatRuntimeError("not an absolute path: %s", path);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user