Use wxFileName::MakeAbsolute() instead of Normalize()

Make the code more clear by being more explicit about what it does.

No real changes and no changes in behaviour at all.
This commit is contained in:
Vadim Zeitlin
2021-07-11 13:19:40 +01:00
parent 1f2413c461
commit 6d2af9e7a1
4 changed files with 15 additions and 15 deletions

View File

@@ -361,7 +361,7 @@ public:
bool MakeRelativeTo(const wxString& pathBase = wxEmptyString, bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
wxPathFormat format = wxPATH_NATIVE); wxPathFormat format = wxPATH_NATIVE);
// make the path absolute // make the path absolute and resolve any "." and ".." in it
// //
// this may be done using another (than current) value of cwd // this may be done using another (than current) value of cwd
bool MakeAbsolute(const wxString& cwd = wxEmptyString, bool MakeAbsolute(const wxString& cwd = wxEmptyString,

View File

@@ -575,15 +575,15 @@ MyFrame::MyFrame()
m_fileHistory->UseMenu(m_fileHistoryMenu); m_fileHistory->UseMenu(m_fileHistoryMenu);
wxFileName fn( "menu.cpp" ); wxFileName fn( "menu.cpp" );
fn.Normalize(); fn.MakeAbsolute();
m_fileHistory->AddFileToHistory( fn.GetFullPath() ); m_fileHistory->AddFileToHistory( fn.GetFullPath() );
fn = "Makefile.in"; fn = "Makefile.in";
fn.Normalize(); fn.MakeAbsolute();
m_fileHistory->AddFileToHistory( fn.GetFullPath() ); m_fileHistory->AddFileToHistory( fn.GetFullPath() );
fn.Assign("minimal", "minimal", "cpp"); fn.Assign("minimal", "minimal", "cpp");
fn.Normalize(); fn.MakeAbsolute();
m_fileHistory->AddFileToHistory( fn.GetFullPath() ); m_fileHistory->AddFileToHistory( fn.GetFullPath() );
fileMenu->AppendSubMenu(m_fileHistoryMenu, "Sample file history"); fileMenu->AppendSubMenu(m_fileHistoryMenu, "Sample file history");

View File

@@ -1765,14 +1765,14 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
// get cwd only once - small time saving // get cwd only once - small time saving
wxString cwd = wxGetCwd(); wxString cwd = wxGetCwd();
// Normalize both paths to be absolute but avoid expanding environment // Bring both paths to canonical form.
// variables in them, this could be unexpected. MakeAbsolute(cwd, format);
const int normFlags = wxPATH_NORM_DOTS | fnBase.MakeAbsolute(cwd, format);
wxPATH_NORM_TILDE |
wxPATH_NORM_ABSOLUTE | // Do this here for compatibility, as we used to do it before.
wxPATH_NORM_LONG; Normalize(wxPATH_NORM_LONG, cwd, format);
Normalize(normFlags, cwd, format); fnBase.Normalize(wxPATH_NORM_LONG, cwd, format);
fnBase.Normalize(normFlags, cwd, format);
bool withCase = IsCaseSensitive(format); bool withCase = IsCaseSensitive(format);
@@ -2620,7 +2620,7 @@ static wxString EscapeFileNameCharsInURL(const char *in)
wxString wxFileName::FileNameToURL(const wxFileName& filename) wxString wxFileName::FileNameToURL(const wxFileName& filename)
{ {
wxFileName fn = filename; wxFileName fn = filename;
fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE); fn.MakeAbsolute();
wxString url = fn.GetFullPath(wxPATH_NATIVE); wxString url = fn.GetFullPath(wxPATH_NATIVE);
#ifndef __UNIX__ #ifndef __UNIX__

View File

@@ -201,8 +201,8 @@ TEST_CASE("wxFileName::Comparison", "[filename]")
{ {
wxFileName fn1(wxT("/tmp/file1")); wxFileName fn1(wxT("/tmp/file1"));
wxFileName fn2(wxT("/tmp/dir2/../file2")); wxFileName fn2(wxT("/tmp/dir2/../file2"));
fn1.Normalize(); fn1.MakeAbsolute();
fn2.Normalize(); fn2.MakeAbsolute();
CHECK(fn1.GetPath() == fn2.GetPath()); CHECK(fn1.GetPath() == fn2.GetPath());
} }