Source cleaning.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39713 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2006-06-14 10:19:14 +00:00
parent 696978ee96
commit 3458e408ba

View File

@@ -1140,70 +1140,70 @@ wxString& wxString::operator=(const wchar_t *pwz)
wxString operator+(const wxString& str1, const wxString& str2) wxString operator+(const wxString& str1, const wxString& str2)
{ {
#if !wxUSE_STL #if !wxUSE_STL
wxASSERT( str1.GetStringData()->IsValid() ); wxASSERT( str1.GetStringData()->IsValid() );
wxASSERT( str2.GetStringData()->IsValid() ); wxASSERT( str2.GetStringData()->IsValid() );
#endif #endif
wxString s = str1; wxString s = str1;
s += str2; s += str2;
return s; return s;
} }
wxString operator+(const wxString& str, wxChar ch) wxString operator+(const wxString& str, wxChar ch)
{ {
#if !wxUSE_STL #if !wxUSE_STL
wxASSERT( str.GetStringData()->IsValid() ); wxASSERT( str.GetStringData()->IsValid() );
#endif #endif
wxString s = str; wxString s = str;
s += ch; s += ch;
return s; return s;
} }
wxString operator+(wxChar ch, const wxString& str) wxString operator+(wxChar ch, const wxString& str)
{ {
#if !wxUSE_STL #if !wxUSE_STL
wxASSERT( str.GetStringData()->IsValid() ); wxASSERT( str.GetStringData()->IsValid() );
#endif #endif
wxString s = ch; wxString s = ch;
s += str; s += str;
return s; return s;
} }
wxString operator+(const wxString& str, const wxChar *psz) wxString operator+(const wxString& str, const wxChar *psz)
{ {
#if !wxUSE_STL #if !wxUSE_STL
wxASSERT( str.GetStringData()->IsValid() ); wxASSERT( str.GetStringData()->IsValid() );
#endif #endif
wxString s; wxString s;
if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) { if ( !s.Alloc(wxStrlen(psz) + str.length()) ) {
wxFAIL_MSG( _T("out of memory in wxString::operator+") ); wxFAIL_MSG( _T("out of memory in wxString::operator+") );
} }
s += str; s += str;
s += psz; s += psz;
return s; return s;
} }
wxString operator+(const wxChar *psz, const wxString& str) wxString operator+(const wxChar *psz, const wxString& str)
{ {
#if !wxUSE_STL #if !wxUSE_STL
wxASSERT( str.GetStringData()->IsValid() ); wxASSERT( str.GetStringData()->IsValid() );
#endif #endif
wxString s; wxString s;
if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) { if ( !s.Alloc(wxStrlen(psz) + str.length()) ) {
wxFAIL_MSG( _T("out of memory in wxString::operator+") ); wxFAIL_MSG( _T("out of memory in wxString::operator+") );
} }
s = psz; s = psz;
s += str; s += str;
return s; return s;
} }
// =========================================================================== // ===========================================================================
@@ -1606,65 +1606,66 @@ inline int wxSafeIsspace(wxChar ch) { return (ch < 127) && wxIsspace(ch); }
// 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 // first check if we're going to modify the string at all
if ( !empty() && if ( !empty() &&
( (
(bFromRight && wxSafeIsspace(GetChar(Len() - 1))) || (bFromRight && wxSafeIsspace(GetChar(length() - 1))) ||
(!bFromRight && wxSafeIsspace(GetChar(0u))) (!bFromRight && wxSafeIsspace(GetChar(0u)))
)
) )
)
{
if ( bFromRight )
{ {
// find last non-space character if ( bFromRight )
iterator psz = begin() + length() - 1; {
while ( wxSafeIsspace(*psz) && (psz >= begin()) ) // find last non-space character
psz--; iterator psz = begin() + length() - 1;
while ( wxSafeIsspace(*psz) && (psz >= begin()) )
psz--;
// truncate at trailing space start // truncate at trailing space start
*++psz = wxT('\0'); *++psz = wxT('\0');
erase(psz, end()); erase(psz, end());
}
else
{
// find first non-space character
iterator psz = begin();
while ( wxSafeIsspace(*psz) )
psz++;
// fix up data and length
erase(begin(), psz);
}
} }
else
{
// find first non-space character
iterator psz = begin();
while ( wxSafeIsspace(*psz) )
psz++;
// fix up data and length return *this;
erase(begin(), psz);
}
}
return *this;
} }
// adds nCount characters chPad to the string from either side // adds nCount characters chPad to the string from either side
wxString& wxString::Pad(size_t nCount, wxChar chPad, bool bFromRight) wxString& wxString::Pad(size_t nCount, wxChar chPad, bool bFromRight)
{ {
wxString s(chPad, nCount); wxString s(chPad, nCount);
if ( bFromRight ) if ( bFromRight )
*this += s; *this += s;
else else
{ {
s += *this; s += *this;
swap(s); swap(s);
} }
return *this; return *this;
} }
// truncate the string // truncate the string
wxString& wxString::Truncate(size_t uiLen) wxString& wxString::Truncate(size_t uiLen)
{ {
if ( uiLen < Len() ) { if ( uiLen < length() )
erase(begin() + uiLen, end()); {
} erase(begin() + uiLen, end());
//else: nothing to do, string is already short enough }
//else: nothing to do, string is already short enough
return *this; return *this;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -1674,17 +1675,17 @@ wxString& wxString::Truncate(size_t uiLen)
// find a character // find a character
int wxString::Find(wxChar ch, bool bFromEnd) const int wxString::Find(wxChar ch, bool bFromEnd) const
{ {
size_type idx = bFromEnd ? find_last_of(ch) : find_first_of(ch); size_type idx = bFromEnd ? find_last_of(ch) : find_first_of(ch);
return (idx == npos) ? wxNOT_FOUND : (int)idx; return (idx == npos) ? wxNOT_FOUND : (int)idx;
} }
// find a sub-string (like strstr) // find a sub-string (like strstr)
int wxString::Find(const wxChar *pszSub) const int wxString::Find(const wxChar *pszSub) const
{ {
size_type idx = find(pszSub); size_type idx = find(pszSub);
return (idx == npos) ? wxNOT_FOUND : (int)idx; return (idx == npos) ? wxNOT_FOUND : (int)idx;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1819,7 +1820,7 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
// we could have overshot // we could have overshot
Shrink(); Shrink();
return Len(); return length();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1968,7 +1969,7 @@ match:
int wxString::Freq(wxChar ch) const int wxString::Freq(wxChar ch) const
{ {
int count = 0; int count = 0;
int len = Len(); int len = length();
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
{ {
if (GetChar(i) == ch) if (GetChar(i) == ch)