From: Vadim Zeitlin Date: Sat, 9 Mar 2013 15:08:36 +0000 (+0000) Subject: Return false from wxFileName::AppendDir() and InsertDir() on failure. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6aa4e3989fe770fc7293770ed46604e7d5b9fb99 Return false from wxFileName::AppendDir() and InsertDir() on failure. Give the caller a way to know whether the directory was valid or not. Closes #15091. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73631 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/filename.h b/include/wx/filename.h index f580d1d494..7ef9e2f93d 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -490,9 +490,9 @@ public: // Dir accessors size_t GetDirCount() const { return m_dirs.size(); } - void AppendDir(const wxString& dir); + bool AppendDir(const wxString& dir); void PrependDir(const wxString& dir); - void InsertDir(size_t before, const wxString& dir); + bool InsertDir(size_t before, const wxString& dir); void RemoveDir(size_t pos); void RemoveLastDir() { RemoveDir(GetDirCount() - 1); } diff --git a/interface/wx/filename.h b/interface/wx/filename.h index c7360e8694..beeb7ff7dd 100644 --- a/interface/wx/filename.h +++ b/interface/wx/filename.h @@ -337,12 +337,17 @@ public: wxPathFormat format = wxPATH_NATIVE); /** - Appends a directory component to the path. This component should contain a - single directory name level, i.e. not contain any path or volume separators nor - should it be empty, otherwise the function does nothing (and generates an - assert failure in debug build). + Appends a directory component to the path. + + This component should contain a single directory name level, i.e. not + contain any path or volume separators nor should it be empty, otherwise + the function does nothing and returns false (and generates an assert + failure in debug build). + + Notice that the return value is only available in wxWidgets 2.9.5 or + later. */ - void AppendDir(const wxString& dir); + bool AppendDir(const wxString& dir); /** Creates the file name from another filename object. @@ -841,10 +846,16 @@ public: bool HasVolume() const; /** - Inserts a directory component before the zero-based position in the directory - list. Please see AppendDir() for important notes. + Inserts a directory component before the zero-based position in the + directory list. + + As with AppendDir(), @a dir must be a single directory name and the + function returns @false and does nothing else if it isn't. + + Notice that the return value is only available in wxWidgets 2.9.5 or + later. */ - void InsertDir(size_t before, const wxString& dir); + bool InsertDir(size_t before, const wxString& dir); /** Returns @true if this filename is absolute. diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 6ffcbf1288..6a40c2e74d 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -2034,10 +2034,12 @@ wxFileName::IsMSWUniqueVolumeNamePath(const wxString& path, wxPathFormat format) return true; } -void wxFileName::AppendDir( const wxString& dir ) +bool wxFileName::AppendDir( const wxString& dir ) { - if ( IsValidDirComponent(dir) ) - m_dirs.Add( dir ); + if (!IsValidDirComponent(dir)) + return false; + m_dirs.Add(dir); + return true; } void wxFileName::PrependDir( const wxString& dir ) @@ -2045,10 +2047,12 @@ void wxFileName::PrependDir( const wxString& dir ) InsertDir(0, dir); } -void wxFileName::InsertDir(size_t before, const wxString& dir) +bool wxFileName::InsertDir(size_t before, const wxString& dir) { - if ( IsValidDirComponent(dir) ) - m_dirs.Insert(dir, before); + if (!IsValidDirComponent(dir)) + return false; + m_dirs.Insert(dir, before); + return true; } void wxFileName::RemoveDir(size_t pos)