X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fpath.cpp;h=0e86600453be225bcb647ff699f3cb0b5f20649b;hp=a5a5a10a5532133582172da6abcdf93acdf62ea6;hb=HEAD;hpb=f24e7b96e76b63c9b9b8a6bce4c7a9db64276ea8 diff --git a/source/fs/path.cpp b/source/fs/path.cpp index a5a5a10..1181b92 100644 --- a/source/fs/path.cpp +++ b/source/fs/path.cpp @@ -17,20 +17,7 @@ inline bool is_windows_drive(const string &p) namespace Msp { namespace FS { -Path::Path() -{ } - Path::Path(const string &p) -{ - init(p); -} - -Path::Path(const char *p) -{ - init(p); -} - -void Path::init(const string &p) { if(p.empty()) return; @@ -146,11 +133,21 @@ void Path::add_component(const string &comp) path += DIRSEP; path += comp; } - else if(separators.empty()) + else if(start==0) + { + /* Removing the last component of a relative path results in the + current directory */ path = "."; + } + else if(start==1) + { + /* Removing the last component of an absolute path results in the + root directory */ + path.erase(start, string::npos); + } else { - // Otherwise, erase the last component + // Otherwise, erase the last component and its separator path.erase(separators.back(), string::npos); separators.pop_back(); }