]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for mistakenly prepending slash to the filenames without paths (bug introduced...
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 21 Oct 2003 22:45:28 +0000 (22:45 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 21 Oct 2003 22:45:28 +0000 (22:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24242 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/filename.cpp

index 757bba49a8bf58b855e776256bbd756057945dda..4b0278f2c355a0cfd132ecf55c87f0a0246f281f 100644 (file)
@@ -1261,102 +1261,99 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const
         fullpath += wxGetVolumeString(GetVolume(), format);
     }
 
-    const size_t dirCount = m_dirs.GetCount();
-    if ( dirCount )
+    // the leading character
+    switch ( format )
     {
-        // the leading character
-        switch ( format )
-        {
-            case wxPATH_MAC:
-                if ( m_relative )
-                    fullpath += wxFILE_SEP_PATH_MAC;
-                break;
+        case wxPATH_MAC:
+            if ( m_relative )
+                fullpath += wxFILE_SEP_PATH_MAC;
+            break;
 
-            case wxPATH_DOS:
-                if ( !m_relative )
-                    fullpath += wxFILE_SEP_PATH_DOS;
-                break;
+        case wxPATH_DOS:
+            if ( !m_relative )
+                fullpath += wxFILE_SEP_PATH_DOS;
+            break;
 
-            default:
-                wxFAIL_MSG( wxT("Unknown path format") );
-                // fall through
+        default:
+            wxFAIL_MSG( wxT("Unknown path format") );
+            // fall through
 
-            case wxPATH_UNIX:
-                if ( !m_relative )
+        case wxPATH_UNIX:
+            if ( !m_relative )
+            {
+                // normally the absolute file names start with a slash
+                // with one exception: the ones like "~/foo.bar" don't
+                // have it
+                if ( m_dirs[0u] != _T('~') )
                 {
-                    // normally the absolute file names start with a slash
-                    // with one exception: the ones like "~/foo.bar" don't
-                    // have it
-                    if ( m_dirs[0u] != _T('~') )
-                    {
-                        fullpath += wxFILE_SEP_PATH_UNIX;
-                    }
+                    fullpath += wxFILE_SEP_PATH_UNIX;
                 }
-                break;
+            }
+            break;
 
-            case wxPATH_VMS:
-                // no leading character here but use this place to unset
-                // wxPATH_GET_SEPARATOR flag: under VMS it doesn't make sense
-                // as, if I understand correctly, there should never be a dot
-                // before the closing bracket
-                flags &= ~wxPATH_GET_SEPARATOR;
-        }
+        case wxPATH_VMS:
+            // no leading character here but use this place to unset
+            // wxPATH_GET_SEPARATOR flag: under VMS it doesn't make sense
+            // as, if I understand correctly, there should never be a dot
+            // before the closing bracket
+            flags &= ~wxPATH_GET_SEPARATOR;
+    }
 
-        // then concatenate all the path components using the path separator
-        if ( format == wxPATH_VMS )
-        {
-            fullpath += wxT('[');
-        }
+    if ( m_dirs.empty() )
+    {
+        // there is nothing more
+        return fullpath;
+    }
 
-        for ( size_t i = 0; i < dirCount; i++ )
-        {
-            switch (format)
-            {
-                case wxPATH_MAC:
-                    if ( m_dirs[i] == wxT(".") )
-                    {
-                        // skip appending ':', this shouldn't be done in this
-                        // case as "::" is interpreted as ".." under Unix
-                        continue;
-                    }
+    // then concatenate all the path components using the path separator
+    if ( format == wxPATH_VMS )
+    {
+        fullpath += wxT('[');
+    }
 
-                    // convert back from ".." to nothing
-                    if ( m_dirs[i] != wxT("..") )
-                         fullpath += m_dirs[i];
-                    break;
+    const size_t dirCount = m_dirs.GetCount();
+    for ( size_t i = 0; i < dirCount; i++ )
+    {
+        switch (format)
+        {
+            case wxPATH_MAC:
+                if ( m_dirs[i] == wxT(".") )
+                {
+                    // skip appending ':', this shouldn't be done in this
+                    // case as "::" is interpreted as ".." under Unix
+                    continue;
+                }
 
-                default:
-                    wxFAIL_MSG( wxT("Unexpected path format") );
-                    // still fall through
+                // convert back from ".." to nothing
+                if ( m_dirs[i] != wxT("..") )
+                     fullpath += m_dirs[i];
+                break;
 
-                case wxPATH_DOS:
-                case wxPATH_UNIX:
-                    fullpath += m_dirs[i];
-                    break;
+            default:
+                wxFAIL_MSG( wxT("Unexpected path format") );
+                // still fall through
 
-                case wxPATH_VMS:
-                    // TODO: What to do with ".." under VMS
+            case wxPATH_DOS:
+            case wxPATH_UNIX:
+                fullpath += m_dirs[i];
+                break;
 
-                    // convert back from ".." to nothing
-                    if ( m_dirs[i] != wxT("..") )
-                        fullpath += m_dirs[i];
-                    break;
-            }
+            case wxPATH_VMS:
+                // TODO: What to do with ".." under VMS
 
-            if ( (flags & wxPATH_GET_SEPARATOR) || (i != dirCount - 1) )
-                fullpath += GetPathSeparator(format);
+                // convert back from ".." to nothing
+                if ( m_dirs[i] != wxT("..") )
+                    fullpath += m_dirs[i];
+                break;
         }
 
-        if ( format == wxPATH_VMS )
-        {
-            fullpath += wxT(']');
-        }
+        if ( (flags & wxPATH_GET_SEPARATOR) || (i != dirCount - 1) )
+            fullpath += GetPathSeparator(format);
     }
-    else // no directories
+
+    if ( format == wxPATH_VMS )
     {
-        // still append path separator if requested
-        if ( flags & wxPATH_GET_SEPARATOR )
-            fullpath += GetPathSeparator(format);
+        fullpath += wxT(']');
     }
 
     return fullpath;