Class for path processing. More...
#include <utilities/string_utilities.h>
Static Public Member Functions | |
| static void | AddEndSlash (const char *OldPath, char *NewPath) |
| template<class str_type > | |
| static str_type | AddEndSlash (const str_type &Path) |
| static void | DeleteEndSlash (const char *OldPath, char *NewPath) |
| template<class str_type > | |
| static str_type | DeleteEndSlash (const str_type &OldPath) |
| static char * | ExtractFilePath (const char *FilePath, char *ClearedFilePath) |
| template<class str_type > | |
| static str_type | ExtractFilePath (const str_type &FilePath) |
| static char * | ExtractFileName (const char *FilePath, char *FileName) |
| template<class str_type > | |
| static str_type | ExtractFileName (const str_type &FilePath) |
| static void | ExtractModuleName (const char *file_name, char *module_name) |
| template<class str_type > | |
| static str_type | ExtractModuleName (const str_type &FileName) |
| static char * | ExtractFileExtension (const char *FileName, char *file_extension) |
| template<class str_type > | |
| static str_type | ExtractFileExtension (const str_type &FileName) |
| template<class cont > | |
| static void | ExplodePath (const std::string &Path, cont &PathSegments) |
Class for path processing.
Definition at line 52 of file string_utilities.h.
| void nitro::FSPath::AddEndSlash | ( | const char * | OldPath, | |
| char * | NewPath | |||
| ) | [static] |
Function adds slash to the path OldPath, if slash already exists then another one wouldn't be added.
| OldPath | - Old path. | |
| NewPath | - New path after addition. |
| nitro::exception | Throws exception with error description. |
Definition at line 13 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by AddEndSlash(), nitro::ZIPAbstraction::AddFile(), nitro::Directory::DirectoryExists(), nitro::UnTARAbstraction::ExtractFile(), nitro::DirectoryAbstraction::FindFirst(), nitro::UnZIPAbstraction::UnZIPFile(), and nitro::WalkThroughDirectory().
{
try
{
strcpy( NewPath , OldPath );
if( NewPath[ strlen( NewPath ) - 1 ] != '/' && NewPath[ strlen( NewPath ) - 1 ] != '\\' )
{
strcat( NewPath , "/" );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::AddEndSlash( const char * OldPath , char * NewPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::AddEndSlash( const char * OldPath , char * NewPath )::An error occured" ) , 1 ) );
}
}

| str_type nitro::FSPath::AddEndSlash | ( | const str_type & | Path | ) | [static] |
Function adds slash to the path OldPath, if slash already exists then another one wouldn't be added.
| Path | - Old path. |
| nitro::exception | Throws exception with error description. |
Definition at line 372 of file string_utilities.h.
References AddEndSlash(), nitro::exception::code(), and nitro::exception::what().
{
try
{
if( Path[ Path.length() - 1 ] == '/' || Path[ Path.length() - 1 ] == '\\' )
{
return( Path );
}
else
{
char * TmpStr( new char[ Path.length() + 2 ] );
memset( TmpStr , 0 , Path.length() + 2 );
AddEndSlash( Path.c_str() , TmpStr );
std::string RetStr( TmpStr );
delete [] TmpStr;
return( RetStr );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::AddEndSlash( const str_type & Path )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::AddEndSlash( const str_type & Path )::An error occured" ) , 0 ) );
}
}

| str_type nitro::FSPath::DeleteEndSlash | ( | const str_type & | OldPath | ) | [static] |
Function deletes ending slash.
| OldPath | - Old path before deletion. |
| nitro::exception | Throws exception with error description. |
Definition at line 403 of file string_utilities.h.
References nitro::exception::code(), DeleteEndSlash(), and nitro::exception::what().
{
try
{
char * CharChain( new char[ OldPath.length() + 2 ] );
memset( CharChain , 0 , OldPath.length() + 2 );
DeleteEndSlash( OldPath.c_str() , CharChain );
str_type RetString( CharChain );
delete [] CharChain;
return( RetString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::DeleteEndSlash( const str_type & OldPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::DeleteEndSlash( const str_type & OldPath )::An error occured" ) , 0 ) );
}
}

| void nitro::FSPath::DeleteEndSlash | ( | const char * | OldPath, | |
| char * | NewPath | |||
| ) | [static] |
Function deletes ending slash.
| OldPath | - Old path before deletion. | |
| NewPath | - New path after deletion. |
| nitro::exception | Throws exception with error description. |
Definition at line 34 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by DeleteEndSlash(), and nitro::Directory::ForceCreateDirectory().
{
try
{
if( OldPath[ strlen( OldPath ) - 1 ] == '/' || OldPath[ strlen( OldPath ) - 1 ] == '\\' )
{
memset( NewPath , 0 , strlen( OldPath ) );
strncpy( NewPath , OldPath , strlen( OldPath ) - 1 );
}
else
{
strcpy( NewPath , OldPath );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::DeleteEndSlash( const char * OldPath , char * NewPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::DeleteEndSlash( const char * OldPath , char * NewPath )::An error occured" ) , 1 ) );
}
}

| void nitro::FSPath::ExplodePath | ( | const std::string & | Path, | |
| cont & | PathSegments | |||
| ) | [static] |
Function explodes file path in parts.
| Path | - File path. | |
| PathSegments | - Segments of path. |
| nitro::exception | Throws exception with error description. |
Definition at line 526 of file string_utilities.h.
References nitro::exception::code(), ExtractFileName(), ExtractFilePath(), and nitro::exception::what().
{
try
{
char * PathPart( new char [ Path.size() + 1 ] );
char * PathSegment( new char [ Path.size() + 1 ] );
std::string TmpPath( Path );
do
{
nitro::FSPath::ExtractFileName( TmpPath.c_str() , PathSegment );
PathSegments.push_back( std::string( PathSegment ) );
nitro::FSPath::ExtractFilePath( TmpPath.c_str() , PathPart );
TmpPath = PathPart;
}
while( strlen( PathPart ) );
delete [] PathPart;
delete [] PathSegment;
std::reverse( PathSegments.begin() , PathSegments.end() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExplodePath( const std::string & Path , cont & PathSegments )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExplodePath( const std::string & Path , cont & PathSegments )::An error occured" ) , 0 ) );
}
}

| str_type nitro::FSPath::ExtractFileExtension | ( | const str_type & | FileName | ) | [static] |
Function returns file's extention.
| FileName | - File name whose extention will be extracted. |
| nitro::exception | Throws exception with error description. |
Definition at line 501 of file string_utilities.h.
References nitro::exception::code(), ExtractFileExtension(), and nitro::exception::what().
{
try
{
char * CharChain( new char[ FileName.length() + 1 ] );
memset( CharChain , 0 , CharChain );
ExtractFileExtension( FileName.c_str() , FileName.length() + 1 );
str_type RetString( CharChain );
delete [] CharChain;
return( RetString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileExtension( const str_type & file_name )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileExtension( const str_type & file_name )::An error occured" ) , 0 ) );
}
}

| char * nitro::FSPath::ExtractFileExtension | ( | const char * | FileName, | |
| char * | file_extension | |||
| ) | [static] |
Function returns file's extention.
| FileName | - File name whose extention will be extracted. | |
| file_extension | - String to store extension. |
| nitro::exception | Throws exception with error description. |
Definition at line 155 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by ExtractFileExtension().
{
try
{
int i( ( int )strlen( file_name ) - 1 );
file_extension[ 0 ] = '\0';
for( ; i >= 0 ; i-- )
{
if( file_name[ i ] == '.' )
{
goto end_loop;
}
}
end_loop:;
strncpy( file_extension , &file_name[ i + 1 ] , strlen( file_name ) - i );
return( file_extension );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileExtension( const char * file_name , char * file_extension )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileExtension( const char * file_name , char * file_extension )::An error occured" ) , 1 ) );
}
}

| str_type nitro::FSPath::ExtractFileName | ( | const str_type & | FilePath | ) | [static] |
Wrapper for function ExtractFileName( const char * FilePath , char * FileName ).
| FilePath | - Function extracts file name from file path. If extraction was not successfull, then FilePath is placed in FileName. |
| nitro::exception | Throws exception with error description. |
Definition at line 451 of file string_utilities.h.
References nitro::exception::code(), ExtractFileName(), and nitro::exception::what().
{
try
{
char * CharChain( new char[ FilePath.length() + 1 ] );
memset( CharChain , 0 , FilePath.length() + 1 );
ExtractFileName( FilePath.c_str() , CharChain );
str_type RetString( CharChain );
delete [] CharChain;
return( RetString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileName( const str_type & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileName( const str_type & FilePath )::An error occured" ) , 0 ) );
}
}

| char * nitro::FSPath::ExtractFileName | ( | const char * | FilePath, | |
| char * | FileName | |||
| ) | [static] |
Function extracts file name from file path. If extraction was not successfull, then FilePath is placed in FileName.
| FilePath | - Path to file. | |
| FileName | - File name. |
| nitro::exception | Throws exception with error description. |
Definition at line 93 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::ZIPAbstraction::AddFile(), nitro::ProcessAbstraction::CreateProcess(), ExplodePath(), nitro::UnTARAbstraction::ExtractFile(), ExtractFileName(), and nitro::UnZIPAbstraction::UnZIPFile().
{
try
{
int i( ( int )strlen( FilePath ) - 1 );
FileName[ 0 ] = '\0';
for( ; i >= 0 ; i-- )
{
if( FilePath[ i ] == '/' || FilePath[ i ] == '\\' )
{
goto end_loop;
}
}
// типа не удалось выделить имя файла
strcpy( FileName , FilePath );
return( FileName );
end_loop:;
// выделяем имя файла
strncpy( FileName , & FilePath[ i + 1 ] , strlen( FilePath ) - i );
return( FileName );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileName( const char * FilePath , char * FileName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFileName( const char * FilePath , char * FileName )::An error occured" ) , 1 ) );
}
}

| str_type nitro::FSPath::ExtractFilePath | ( | const str_type & | FilePath | ) | [static] |
Function extracts path to file from file path.
| FilePath | - Path to file (including file name). |
| nitro::exception | Throws exception with error description. |
Definition at line 427 of file string_utilities.h.
References nitro::exception::code(), ExtractFilePath(), and nitro::exception::what().
{
try
{
char * CharChain( new char[ FilePath.length() + 2 ] );
memset( CharChain , 0 , FilePath.length() + 2 );
str_type RetString( ExtractFilePath( FilePath.c_str() , CharChain ) );
delete [] CharChain;
return( RetString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFilePath( const str_type & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFilePath( const str_type & FilePath )::An error occured" ) , 0 ) );
}
}

| char * nitro::FSPath::ExtractFilePath | ( | const char * | FilePath, | |
| char * | ClearedFilePath | |||
| ) | [static] |
Function extracts path to file from file path.
| FilePath | - Path to file (including file name). | |
| ClearedFilePath | - Path to file (excluding file name, ending slash is cut). |
| nitro::exception | Throws exception with error description. |
Definition at line 58 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by ExplodePath(), ExtractFilePath(), nitro::Directory::ForceCreateDirectory(), and nitro::File::ForceCreateFile().
{
try
{
int i( ( int )strlen( FilePath ) - 1 );
ClearedFilePath[ 0 ] = '\0';
for( ; i >= 0 ; i-- )
{
if( FilePath[ i ] == '/' || FilePath[ i ] == '\\' )
{
goto end_loop;
}
}
end_loop:;
if( i >= 0 )
{
strncpy( ClearedFilePath , FilePath , i );
ClearedFilePath[ i ] = '\0';
}
else
{
ClearedFilePath[ 0 ] = '\0';
}
return( ClearedFilePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractFilePath( const char * FilePath , char * ClearedFilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractFilePath( const char * FilePath , char * ClearedFilePath )::An error occured" ) , 1 ) );
}
}

| str_type nitro::FSPath::ExtractModuleName | ( | const str_type & | FileName | ) | [static] |
Function extracts module name from pair [module name].[extention].
| FileName | - File name. |
| nitro::exception | Throws exception with error description. |
Definition at line 476 of file string_utilities.h.
References nitro::exception::code(), ExtractModuleName(), and nitro::exception::what().
{
try
{
char * CharChain( new char[ FileName.length() + 1 ] );
memset( CharChain , 0 , FileName.length() + 1 );
ExtractModuleName( FileName.c_str() , CharChain );
str_type RetString( CharChain );
delete [] CharChain;
return( RetString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractModuleName( const str_type & FileName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractModuleName( const str_type & FileName )::An error occured" ) , 0 ) );
}
}

| void nitro::FSPath::ExtractModuleName | ( | const char * | file_name, | |
| char * | module_name | |||
| ) | [static] |
Function extracts module name from pair [module name].[extention].
| file_name | - File name. | |
| module_name | - Module name. |
| nitro::exception | Throws exception with error description. |
Definition at line 128 of file string_utilities.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by ExtractModuleName().
{
try
{
int i( ( int )strlen( file_name ) - 1 );
module_name[ 0 ] = '\0';
for( ; i >= 0 ; i-- )
{
if( file_name[ i ] == '.' )
{
goto end_loop;
}
}
end_loop:;
strncpy( module_name , file_name , i );
module_name[ i ] = '\0';
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "FSPath::ExtractModuleName( const char * file_name , char * module_name )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "FSPath::ExtractModuleName( const char * file_name , char * module_name )::An error occured" ) , 1 ) );
}
}

1.6.1