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
This commit is contained in:
Vadim Zeitlin
2013-03-09 15:08:36 +00:00
parent 29cc4cc9bc
commit 6aa4e3989f
3 changed files with 31 additions and 16 deletions

View File

@@ -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); }

View File

@@ -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.

View File

@@ -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)