implement FileInfo::completeExtension

This commit is contained in:
wmayer
2017-10-24 19:38:01 +02:00
parent cfe2d134a2
commit 16e6d887e7
2 changed files with 26 additions and 8 deletions

View File

@@ -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;
}

View File

@@ -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;
//@}