Distributed under the LGPL
*/
+#include <msp/core/except.h>
#include <msp/strings/utils.h>
#include "path.h"
#include "utils.h"
}
else
{
- for(Iterator i=--end();; --i)
+ for(Iterator i=end(); i!=begin();)
{
+ --i;
if(!++n)
return *i;
- if(i==begin())
- break;
}
}
- return string();
+ throw InvalidParameterValue("Path component index out of range");
}
bool Path::operator==(const Path &p) const
#endif
else if(comp=="..")
{
- if(path.empty())
+ if(path.empty() || path==".")
path=comp;
// .. in root directory is a no-op
else if(path.size()==1 && path[0]==DIRSEP)
path+=DIRSEP;
path+=comp;
}
+ else if(slash==string::npos)
+ path=".";
else
+ {
+ if(slash==0)
+ slash=1;
// Otherwise, erase the last component
path.erase(slash, string::npos);
+ }
}
}
else if(comp!="." || path.empty())
{
- if(path==".")
- path="";
+ if(comp!="." && path.empty())
+ path=".";
if(path.size()>1 || (path.size()==1 && path[0]!=DIRSEP))
path+=DIRSEP;
path+=comp;