From 81f256328c32766ebf9fca0a97b03bb53e24bc6b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 4 Dec 2001 01:14:09 +0000 Subject: [PATCH] fixed Assign(fullpath, fullname) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/filename.tex | 13 ++++++++----- include/wx/filename.h | 8 ++++++++ samples/console/console.cpp | 21 ++++++++++++++++++++- src/common/filename.cpp | 37 ++++++++++++++++++++++++++++--------- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/docs/latex/wx/filename.tex b/docs/latex/wx/filename.tex index 4769f24b38..aead365877 100644 --- a/docs/latex/wx/filename.tex +++ b/docs/latex/wx/filename.tex @@ -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} diff --git a/include/wx/filename.h b/include/wx/filename.h index 0b8bec879f..0c51ce5c0c 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -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, diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 051b4e253d..1ba917e1d0 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -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(); diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 06d24ccd2f..3b45c14c03 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -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() -- 2.45.2