mirror of
https://github.com/textmate/textmate.git
synced 2026-02-15 08:55:01 -05:00
Add path::is_absolute.
This is actually not entirely trivial since we can have a path that starts with a slash but includes more ‘..’ components than there are actual directories in the path.
This commit is contained in:
@@ -178,6 +178,17 @@ namespace path
|
||||
return !path.empty() && path[0] == '/' ? normalize(path) : normalize(base + "/" + path);
|
||||
}
|
||||
|
||||
bool is_absolute (std::string const& path)
|
||||
{
|
||||
if(!path.empty() && path[0] == '/')
|
||||
{
|
||||
std::string p = normalize(path);
|
||||
if(p != "/.." && p.find("/../") != 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string with_tilde (std::string const& p)
|
||||
{
|
||||
std::string const& base = home();
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace path
|
||||
|
||||
PUBLIC std::string join (std::string const& base, std::string const& path); // this will normalize the (resulting) path
|
||||
|
||||
PUBLIC bool is_absolute (std::string const& path);
|
||||
PUBLIC std::string with_tilde (std::string const& path); // /Users/me/foo.html.erb → ~/foo.html.erb
|
||||
PUBLIC std::string relative_to (std::string const& path, std::string const& base); // /Users/me/foo.html.erb (arg: ~/Desktop) → ../foo.html.erb
|
||||
|
||||
|
||||
Reference in New Issue
Block a user