fixed bug in parsing filenames without paths, added more/better tests

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-01-23 00:24:32 +00:00
parent 5e68f8f373
commit 8e7dda219e
2 changed files with 46 additions and 15 deletions

View File

@@ -512,7 +512,10 @@ void wxFileName::SplitPath(const wxString& fullpath,
}
}
if ( (posLastDot != wxString::npos) && (posLastDot < posLastSlash) )
// if we do have a dot and a slash, check that the dot is in the name part
if ( (posLastDot != wxString::npos) &&
(posLastSlash != wxString::npos) &&
(posLastDot < posLastSlash) )
{
// the dot is part of the path, not the start of the extension
posLastDot = wxString::npos;
@@ -538,9 +541,20 @@ void wxFileName::SplitPath(const wxString& fullpath,
// take all characters starting from the one after the last slash and
// up to, but excluding, the last dot
size_t nStart = posLastSlash == wxString::npos ? 0 : posLastSlash + 1;
size_t count = posLastDot == wxString::npos
? wxString::npos
: posLastDot - posLastSlash - 1;
size_t count;
if ( posLastDot == wxString::npos )
{
// take all until the end
count = wxString::npos;
}
else if ( posLastSlash == wxString::npos )
{
count = posLastDot;
}
else // have both dot and slash
{
count = posLastDot - posLastSlash - 1;
}
*pstrName = fullpath.Mid(nStart, count);
}