rewrite wxContractPath as wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir; add test units and docs for them

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57867 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-01-07 00:38:46 +00:00
parent eadd3970f2
commit 395f3aa8bd
4 changed files with 196 additions and 2 deletions

View File

@@ -1152,7 +1152,6 @@ bool wxFileName::Normalize(int flags,
}
}
// the existing path components
wxArrayString dirs = GetDirs();
@@ -1302,6 +1301,49 @@ bool wxFileName::Normalize(int flags,
return true;
}
#ifndef __WXWINCE__
bool wxFileName::ReplaceEnvVariable(const wxString& envname,
const wxString& replacementFmtString,
wxPathFormat format)
{
// look into stringForm for the contents of the given environment variable
wxString val;
if (envname.empty() ||
!wxGetEnv(envname, &val))
return false;
if (val.empty())
return false;
wxString stringForm = GetPath(wxPATH_GET_VOLUME, format);
// do not touch the file name and the extension
wxString replacement = wxString::Format(replacementFmtString, envname);
stringForm.Replace(val, replacement);
// Now assign ourselves the modified path:
Assign(stringForm, GetFullName(), format);
return true;
}
#endif
bool wxFileName::ReplaceHomeDir(wxPathFormat format)
{
wxString homedir = wxGetHomeDir();
if (homedir.empty())
return false;
wxString stringForm = GetPath(wxPATH_GET_VOLUME, format);
// do not touch the file name and the extension
stringForm.Replace(homedir, "~");
// Now assign ourselves the modified path:
Assign(stringForm, GetFullName(), format);
return true;
}
// ----------------------------------------------------------------------------
// get the shortcut target
// ----------------------------------------------------------------------------