Allow to skip extensions of filenames.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1541 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-09-05 16:35:10 +00:00
parent ec4d244224
commit 60f1955826
4 changed files with 17 additions and 6 deletions

View File

@ -120,7 +120,7 @@ public:
//! Returns the base part of a filename, i.e. the name without the directory
//! part. If no directory is prefixed, the full name is returned.
/** \param filename: The file to get the basename from */
virtual core::stringc getFileBasename(const core::stringc& filename) const = 0;
virtual core::stringc getFileBasename(const core::stringc& filename, bool keepExtension=true) const = 0;
//! Creates a list of files and directories in the current working directory and returns it.
/** \return a Pointer to the created IFileList is returned. After the list has been used

View File

@ -427,7 +427,7 @@ public:
{
if (!str)
return false;
s32 i;
u32 i;
for(i=0; array[i] && str[i] && i < n; ++i)
if (array[i] != str[i])
return false;

View File

@ -241,15 +241,26 @@ core::stringc CFileSystem::getFileDir(const core::stringc& filename) const
//! returns the base part of a filename, i.e. all except for the directory
//! part. If no directory path is prefixed, the full name is returned.
core::stringc CFileSystem::getFileBasename(const core::stringc& filename) const
core::stringc CFileSystem::getFileBasename(const core::stringc& filename, bool keepExtension) const
{
// find last forward or backslash
s32 lastSlash = filename.findLast('/');
const s32 lastBackSlash = filename.findLast('\\');
lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
lastSlash = core::max_(lastSlash, lastBackSlash);
s32 end = 0;
if (!keepExtension)
{
end = filename.findLast('.');
if (end == -1)
end=0;
else
end = filename.size()-end;
}
if ((u32)lastSlash < filename.size())
return filename.subString(lastSlash+1, filename.size()-lastSlash);
return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end);
else if (end != 0)
return filename.subString(0, filename.size()-end);
else
return filename;
}

View File

@ -65,7 +65,7 @@ public:
//! Returns the base part of a filename, i.e. the name without the directory
//! part. If no directory is prefixed, the full name is returned.
/** \param filename: The file to get the basename from */
core::stringc getFileBasename(const core::stringc& filename) const;
core::stringc getFileBasename(const core::stringc& filename, bool keepExtension=true) const;
//! Creates a list of files and directories in the current working directory
//! and returns it.