]> git.saurik.com Git - wxWidgets.git/commitdiff
implement deprecated wxStripExtension() in terms of new wxFileName::StripExtension...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Mar 2009 15:55:01 +0000 (15:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Mar 2009 15:55:01 +0000 (15:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59868 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/filefn.h
include/wx/filename.h
interface/wx/filename.h
src/common/filefn.cpp
src/common/filename.cpp
tests/filename/filenametest.cpp

index c64db53235fc815dc5572cffcdd493d98da97e4b..427eb1974b6a0f21303f00b908004c89a471d855 100644 (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) );
index 7a7593c6d606bd65ee7fe3b72cffc8cad9b27928..70ebc44ed776148c462a0391208d7f08ed01ecbe 100644 (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);
index fcec3530203046ddb7be86b4158782c3ebf55dc2..72bf9273e895fcbebe67984c04bc22c19660c551 100644 (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.
     */
index b732f23a1c869cbd02541ce34ca67ba755ff50dc..ca0d92a8632fe3c6a28548749b68eff1b8bf1eac 100644 (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
index 7db00dc4a94051bc634f0001290a7ac94dcce413..f16ae7127bf9ab7af950bd6d2e656d52b2bb1371 100644 (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
 // ----------------------------------------------------------------------------
index 9132c0e3eaaa5d26251cb876c417175a23fe3a95..d4a83c2ca33ffb22a0976bfbc5c71f3be996fa4c 100644 (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__