forked from lix-project/lix
isInDir() / isDirOrInDir(): Use std::string_view
This commit is contained in:
parent
be64fb9b51
commit
e1a0359b59
|
@ -196,16 +196,16 @@ std::string_view baseNameOf(std::string_view path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isInDir(const Path & path, const Path & dir)
|
bool isInDir(std::string_view path, std::string_view dir)
|
||||||
{
|
{
|
||||||
return path[0] == '/'
|
return path.substr(0, 1) == "/"
|
||||||
&& string(path, 0, dir.size()) == dir
|
&& path.substr(0, dir.size()) == dir
|
||||||
&& path.size() >= dir.size() + 2
|
&& path.size() >= dir.size() + 2
|
||||||
&& path[dir.size()] == '/';
|
&& path[dir.size()] == '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isDirOrInDir(const Path & path, const Path & dir)
|
bool isDirOrInDir(std::string_view path, std::string_view dir)
|
||||||
{
|
{
|
||||||
return path == dir || isInDir(path, dir);
|
return path == dir || isInDir(path, dir);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,11 +66,13 @@ Path dirOf(const Path & path);
|
||||||
following the final `/' (trailing slashes are removed). */
|
following the final `/' (trailing slashes are removed). */
|
||||||
std::string_view baseNameOf(std::string_view path);
|
std::string_view baseNameOf(std::string_view path);
|
||||||
|
|
||||||
/* Check whether 'path' is a descendant of 'dir'. */
|
/* Check whether 'path' is a descendant of 'dir'. Both paths must be
|
||||||
bool isInDir(const Path & path, const Path & dir);
|
canonicalized. */
|
||||||
|
bool isInDir(std::string_view path, std::string_view dir);
|
||||||
|
|
||||||
/* Check whether 'path' is equal to 'dir' or a descendant of 'dir'. */
|
/* Check whether 'path' is equal to 'dir' or a descendant of
|
||||||
bool isDirOrInDir(const Path & path, const Path & dir);
|
'dir'. Both paths must be canonicalized. */
|
||||||
|
bool isDirOrInDir(std::string_view path, std::string_view dir);
|
||||||
|
|
||||||
/* Get status of `path'. */
|
/* Get status of `path'. */
|
||||||
struct stat lstat(const Path & path);
|
struct stat lstat(const Path & path);
|
||||||
|
|
Loading…
Reference in a new issue