This commit is contained in:
Glenn Maynard
2006-03-26 06:09:12 +00:00
parent 3a80542460
commit 6b24dd0309
+19 -16
View File
@@ -649,11 +649,11 @@ void split( const wstring &Source, const wstring &Delimitor, int &begin, int &si
* c:\foo\bar.txt -> "c:\foo\", "bar", ".txt" * c:\foo\bar.txt -> "c:\foo\", "bar", ".txt"
* \\foo\fum -> "\\foo\", "fum", "" * \\foo\fum -> "\\foo\", "fum", ""
*/ */
void splitpath( const RString &Path, RString& Dir, RString& Filename, RString& Ext ) void splitpath( const RString &sPath, RString &sDir, RString &sFilename, RString &sExt )
{ {
Dir = Filename = Ext = ""; sDir = sFilename = sExt = "";
vector<RString> mat; vector<RString> asMatches;
/* /*
* One level of escapes for the regex, one for C. Ew. * One level of escapes for the regex, one for C. Ew.
@@ -661,31 +661,34 @@ void splitpath( const RString &Path, RString& Dir, RString& Filename, RString& E
* ^(.*[\\/])?(.*)$ * ^(.*[\\/])?(.*)$
*/ */
static Regex sep("^(.*[\\\\/])?(.*)$"); static Regex sep("^(.*[\\\\/])?(.*)$");
bool check = sep.Compare(Path, mat); bool bCheck = sep.Compare( sPath, asMatches );
ASSERT(check); ASSERT( bCheck );
Dir = mat[0]; sDir = asMatches[0];
const RString Base = mat[1]; const RString sBase = asMatches[1];
/* ^(.*)(\.[^\.]+)$ */ /* ^(.*)(\.[^\.]+)$ */
static Regex SplitExt("^(.*)(\\.[^\\.]+)$"); static Regex SplitExt("^(.*)(\\.[^\\.]+)$");
if( SplitExt.Compare(Base, mat) ) if( SplitExt.Compare(sBase, asMatches) )
{ {
Filename = mat[0]; sFilename = asMatches[0];
Ext = mat[1]; sExt = asMatches[1];
} else }
Filename = Base; else
{
sFilename = sBase;
}
} }
/* "foo.bar", "baz" -> "foo.baz" /* "foo.bar", "baz" -> "foo.baz"
* "foo", "baz" -> "foo.baz" * "foo", "baz" -> "foo.baz"
* "foo.bar", "" -> "foo" */ * "foo.bar", "" -> "foo" */
RString SetExtension( const RString &path, const RString &ext ) RString SetExtension( const RString &sPath, const RString &sExt )
{ {
RString Dir, FName, OldExt; RString sDir, sFileName, sOldExt;
splitpath( path, Dir, FName, OldExt ); splitpath( sPath, sDir, sFileName, sOldExt );
return Dir + FName + (ext.size()? ".":"") + ext; return sDir + sFileName + (sExt.size()? ".":"") + sExt;
} }
RString GetExtension( const RString &sPath ) RString GetExtension( const RString &sPath )