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:
parent
62714742f3
commit
181dd701fa
@ -555,10 +555,11 @@ wxDEPRECATED_BUT_USED_INTERNALLY(
|
|||||||
WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
|
WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
|
||||||
|
|
||||||
// Strip the extension, in situ
|
// 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(char *buffer) );
|
||||||
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
|
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
|
||||||
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
|
wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
|
||||||
// DEPRECATED: construct a wxFileName, use ClearExt() and then GetFullPath()
|
|
||||||
|
|
||||||
// Get a temporary filename
|
// Get a temporary filename
|
||||||
wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
|
wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
|
||||||
|
@ -519,6 +519,9 @@ public:
|
|||||||
wxString *path,
|
wxString *path,
|
||||||
wxPathFormat format = wxPATH_NATIVE);
|
wxPathFormat format = wxPATH_NATIVE);
|
||||||
|
|
||||||
|
// Strip the file extension
|
||||||
|
static wxString StripExtension(const wxString& fullpath);
|
||||||
|
|
||||||
#ifdef wxHAS_FILESYSTEM_VOLUMES
|
#ifdef wxHAS_FILESYSTEM_VOLUMES
|
||||||
// return the string representing a file system volume, or drive
|
// return the string representing a file system volume, or drive
|
||||||
static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
|
static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
|
||||||
|
@ -1137,6 +1137,28 @@ public:
|
|||||||
wxString* path,
|
wxString* path,
|
||||||
wxPathFormat format = wxPATH_NATIVE);
|
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.
|
Sets the access and modification times to the current moment.
|
||||||
*/
|
*/
|
||||||
|
@ -384,16 +384,7 @@ void wxStripExtension(wchar_t *buffer) { wxDoStripExtension(buffer); }
|
|||||||
|
|
||||||
void wxStripExtension(wxString& buffer)
|
void wxStripExtension(wxString& buffer)
|
||||||
{
|
{
|
||||||
//RN: Be careful about the handling the case where
|
buffer = wxFileName::StripExtension(buffer);
|
||||||
//buffer.length() == 0
|
|
||||||
for(size_t i = buffer.length() - 1; i != wxString::npos; --i)
|
|
||||||
{
|
|
||||||
if (buffer.GetChar(i) == wxT('.'))
|
|
||||||
{
|
|
||||||
buffer = buffer.Left(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructive removal of /./ and /../ stuff
|
// Destructive removal of /./ and /../ stuff
|
||||||
|
@ -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
|
// time functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -454,35 +454,15 @@ void FileNameTestCase::TestReplace()
|
|||||||
fn.GetFullPath(wxPATH_UNIX) );
|
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()
|
void FileNameTestCase::TestStrip()
|
||||||
{
|
{
|
||||||
//test a crash
|
CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension(_T("")) );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T("")) );
|
CPPUNIT_ASSERT_EQUAL( ".", wxFileName::StripExtension(_T(".")) );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( ".vimrc", wxFileName::StripExtension(_T(".vimrc")) );
|
||||||
//others
|
CPPUNIT_ASSERT_EQUAL( "bad", wxFileName::StripExtension(_T("bad")) );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".")) );
|
CPPUNIT_ASSERT_EQUAL( "good", wxFileName::StripExtension(_T("good.wav")) );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".wav")) );
|
CPPUNIT_ASSERT_EQUAL( "good.wav", wxFileName::StripExtension(_T("good.wav.wav")) );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(_T("good")), wxTestStripExtension(_T("good.wav")) );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(_T("good.wav")), wxTestStripExtension(_T("good.wav.wav")) );
|
|
||||||
}
|
}
|
||||||
#endif // WXWIN_COMPATIBILITY_2_8
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user