bogus assert removed, optimized (and removed a bug in process of doing it)

wxString::Trim


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@799 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-10-03 00:25:17 +00:00
parent 524bf39144
commit 2c3b684c2b
2 changed files with 34 additions and 24 deletions

View File

@@ -257,10 +257,10 @@ public:
size_t Len() const { return GetStringData()->nDataLength; } size_t Len() const { return GetStringData()->nDataLength; }
/// string contains any characters? /// string contains any characters?
bool IsEmpty() const { return Len() == 0; } bool IsEmpty() const { return Len() == 0; }
/// reinitialize string (and free data!) /// reinitialize string (and free memory)
void Empty() void Empty()
{ {
if ( GetStringData()->nDataLength != 0 ) if ( !IsEmpty() )
Reinit(); Reinit();
wxASSERT( GetStringData()->nDataLength == 0 ); wxASSERT( GetStringData()->nDataLength == 0 );

View File

@@ -775,6 +775,15 @@ wxString& wxString::MakeLower()
// trims spaces (in the sense of isspace) from left or right side // trims spaces (in the sense of isspace) from left or right side
wxString& wxString::Trim(bool bFromRight) wxString& wxString::Trim(bool bFromRight)
{ {
// first check if we're going to modify the string at all
if ( !IsEmpty() &&
(
(bFromRight && isspace(GetChar(Len() - 1))) ||
(!bFromRight && isspace(GetChar(0u)))
)
)
{
// ok, there is at least one space to trim
CopyBeforeWrite(); CopyBeforeWrite();
if ( bFromRight ) if ( bFromRight )
@@ -800,6 +809,7 @@ wxString& wxString::Trim(bool bFromRight)
memmove(m_pchData, psz, (nDataLength + 1)*sizeof(char)); memmove(m_pchData, psz, (nDataLength + 1)*sizeof(char));
GetStringData()->nDataLength = nDataLength; GetStringData()->nDataLength = nDataLength;
} }
}
return *this; return *this;
} }