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(start<p.size())
{
string::size_type slash = p.find_first_of("/\\", start);
- if(slash>start)
- add_component(p.substr(start, slash-start));
+ if(slash>start || start==0)
+ add_component(p.substr(start, max<string::size_type>(slash-start, 1U)));
if(slash==string::npos)
break;
start = slash+1;
Path &Path::operator/=(const Path &p)
{
if(p.is_absolute())
- path = p.path;
+ *this = p;
else
{
for(Iterator i=p.begin(); i!=p.end(); ++i)
void Path::add_component(const string &comp)
{
- if(comp.empty())
- ;
- else if(comp.size()==1 && comp[0]==DIRSEP)
+ if(comp.size()==1 && (comp[0]=='/' || comp[0]=='\\'))
{
// Replace the path with the root directory
#ifdef WIN32
else
#endif
{
- path = comp;
+ path.assign(1, DIRSEP);
separators.clear();
separators.push_back(0);
}