X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3fc1adbd94297c3b275031be87cb15dedb422b1f..f14d6dd133f96d7110b9ff635e977349b1806238:/include/wx/string.h?ds=sidebyside diff --git a/include/wx/string.h b/include/wx/string.h index 844cfa9f81..ac55f5c5f9 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -262,7 +262,7 @@ protected: // initializes the string to the empty value (must be called only from // ctors, use Reinit() otherwise) void Init() { m_pchData = (wxChar *)wxEmptyString; } - // initializaes the string with (a part of) C-string + // initializes the string with (a part of) C-string void InitWith(const wxChar *psz, size_t nPos = 0, size_t nLen = npos); // as Init, but also frees old data void Reinit() { GetStringData()->Unlock(); Init(); } @@ -671,7 +671,10 @@ public: wxString(const wxWCharBuffer& psz) : wxStringBase(psz.data()) { } #else // ANSI // from C string (for compilers using unsigned char) - wxString(const unsigned char* psz, size_t nLength = npos) + wxString(const unsigned char* psz) + : wxStringBase((const char*)psz) { } + // from part of C string (for compilers using unsigned char) + wxString(const unsigned char* psz, size_t nLength) : wxStringBase((const char*)psz, nLength) { } #if wxUSE_WCHAR_T @@ -931,16 +934,19 @@ public: { *this = str + *this; return *this; } // non-destructive concatenation - // - friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2); - // + // two strings + friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, + const wxString& string2); + // string with a single char friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch); - // + // char with a string friend wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string); - // - friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wxChar *psz); - // - friend wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string); + // string with C string + friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, + const wxChar *psz); + // C string with string + friend wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, + const wxString& string); // stream-like functions // insert an int into string @@ -958,10 +964,16 @@ public: #if defined wxLongLong_t && !defined wxLongLongIsLong // insert a long long if they exist and aren't longs wxString& operator<<(wxLongLong_t ll) - { return (*this) << Format(_T("%") wxLongLongFmtSpec _T("d"), ll); } + { + const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("d"); + return (*this) << Format(fmt, ll); + } // insert an unsigned long long wxString& operator<<(wxULongLong_t ull) - { return (*this) << Format(_T("%") wxLongLongFmtSpec _T("u"), ull); } + { + const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("u"); + return (*this) << Format(fmt , ull); + } #endif // insert a float into string wxString& operator<<(float f) @@ -1066,7 +1078,7 @@ public: // convert to a double bool ToDouble(double *val) const; - // formated input/output + // formatted input/output // as sprintf(), returns the number of characters written or < 0 on error // (take 'this' into account in attribute parameter count) int Printf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2; @@ -1283,16 +1295,16 @@ public: { return (wxString&)wxStringBase::operator+=(ch); } }; -// IBM xlC compiler needs these operators to be declared in global scope, -// although this shouldn't be a problem for the other compilers we prefer to -// only do it for it in stable 2.6 branch -#ifdef __IBMCPP__ +// notice that even though for many compilers the friend declarations above are +// enough, from the point of view of C++ standard we must have the declarations +// here as friend ones are not injected in the enclosing namespace and without +// them the code fails to compile with conforming compilers such as xlC or g++4 wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2); wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch); wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string); wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wxChar *psz); wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string); -#endif // __IBMCPP__ + // define wxArrayString, for compatibility #if WXWIN_COMPATIBILITY_2_4 && !wxUSE_STL