wxSplitPath() bugs corrected and it's documented
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1716 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -239,6 +239,27 @@ The {\it flags} parameter is reserved for future use.
|
|||||||
Sets the current working directory, returning TRUE if the operation succeeded.
|
Sets the current working directory, returning TRUE if the operation succeeded.
|
||||||
Under MS Windows, the current drive is also changed if {\it dir} contains a drive specification.
|
Under MS Windows, the current drive is also changed if {\it dir} contains a drive specification.
|
||||||
|
|
||||||
|
\membersection{::wxSplitPath}\label{wxsplitfunction}
|
||||||
|
|
||||||
|
\func{void}{wxSplitPath}{\param{const char *}{ fullname}, \param{const wxString *}{ path}, \param{const wxString *}{ name}, \param{const wxString *}{ ext}}
|
||||||
|
|
||||||
|
This function splits a full file name into components: the path (including possible disk/drive
|
||||||
|
specification under Windows), the base name and the extension. Any of the output parameters
|
||||||
|
({\it path}, {\it name} or {\it ext}) may be NULL if you are not interested in the value of
|
||||||
|
a particular component.
|
||||||
|
|
||||||
|
wxSplitPath() will correctly handle filenames with both DOS and Unix path separators under
|
||||||
|
Windows, however it will not consider backslashes as path separators under Unix (where backslash
|
||||||
|
is a valid character in a filename).
|
||||||
|
|
||||||
|
On entry, {\it fullname} should be non NULL (it may be empty though).
|
||||||
|
|
||||||
|
On return, {\it path} contains the file path (without the trailing separator), {\it name}
|
||||||
|
contains the file name and {\it ext} contains the file extension without leading dot. All
|
||||||
|
three of them may be empty if the corresponding component is. The old contents of the
|
||||||
|
strings pointed to by these parameters will be overwritten in any case (if the pointers
|
||||||
|
are not NULL).
|
||||||
|
|
||||||
\section{String functions}
|
\section{String functions}
|
||||||
|
|
||||||
\membersection{::copystring}
|
\membersection{::copystring}
|
||||||
|
@@ -1532,40 +1532,55 @@ void WXDLLEXPORT wxSplitPath(const char *pszFileName,
|
|||||||
wxString *pstrName,
|
wxString *pstrName,
|
||||||
wxString *pstrExt)
|
wxString *pstrExt)
|
||||||
{
|
{
|
||||||
wxCHECK_RET( pszFileName, "NULL file name in wxSplitPath" );
|
// it can be empty, but it shouldn't be NULL
|
||||||
|
wxCHECK_RET( pszFileName, "NULL file name in wxSplitPath" );
|
||||||
|
|
||||||
const char *pDot = strrchr(pszFileName, wxFILE_SEP_EXT);
|
const char *pDot = strrchr(pszFileName, wxFILE_SEP_EXT);
|
||||||
const char *pSepUnix = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
|
|
||||||
const char *pSepDos = strrchr(pszFileName, wxFILE_SEP_PATH_DOS);
|
|
||||||
|
|
||||||
// take the last of the two: nPosUnix containts the last slash in the
|
#ifdef __WXMSW__
|
||||||
// filename
|
// under Windows we understand both separators
|
||||||
size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
|
const char *pSepUnix = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
|
||||||
size_t nPosDos = pSepDos ? pSepDos - pszFileName : 0;
|
const char *pSepDos = strrchr(pszFileName, wxFILE_SEP_PATH_DOS);
|
||||||
if ( nPosDos > nPosUnix )
|
const char *pLastSeparator = pSepUnix > pSepDos ? pSepUnix : pSepDos;
|
||||||
nPosUnix = nPosDos;
|
#else // assume Unix
|
||||||
|
const char *pLastSeparator = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
|
||||||
|
|
||||||
if ( pstrPath )
|
if ( pDot == pszFileName )
|
||||||
*pstrPath = wxString(pszFileName, nPosUnix);
|
{
|
||||||
|
// under Unix files like .profile are treated in a special way
|
||||||
|
pDot = NULL;
|
||||||
|
}
|
||||||
|
#endif // MSW/Unix
|
||||||
|
|
||||||
|
if ( pDot < pLastSeparator )
|
||||||
|
{
|
||||||
|
// the dot is part of the path, not the start of the extension
|
||||||
|
pDot = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
size_t nPosDot = 0;
|
if ( pstrPath )
|
||||||
if ( pDot )
|
{
|
||||||
nPosDot = pDot - pszFileName;
|
if ( pLastSeparator )
|
||||||
|
*pstrPath = wxString(pszFileName, pLastSeparator - pszFileName);
|
||||||
|
else
|
||||||
|
pstrPath->Empty();
|
||||||
|
}
|
||||||
|
|
||||||
if ( nPosDot > nPosUnix ) {
|
|
||||||
// the file name looks like "path/name.ext"
|
|
||||||
if ( pstrName )
|
if ( pstrName )
|
||||||
*pstrName = wxString(pszFileName + nPosUnix + 1, nPosDot - nPosUnix - 1);
|
{
|
||||||
|
const char *start = pLastSeparator ? pLastSeparator + 1 : pszFileName;
|
||||||
|
const char *end = pDot ? pDot : pszFileName + strlen(pszFileName);
|
||||||
|
|
||||||
|
*pstrName = wxString(start, end - start);
|
||||||
|
}
|
||||||
|
|
||||||
if ( pstrExt )
|
if ( pstrExt )
|
||||||
*pstrExt = wxString(pszFileName + nPosDot + 1);
|
{
|
||||||
}
|
if ( pDot )
|
||||||
else {
|
*pstrExt = wxString(pDot + 1);
|
||||||
// there is either no dot at all or there is a '/' after it
|
else
|
||||||
if ( pstrName )
|
pstrExt->Empty();
|
||||||
*pstrName = wxString(pszFileName + nPosUnix + 1);
|
}
|
||||||
if ( pstrExt )
|
|
||||||
pstrExt->Empty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user