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) );
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);
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.
*/
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
}
}
+/* static */
+wxString wxFileName::StripExtension(const wxString& fullpath)
+{
+ wxFileName fn(fullpath);
+ fn.SetExt("");
+ return fn.GetFullPath();
+}
+
// ----------------------------------------------------------------------------
// time functions
// ----------------------------------------------------------------------------
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__