From: Mikko Rasa Date: Fri, 6 Jul 2012 20:46:28 +0000 (+0300) Subject: Refactor Path::init X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=a0d162e53034a6ef2ef8cfc310a3ee18a6a3872e Refactor Path::init --- diff --git a/source/fs/path.cpp b/source/fs/path.cpp index 9380527..241b2f8 100644 --- a/source/fs/path.cpp +++ b/source/fs/path.cpp @@ -32,14 +32,14 @@ Path::Path(const char *p) void Path::init(const string &p) { + if(p.empty()) + return; string::size_type start = 0; - if(p[0]=='/' || p[0]=='\\') - add_component(string(1, DIRSEP)); - while(1) + while(startstart) - add_component(p.substr(start, slash-start)); + if(slash>start || start==0) + add_component(p.substr(start, max(slash-start, 1U))); if(slash==string::npos) break; start = slash+1; @@ -100,9 +100,7 @@ Path &Path::operator/=(const Path &p) void Path::add_component(const string &comp) { - if(comp.empty()) - ; - else if(comp.size()==1 && comp[0]==DIRSEP) + if(comp.size()==1 && comp[0]==DIRSEP) { // Replace the path with the root directory #ifdef WIN32