From: Mikko Rasa Date: Sun, 27 Aug 2006 10:51:38 +0000 (+0000) Subject: Add Path::empty() X-Git-Tag: fs-1.0~22 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4cc2d6ced17e8cbe1ae3251069131d22a292b857;p=libs%2Fcore.git Add Path::empty() begin()==end() for an empty path --- diff --git a/source/path.cpp b/source/path.cpp index 9996137..1a9460a 100644 --- a/source/path.cpp +++ b/source/path.cpp @@ -141,10 +141,12 @@ Path::iterator::iterator(const Path &p): path(p), start(0) { - if(path.path[0]==DIRCHAR) + if(path.path.empty()) + start=end=string::npos; + else if(path.path[0]==DIRCHAR) end=1; #ifdef WIN32 - else if(path.path[2]==DIRCHAR && is_windows_drive(path.path.substr(0,2))) + else if(path.path.size()>2 && path.path[2]==DIRCHAR && is_windows_drive(path.path.substr(0,2))) end=2; #endif else diff --git a/source/path.h b/source/path.h index f523622..9e1e374 100644 --- a/source/path.h +++ b/source/path.h @@ -45,7 +45,8 @@ public: Path(const std::string &p) { init(p); } Path(const char *p) { init(p); } const std::string &str() const { return path; } - unsigned size() const; + unsigned size() const; + bool empty() const { return path.empty(); } bool is_absolute() const; Path subpath(unsigned, unsigned =(unsigned)-1) const; Path operator/(const Path &p) const { Path a=*this; a/=p; return a; }