cleanup
This commit is contained in:
@@ -17,64 +17,6 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageFileDriver.h"
|
#include "RageFileDriver.h"
|
||||||
|
|
||||||
void FixSlashesInPlace( CString &sPath )
|
|
||||||
{
|
|
||||||
for( unsigned i = 0; i < sPath.size(); ++i )
|
|
||||||
if( sPath[i] == '\\' )
|
|
||||||
sPath[i] = '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
CString FixSlashes( CString sPath )
|
|
||||||
{
|
|
||||||
FixSlashesInPlace( 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. */
|
|
||||||
CStringArray as;
|
|
||||||
split( sPath, "/", as, false );
|
|
||||||
|
|
||||||
for( unsigned i=0; i<as.size(); i++ )
|
|
||||||
{
|
|
||||||
if( as[i] == ".." && i != 0 )
|
|
||||||
{
|
|
||||||
as.erase( as.begin()+i-1 );
|
|
||||||
as.erase( as.begin()+i-1 );
|
|
||||||
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] == "." && i != 0 )
|
|
||||||
{
|
|
||||||
as.erase( as.begin()+i );
|
|
||||||
i -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sPath = join( "/", as );
|
|
||||||
}
|
|
||||||
|
|
||||||
RageFile::RageFile()
|
RageFile::RageFile()
|
||||||
{
|
{
|
||||||
m_File = NULL;
|
m_File = NULL;
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// call FixSlashes on any path that came from the user
|
|
||||||
void FixSlashesInPlace( CString &sPath );
|
|
||||||
CString FixSlashes( CString sPath );
|
|
||||||
void CollapsePath( CString &sPath );
|
|
||||||
|
|
||||||
class RageFileObj;
|
class RageFileObj;
|
||||||
|
|
||||||
class RageFile
|
class RageFile
|
||||||
|
|||||||
+58
-21
@@ -898,27 +898,6 @@ void Replace_Unicode_Markers( CString &Text )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplaceText( CString &Text, const map<CString,CString> &m )
|
|
||||||
{
|
|
||||||
basic_string<char,char_traits_char_nocase> txt(Text);
|
|
||||||
|
|
||||||
for(map<CString,CString>::const_iterator it = m.begin(); it != m.end(); ++it)
|
|
||||||
{
|
|
||||||
unsigned start = 0;
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
unsigned pos = txt.find(it->first, start);
|
|
||||||
if(pos == txt.npos)
|
|
||||||
break;
|
|
||||||
|
|
||||||
txt.replace(pos, it->first.size(), it->second);
|
|
||||||
start = pos+it->second.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text = txt.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Form a string to identify a wchar_t with ASCII. */
|
/* Form a string to identify a wchar_t with ASCII. */
|
||||||
CString WcharDisplayText(wchar_t c)
|
CString WcharDisplayText(wchar_t c)
|
||||||
{
|
{
|
||||||
@@ -1005,6 +984,64 @@ char char_traits_char_nocase::uptab[256] =
|
|||||||
'\xF0','\xF1','\xF2','\xF3','\xF4','\xF5','\xF6','\xF7','\xF8','\xF9','\xFA','\xFB','\xFC','\xFD','\xFE','\xFF',
|
'\xF0','\xF1','\xF2','\xF3','\xF4','\xF5','\xF6','\xF7','\xF8','\xF9','\xFA','\xFB','\xFC','\xFD','\xFE','\xFF',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void FixSlashesInPlace( CString &sPath )
|
||||||
|
{
|
||||||
|
for( unsigned i = 0; i < sPath.size(); ++i )
|
||||||
|
if( sPath[i] == '\\' )
|
||||||
|
sPath[i] = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
CString FixSlashes( CString sPath )
|
||||||
|
{
|
||||||
|
FixSlashesInPlace( 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. */
|
||||||
|
CStringArray as;
|
||||||
|
split( sPath, "/", as, false );
|
||||||
|
|
||||||
|
for( unsigned i=0; i<as.size(); i++ )
|
||||||
|
{
|
||||||
|
if( as[i] == ".." && i != 0 )
|
||||||
|
{
|
||||||
|
as.erase( as.begin()+i-1 );
|
||||||
|
as.erase( as.begin()+i-1 );
|
||||||
|
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] == "." && i != 0 )
|
||||||
|
{
|
||||||
|
as.erase( as.begin()+i );
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sPath = join( "/", as );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Helper function for reading/writing scores
|
// Helper function for reading/writing scores
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "RageFile.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// SAFE_ Macros
|
// SAFE_ Macros
|
||||||
@@ -227,7 +226,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
void Replace_Unicode_Markers( CString &Text );
|
void Replace_Unicode_Markers( CString &Text );
|
||||||
void ReplaceText( CString &Text, const map<CString,CString> &m );
|
|
||||||
CString WcharDisplayText(wchar_t c);
|
CString WcharDisplayText(wchar_t c);
|
||||||
|
|
||||||
CString Basename( const CString &dir );
|
CString Basename( const CString &dir );
|
||||||
@@ -292,10 +290,16 @@ bool ResolvePath(CString &path);
|
|||||||
unsigned GetFileSizeInBytes( const CString &sFilePath );
|
unsigned GetFileSizeInBytes( const CString &sFilePath );
|
||||||
void FlushDirCache();
|
void FlushDirCache();
|
||||||
|
|
||||||
|
// call FixSlashes on any path that came from the user
|
||||||
|
void FixSlashesInPlace( CString &sPath );
|
||||||
|
CString FixSlashes( CString sPath );
|
||||||
|
void CollapsePath( CString &sPath );
|
||||||
|
|
||||||
// helper file functions used by Bookkeeper and ProfileManager
|
// helper file functions used by Bookkeeper and ProfileManager
|
||||||
//
|
//
|
||||||
// Helper function for reading/writing scores
|
// Helper function for reading/writing scores
|
||||||
//
|
//
|
||||||
|
class RageFile;
|
||||||
bool FileRead(RageFile& f, CString& sOut);
|
bool FileRead(RageFile& f, CString& sOut);
|
||||||
bool FileRead(RageFile& f, int& iOut);
|
bool FileRead(RageFile& f, int& iOut);
|
||||||
bool FileRead(RageFile& f, unsigned& uOut);
|
bool FileRead(RageFile& f, unsigned& uOut);
|
||||||
|
|||||||
Reference in New Issue
Block a user