fix up path handling
This commit is contained in:
@@ -32,8 +32,9 @@ CString FixSlashes( CString sPath )
|
|||||||
|
|
||||||
void CollapsePath( CString &sPath )
|
void CollapsePath( CString &sPath )
|
||||||
{
|
{
|
||||||
|
/* Don't ignore empty: we do want to keep trailing slashes. */
|
||||||
CStringArray as;
|
CStringArray as;
|
||||||
split( sPath, "/", as, true );
|
split( sPath, "/", as, false );
|
||||||
|
|
||||||
for( unsigned i=0; i<as.size(); i++ )
|
for( unsigned i=0; i<as.size(); i++ )
|
||||||
{
|
{
|
||||||
@@ -43,6 +44,12 @@ void CollapsePath( CString &sPath )
|
|||||||
as.erase( as.begin()+i-1 );
|
as.erase( as.begin()+i-1 );
|
||||||
i -= 2;
|
i -= 2;
|
||||||
}
|
}
|
||||||
|
else if( as[i] == "" && i+1 < as.size() )
|
||||||
|
{
|
||||||
|
/* Remove empty parts that aren't at the end; "foo//bar/" -> "foo/bar/". */
|
||||||
|
as.erase( as.begin()+i );
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
else if( as[i] == "." )
|
else if( as[i] == "." )
|
||||||
{
|
{
|
||||||
as.erase( as.begin()+i );
|
as.erase( as.begin()+i );
|
||||||
|
|||||||
@@ -77,29 +77,30 @@ int FileSet::GetFileHash(const CString &path) const
|
|||||||
return i->hash + i->size;
|
return i->hash + i->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". */
|
/*
|
||||||
|
* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz".
|
||||||
|
* "foo" -> "", "foo"
|
||||||
|
*/
|
||||||
static void SplitPath( CString Path, CString &Dir, CString &Name )
|
static void SplitPath( CString Path, CString &Dir, CString &Name )
|
||||||
{
|
{
|
||||||
/* Strip off any trailing slashes. */
|
CollapsePath( Path );
|
||||||
if( Path.size() > 0 && Path.Right(1) == "/" )
|
if( Path.Right(1) == "/" )
|
||||||
Path.erase( Path.size()-1 );
|
Path.erase( Path.size()-1 );
|
||||||
|
|
||||||
static Regex split("(.*/)([^/]+)");
|
unsigned sep = Path.find_last_of( '/' );
|
||||||
|
if( sep == CString::npos )
|
||||||
CStringArray match;
|
{
|
||||||
if(split.Compare(Path, match)) {
|
Dir = "";
|
||||||
/* At least one slash. */
|
|
||||||
Dir = match[0];
|
|
||||||
Name = match[1];
|
|
||||||
} else {
|
|
||||||
/* No slash. */
|
|
||||||
Dir = "./";
|
|
||||||
Name = Path;
|
Name = Path;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dir = Path.substr( 0, sep+1 );
|
||||||
|
Name = Path.substr( sep+1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FileType FilenameDB::GetFileType( const CString &sPath )
|
FileType FilenameDB::GetFileType( const CString &sPath )
|
||||||
{
|
{
|
||||||
CString Dir, Name;
|
CString Dir, Name;
|
||||||
@@ -211,6 +212,9 @@ FileSet &FilenameDB::GetFileSet( CString dir )
|
|||||||
dir.Replace("\\", "/"); /* foo\bar -> foo/bar */
|
dir.Replace("\\", "/"); /* foo\bar -> foo/bar */
|
||||||
dir.Replace("//", "/"); /* foo//bar -> foo/bar */
|
dir.Replace("//", "/"); /* foo//bar -> foo/bar */
|
||||||
|
|
||||||
|
if( dir == "" )
|
||||||
|
dir = ".";
|
||||||
|
|
||||||
CString lower = dir;
|
CString lower = dir;
|
||||||
lower.MakeLower();
|
lower.MakeLower();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user