implement deprecated wxStripExtension() in terms of new wxFileName::StripExtension() (closes #10634)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59868 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-03-26 15:55:01 +00:00
parent 62714742f3
commit 181dd701fa
6 changed files with 42 additions and 37 deletions

View File

@ -555,10 +555,11 @@ wxDEPRECATED_BUT_USED_INTERNALLY(
WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
// Strip the extension, in situ
// Deprecated in favour of wxFileName::StripExtension() but notice that their
// behaviour is slightly different, see the manual
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
// DEPRECATED: construct a wxFileName, use ClearExt() and then GetFullPath()
// Get a temporary filename
wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );

View File

@ -519,6 +519,9 @@ public:
wxString *path,
wxPathFormat format = wxPATH_NATIVE);
// Strip the file extension
static wxString StripExtension(const wxString& fullpath);
#ifdef wxHAS_FILESYSTEM_VOLUMES
// return the string representing a file system volume, or drive
static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);

View File

@ -1137,6 +1137,28 @@ public:
wxString* path,
wxPathFormat format = wxPATH_NATIVE);
/**
Strip the file extension.
This function does more than just removing everything after the last
period from the string, for example it will return the string ".vimrc"
unchanged because the part after the period is not an extension but the
file name in this case. You can use wxString::BeforeLast() to really
get just the part before the last period (but notice that that function
returns empty string if period is not present at all unlike this
function which returns the @a fullname unchanged in this case).
@param fullname
File path including name and, optionally, extension.
@return
File path without extension
@since 2.9.0
*/
static wxString StripExtension(const wxString& fullname);
/**
Sets the access and modification times to the current moment.
*/

View File

@ -384,16 +384,7 @@ void wxStripExtension(wchar_t *buffer) { wxDoStripExtension(buffer); }
void wxStripExtension(wxString& buffer)
{
//RN: Be careful about the handling the case where
//buffer.length() == 0
for(size_t i = buffer.length() - 1; i != wxString::npos; --i)
{
if (buffer.GetChar(i) == wxT('.'))
{
buffer = buffer.Left(i);
break;
}
}
buffer = wxFileName::StripExtension(buffer);
}
// Destructive removal of /./ and /../ stuff

View File

@ -2261,6 +2261,14 @@ void wxFileName::SplitPath(const wxString& fullpath,
}
}
/* static */
wxString wxFileName::StripExtension(const wxString& fullpath)
{
wxFileName fn(fullpath);
fn.SetExt("");
return fn.GetFullPath();
}
// ----------------------------------------------------------------------------
// time functions
// ----------------------------------------------------------------------------

View File

@ -454,35 +454,15 @@ void FileNameTestCase::TestReplace()
fn.GetFullPath(wxPATH_UNIX) );
}
#if WXWIN_COMPATIBILITY_2_8
#ifdef __VISUALC__
// disable warning about using deprecated wxStripExtension()
#pragma warning(disable:4996)
#endif
wxString wxTestStripExtension(wxString szFile)
{
wxStripExtension(szFile);
return szFile;
}
#ifdef __VISUALC__
#pragma warning(default:4996)
#endif
void FileNameTestCase::TestStrip()
{
//test a crash
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T("")) );
//others
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".")) );
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".wav")) );
CPPUNIT_ASSERT_EQUAL( wxString(_T("good")), wxTestStripExtension(_T("good.wav")) );
CPPUNIT_ASSERT_EQUAL( wxString(_T("good.wav")), wxTestStripExtension(_T("good.wav.wav")) );
CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension(_T("")) );
CPPUNIT_ASSERT_EQUAL( ".", wxFileName::StripExtension(_T(".")) );
CPPUNIT_ASSERT_EQUAL( ".vimrc", wxFileName::StripExtension(_T(".vimrc")) );
CPPUNIT_ASSERT_EQUAL( "bad", wxFileName::StripExtension(_T("bad")) );
CPPUNIT_ASSERT_EQUAL( "good", wxFileName::StripExtension(_T("good.wav")) );
CPPUNIT_ASSERT_EQUAL( "good.wav", wxFileName::StripExtension(_T("good.wav.wav")) );
}
#endif // WXWIN_COMPATIBILITY_2_8
#ifdef __WINDOWS__