if(path.size()==1 && path[0]==DIRSEP)
return 1;
- unsigned count=1;
+ unsigned count = 1;
for(string::const_iterator i=path.begin(); i!=path.end(); ++i)
if(*i==DIRSEP) ++count;
return count;
Path Path::subpath(unsigned start, unsigned count) const
{
Path result;
- Iterator i=begin();
+ Iterator i = begin();
for(unsigned j=0; (j<start && i!=end()); ++j)
++i;
for(unsigned j=0; (j<count && i!=end()); ++j)
{
- result/=*i;
+ result /= *i;
++i;
}
return result;
Path Path::operator/(const Path &p) const
{
- Path a=*this;
- a/=p;
+ Path a = *this;
+ a /= p;
return a;
}
Path &Path::operator/=(const Path &p)
{
if(p.is_absolute())
- path=p.path;
+ path = p.path;
else
{
for(Iterator i=p.begin(); i!=p.end(); ++i)
Path::Iterator Path::end() const
{
Iterator i(*this);
- i.start=i.end=std::string::npos;
+ i.start=i.end = std::string::npos;
return i;
}
void Path::init(const string &p)
{
- string::size_type start=0;
+ string::size_type start = 0;
if(p[0]=='/' || p[0]=='\\')
add_component(string(1, DIRSEP));
while(1)
{
- string::size_type slash=p.find_first_of("/\\", start);
+ string::size_type slash = p.find_first_of("/\\", start);
if(slash>start)
add_component(p.substr(start, slash-start));
if(slash==string::npos)
break;
- start=slash+1;
+ start = slash+1;
}
}
{
// Replace the path with the root directory
#ifdef WIN32
- unsigned slash=path.find(DIRSEP);
+ unsigned slash = path.find(DIRSEP);
if(is_windows_drive(path.substr(0, slash)))
- path=path.substr(0, 2);
+ path = path.substr(0, 2);
else
#endif
- path=comp;
+ path = comp;
}
#ifdef WIN32
else if(is_windows_drive(comp))
- path=comp;
+ path = comp;
#endif
else if(comp=="..")
{
if(path.empty() || path==".")
- path=comp;
+ path = comp;
// .. in root directory is a no-op
else if(path.size()==1 && path[0]==DIRSEP)
;
#endif
else
{
- string::size_type slash=path.rfind(DIRSEP);
- string::size_type start=(slash==string::npos ? 0 : slash+1);
+ string::size_type slash = path.rfind(DIRSEP);
+ string::size_type start = (slash==string::npos ? 0 : slash+1);
if(!path.compare(start, string::npos, ".."))
{
// If the last component already is a .., add another
- path+=DIRSEP;
- path+=comp;
+ path += DIRSEP;
+ path += comp;
}
else if(slash==string::npos)
- path=".";
+ path = ".";
else
{
if(slash==0)
- slash=1;
+ slash = 1;
// Otherwise, erase the last component
path.erase(slash, string::npos);
}
else if(comp!="." || path.empty())
{
if(comp!="." && path.empty())
- path=".";
+ path = ".";
if(path.size()>1 || (path.size()==1 && path[0]!=DIRSEP))
- path+=DIRSEP;
- path+=comp;
+ path += DIRSEP;
+ path += comp;
}
}
start(0)
{
if(path.path.empty())
- start=end=string::npos;
+ start=end = string::npos;
else if(path.path[0]==DIRSEP)
- end=1;
+ end = 1;
#ifdef WIN32
else if(path.path.size()>2 && path.path[2]==DIRSEP && is_windows_drive(path.path.substr(0, 2)))
- end=2;
+ end = 2;
#endif
else
- end=path.path.find(DIRSEP);
+ end = path.path.find(DIRSEP);
}
Path::Iterator &Path::Iterator::operator++()
{
- start=end;
+ start = end;
if(start>=path.path.size())
return *this;
if(path.path[start]==DIRSEP)
++start;
- end=path.path.find(DIRSEP, start);
+ end = path.path.find(DIRSEP, start);
return *this;
}
if(start==0)
return *this;
- end=start;
+ end = start;
if(end>1 && end<path.path.size() && path.path[end]!=DIRSEP)
--end;
- start=path.path.rfind(DIRSEP, end-1);
+ start = path.path.rfind(DIRSEP, end-1);
if(start==string::npos)
- start=0;
+ start = 0;
else if(start<end-1)
++start;