implement FileInfo::completeExtension
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Base;
|
||||
|
||||
@@ -280,6 +282,14 @@ std::string FileInfo::extension () const
|
||||
return FileName.substr(pos+1);
|
||||
}
|
||||
|
||||
std::string FileInfo::completeExtension () const
|
||||
{
|
||||
std::string::size_type pos = FileName.find_first_of('.');
|
||||
if (pos == std::string::npos)
|
||||
return std::string();
|
||||
return FileName.substr(pos+1);
|
||||
}
|
||||
|
||||
bool FileInfo::hasExtension (const char* Ext) const
|
||||
{
|
||||
#if defined (FC_OS_WIN32)
|
||||
@@ -469,6 +479,10 @@ bool FileInfo::renameFile(const char* NewName)
|
||||
#else
|
||||
# error "FileInfo::renameFile() not implemented for this platform!"
|
||||
#endif
|
||||
if (!res) {
|
||||
int code = errno;
|
||||
std::clog << "Error in renameFile: " << strerror(code) << " (" << code << ")" << std::endl;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -69,20 +69,24 @@ public:
|
||||
std::string fileNamePure () const;
|
||||
/// Convert the path name into a UCS-2 encoded wide string format.
|
||||
std::wstring toStdWString() const;
|
||||
/** Returns the file's extension name.
|
||||
* If complete is true (the default), extension() returns the string of all
|
||||
* characters in the file name after (but not including) the first '.' character.
|
||||
* If complete is false, extension() returns the string of all characters in
|
||||
* the file name after (but not including) the last '.' character.
|
||||
* Example:
|
||||
/** Returns the extension of the file.
|
||||
* The extension consists of all characters in the file after (but not including)
|
||||
* the last '.' character.
|
||||
*@code
|
||||
* FileInfo fi( "/tmp/archive.tar.gz" );
|
||||
* std::string ext = fi.extension(true); // ext = "tar.gz"
|
||||
* ext = fi.extension(false); // ext = "gz"
|
||||
* ext = fi.extension(); // ext = "gz"
|
||||
*@endcode
|
||||
*/
|
||||
std::string extension () const;
|
||||
/** Returns the complete extension of the file.
|
||||
* The complete extension consists of all characters in the file after (but not including)
|
||||
* the first '.' character.
|
||||
*@code
|
||||
* FileInfo fi( "/tmp/archive.tar.gz" );
|
||||
* ext = fi.completeExtension(); // ext = "tar.gz"
|
||||
*@endcode
|
||||
*/
|
||||
std::string completeExtension () const;
|
||||
/// Checks for a special extension, NOT case sensetive
|
||||
bool hasExtension (const char* Ext) const;
|
||||
//@}
|
||||
|
||||
Reference in New Issue
Block a user