CollapsePath(".") -> "."

This commit is contained in:
Glenn Maynard
2003-12-15 02:32:09 +00:00
parent 336411233f
commit c3f13981ef
+17 -1
View File
@@ -30,6 +30,22 @@ CString FixSlashes( CString sPath )
return sPath;
}
/*
* Keep trailing slashes, since that can be used to illustrate that a path always
* represents a directory. Not sure if we should always keep leading "." (we do
* because it's simpler), but be sure to keep the "." if it's all that's there, so
* collapsing "." doesn't result in "".
*
* foo/bar -> foo/bar
* foo/bar/ -> foo/bar/
* foo///bar/// -> foo/bar/
* foo/bar/./baz -> foo/bar/baz
* foo/bar/../baz -> foo/baz
* ./foo -> foo
* ./ -> .
* ./// -> .
*/
void CollapsePath( CString &sPath )
{
/* Don't ignore empty: we do want to keep trailing slashes. */
@@ -50,7 +66,7 @@ void CollapsePath( CString &sPath )
as.erase( as.begin()+i );
i -= 1;
}
else if( as[i] == "." )
else if( as[i] == "." && i != 0 )
{
as.erase( as.begin()+i );
i -= 1;