]> git.saurik.com Git - wxWidgets.git/commitdiff
Recognize UNCs starting with forward slashes too in wxFileName.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 5 Nov 2009 14:59:39 +0000 (14:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 5 Nov 2009 14:59:39 +0000 (14:59 +0000)
Treat \\share\path and //share/path in the same way (for wxPATH_DOS paths).

Add a test for UNC parsing to the unit test.

Closes #11376.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62561 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/filename.cpp
tests/filename/filenametest.cpp

index 2a8092dfed49e667033e69b81e7bc14f17c1b21f..09b03c625187214cb7ba9a1758a570f3666515ed 100644 (file)
 extern const wxULongLong wxInvalidSize = (unsigned)-1;
 #endif // wxUSE_LONGLONG
 
+namespace
+{
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -295,17 +297,26 @@ static wxString wxGetVolumeString(const wxString& volume, wxPathFormat format)
     return path;
 }
 
+// return true if the character is a DOS path separator i.e. either a slash or
+// a backslash
+inline bool IsDOSPathSep(wxUniChar ch)
+{
+    return ch == wxFILE_SEP_PATH_DOS || ch == wxFILE_SEP_PATH_UNIX;
+}
+
 // return true if the format used is the DOS/Windows one and the string looks
 // like a UNC path
 static bool IsUNCPath(const wxString& path, wxPathFormat format)
 {
     return format == wxPATH_DOS &&
                 path.length() >= 4 && // "\\a" can't be a UNC path
-                    path[0u] == wxFILE_SEP_PATH_DOS &&
-                        path[1u] == wxFILE_SEP_PATH_DOS &&
-                            path[2u] != wxFILE_SEP_PATH_DOS;
+                    IsDOSPathSep(path[0u]) &&
+                        IsDOSPathSep(path[1u]) &&
+                            !IsDOSPathSep(path[2u]);
 }
 
+} // anonymous namespace
+
 // ============================================================================
 // implementation
 // ============================================================================
index eefd5ffd62f16f9e5fcf310aba1de87ae2bab2e9..8039d2f80b66bce1c47990cdb0420c3c6985c35d 100644 (file)
@@ -124,6 +124,7 @@ private:
 #ifdef __WINDOWS__
         CPPUNIT_TEST( TestShortLongPath );
 #endif // __WINDOWS__
+        CPPUNIT_TEST( TestUNC );
     CPPUNIT_TEST_SUITE_END();
 
     void TestConstruction();
@@ -136,6 +137,7 @@ private:
 #ifdef __WINDOWS__
     void TestShortLongPath();
 #endif // __WINDOWS__
+    void TestUNC();
 
     DECLARE_NO_COPY_CLASS(FileNameTestCase)
 };
@@ -493,3 +495,15 @@ void FileNameTestCase::TestShortLongPath()
 }
 
 #endif // __WINDOWS__
+
+void FileNameTestCase::TestUNC()
+{
+    wxFileName fn("//share/path/name.ext", wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "share", fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "/path", fn.GetPath() );
+
+    fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "share2", fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "/path2", fn.GetPath() );
+}
+