]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed Assign(fullpath, fullname)
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Dec 2001 01:14:09 +0000 (01:14 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Dec 2001 01:14:09 +0000 (01:14 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/filename.tex
include/wx/filename.h
samples/console/console.cpp
src/common/filename.cpp

index 4769f24b3815ccf117bae361b4d5487d8b03171c..aead365877d31f51e6f2d5741c1fd055ae517e46 100644 (file)
@@ -173,7 +173,11 @@ Constructor from a directory name and a file name.
 
 \func{}{wxFileName}{\param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
 
-Constructor from a directory name, file base name and extension
+Constructor from a directory name, base file name and extension
+
+\func{}{wxFileName}{\param{const wxString\& }{volume}, \param{const wxString\& }{path}, \param{const wxString\& }{name}, \param{const wxString\& }{ext}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
+
+Constructor from a volume name, a directory name, base file name and extension
 
 \membersection{wxFileName::AppendDir}\label{wxfilenameappenddir}
 
@@ -208,15 +212,14 @@ volume (or current volume if {\it volume} is empty).
 
 \func{void}{AssignDir}{\param{const wxString\& }{dir}, \param{wxPathFormat }{format = wxPATH\_NATIVE}}
 
-empty volume
-
+Set this file name object to the given directory name. The name and extension
+will be empty.
 
 \membersection{wxFileName::AssignHomeDir}\label{wxfilenameassignhomedir}
 
 \func{void}{AssignHomeDir}{\void}
 
-get the value of user home (Unix only mainly)
-
+Set this file name object to the home directory.
 
 \membersection{wxFileName::AssignTempFileName}\label{wxfilenameassigntempfilename}
 
index 0b8bec879f3aaa71429e790fb3877b5df1f2974a..0c51ce5c0c2dd4d998c58aae3a90632d2539e4b7 100644 (file)
@@ -96,6 +96,14 @@ public:
                wxPathFormat format = wxPATH_NATIVE)
         { Assign(path, name, format); }
 
+        // from a volume, directory name, file base name and extension
+    wxFileName(const wxString& volume,
+               const wxString& path,
+               const wxString& name,
+               const wxString& ext,
+               wxPathFormat format = wxPATH_NATIVE)
+        { Assign(volume, path, name, ext, format); }
+
         // from a directory name, file base name and extension
     wxFileName(const wxString& path,
                const wxString& name,
index 051b4e253db50cf0dc8e27a2237436dd14ed9692..1ba917e1d07757a50705f41700eb31e401323cfd 100644 (file)
@@ -740,6 +740,17 @@ static void TestFileConfRead()
 
 #include "wx/filename.h"
 
+static void DumpFileName(const wxFileName& fn)
+{
+    wxString full = fn.GetFullPath();
+
+    wxString vol, path, name, ext;
+    wxFileName::SplitPath(full, &vol, &path, &name, &ext);
+
+    wxPrintf(_T("Filename '%s' -> vol '%s', path '%s', name '%s', ext '%s'\n"),
+             full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
+}
+
 static struct FileNameInfo
 {
     const wxChar *fullname;
@@ -5216,11 +5227,19 @@ int main(int argc, char **argv)
 #endif // TEST_FILE
 
 #ifdef TEST_FILENAME
-    TestFileNameTemp();
+    if ( 0 )
+    {
+        wxFileName fn;
+        fn.Assign("c:\\foo", "bar.baz");
+
+        DumpFileName(fn);
+    }
+
     if ( 0 )
     {
     TestFileNameConstruction();
     TestFileNameSplit();
+    TestFileNameTemp();
         TestFileNameCwd();
         TestFileNameComparison();
         TestFileNameOperations();
index 06d24ccd2f6b7eea38c38aeb47f69013b30de6d0..3b45c14c03781b2a67f096b0ba0d0d08cc97be0a 100644 (file)
@@ -247,27 +247,46 @@ void wxFileName::Assign(const wxString& fullpath,
     Assign(volume, path, name, ext, format);
 }
 
-void wxFileName::Assign(const wxString& fullpath,
+void wxFileName::Assign(const wxString& fullpathOrig,
                         const wxString& fullname,
                         wxPathFormat format)
 {
+    // always recognize fullpath as directory, even if it doesn't end with a
+    // slash
+    wxString fullpath = fullpathOrig;
+    if ( !wxEndsWithPathSeparator(fullpath) )
+    {
+        fullpath += GetPathSeparators(format)[0u];
+    }
+
     wxString volume, path, name, ext;
+
+    // do some consistency checks in debug mode: the name should be really just
+    // the filename and the path should be realyl just a path
+#ifdef __WXDEBUG__
+    wxString pathDummy, nameDummy, extDummy;
+
+    SplitPath(fullname, &pathDummy, &name, &ext, format);
+
+    wxASSERT_MSG( pathDummy.empty(),
+                  _T("the file name shouldn't contain the path") );
+
+    SplitPath(fullpath, &volume, &path, &nameDummy, &extDummy, format);
+
+    wxASSERT_MSG( nameDummy.empty() && extDummy.empty(),
+                  _T("the path shouldn't contain file name nor extension") );
+
+#else // !__WXDEBUG__
     SplitPath(fullname, NULL /* no path */, &name, &ext, format);
     SplitPath(fullpath, &volume, &path, NULL, NULL, format);
+#endif // __WXDEBUG__/!__WXDEBUG__
 
     Assign(volume, path, name, ext, format);
 }
 
 void wxFileName::AssignDir(const wxString& dir, wxPathFormat format)
 {
-    // always recognize dir as directory, even if it doesn't end with a slash
-    wxString dirname = dir;
-    if ( !wxEndsWithPathSeparator(dirname) )
-    {
-        dirname += GetPathSeparators(format)[0u];
-    }
-
-    Assign(dirname, _T(""), format);
+    Assign(dir, _T(""), format);
 }
 
 void wxFileName::Clear()