// function wxVsnprintfA (A for ANSI), should also find one for Unicode
// strings in Unicode build
#ifdef __WXMSW__
- #if defined(__VISUALC__) || defined(__MINGW32__)
+ #if defined(__VISUALC__) || (defined(__MINGW32__) && wxUSE_NORLANDER_HEADERS)
#define wxVsnprintfA _vsnprintf
#endif
+#elif defined(__WXMAC__)
+ #define wxVsnprintfA vsnprintf
#else // !Windows
#ifdef HAVE_VSNPRINTF
#define wxVsnprintfA vsnprintf
#if defined(__VISUALC__)
#pragma message("Using sprintf() because no snprintf()-like function defined")
- #elif defined(__GNUG__) && !defined(__UNIX__)
- #warning "Using sprintf() because no snprintf()-like function defined"
- #elif defined(__MWERKS__)
+ #elif defined(__GNUG__)
#warning "Using sprintf() because no snprintf()-like function defined"
#endif //compiler
#endif // no vsnprintf
// trimming and padding
// ---------------------------------------------------------------------------
+// some compilers (VC++ 6.0 not to name them) return TRUE for a call to
+// isspace('ê') in the C locale which seems to be broken to me, but we have to
+// live with this by checking that the character is a 7 bit one - even if this
+// may fail to detect some spaces (I don't know if Unicode doesn't have
+// space-like symbols somewhere except in the first 128 chars), it is arguably
+// still better than trimming away accented letters
+inline int wxSafeIsspace(wxChar ch) { return (ch < 127) && wxIsspace(ch); }
+
// trims spaces (in the sense of isspace) from left or right side
wxString& wxString::Trim(bool bFromRight)
{
// first check if we're going to modify the string at all
if ( !IsEmpty() &&
(
- (bFromRight && wxIsspace(GetChar(Len() - 1))) ||
- (!bFromRight && wxIsspace(GetChar(0u)))
+ (bFromRight && wxSafeIsspace(GetChar(Len() - 1))) ||
+ (!bFromRight && wxSafeIsspace(GetChar(0u)))
)
)
{
{
// find last non-space character
wxChar *psz = m_pchData + GetStringData()->nDataLength - 1;
- while ( wxIsspace(*psz) && (psz >= m_pchData) )
+ while ( wxSafeIsspace(*psz) && (psz >= m_pchData) )
psz--;
// truncate at trailing space start
{
// find first non-space character
const wxChar *psz = m_pchData;
- while ( wxIsspace(*psz) )
+ while ( wxSafeIsspace(*psz) )
psz++;
// fix up data and length
// NB: wxVsnprintf() may return either less than the buffer size or -1 if
// there is not enough place depending on implementation
- int iLen = wxVsnprintfA(szScratch, WXSIZEOF(szScratch), pszFormat, argptr);
+ int iLen = wxVsnprintfA(szScratch, WXSIZEOF(szScratch), (char *)pszFormat, argptr);
if ( iLen != -1 ) {
// the whole string is in szScratch
*this = szScratch;
// ---------------------------------------------------------------------------
// standard C++ library string functions
// ---------------------------------------------------------------------------
+
#ifdef wxSTD_STRING_COMPATIBILITY
+void wxString::resize(size_t nSize, wxChar ch)
+{
+ size_t len = length();
+
+ if ( nSize < len )
+ {
+ Truncate(nSize);
+ }
+ else if ( nSize > len )
+ {
+ *this += wxString(ch, len - nSize);
+ }
+ //else: we have exactly the specified length, nothing to do
+}
+
+void wxString::swap(wxString& str)
+{
+ // this is slightly less efficient than fiddling with m_pchData directly,
+ // but it is still quite efficient as we don't copy the string here because
+ // ref count always stays positive
+ wxString tmp = str;
+ str = *this;
+ *this = str;
+}
+
wxString& wxString::insert(size_t nPos, const wxString& str)
{
wxASSERT( str.GetStringData()->IsValid() );