X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f512f90a83cc4c7a96a2bca4893a3c1fa2975077..2fa7c206f68655f226e37ce1f1cc7e646e6c0bf2:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index dbbb42cf8f..1b0c138ea9 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -38,7 +38,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __WXMAC__ +#if defined(__WXMAC__) || defined(__VISAGECPP__) #include #endif @@ -46,11 +46,20 @@ #include #endif -#include -#include -#include -#include -#include +#if defined(__VISAGECPP__) && __IBMCPP__ >= 400 + // problem in VACPP V4 with including stdlib.h multiple times + // strconv includes it anyway +# include +# include +# include +# include +#else +# include +# include +# include +# include +# include +#endif #ifdef HAVE_STRINGS_H #include // for strcasecmp() @@ -85,10 +94,17 @@ // constants // ---------------------------------------------------------------------------- +#if defined(__VISAGECPP__) && __IBMCPP__ >= 400 +// must define this static for VA or else you get multiply defined symbols everywhere +extern const unsigned int wxSTRING_MAXLEN; + +#else // maximum possible length for a string means "take all string" everywhere // (as sizeof(StringData) is unknown here, we substract 100) const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100; +#endif + // ---------------------------------------------------------------------------- // global data // ---------------------------------------------------------------------------- @@ -156,6 +172,15 @@ inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2) #endif // OS/compiler } +// wxSnprintf() is like snprintf() if it's available and sprintf() (always +// available, but dangerous!) if not +extern int WXDLLEXPORT wxSnprintf(wxChar *buf, size_t len, + const wxChar *format, ...); + +// and wxVsnprintf() is like vsnprintf() or vsprintf() +extern int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len, + const wxChar *format, va_list argptr); + // return an empty wxString class WXDLLEXPORT wxString; // not yet defined inline const wxString& wxGetEmptyString() { return *(wxString *)&wxEmptyString; } @@ -262,7 +287,9 @@ private: // // try `s << i' or `s.Printf("%d", i)' instead wxString(int); + wxString(unsigned int); wxString(long); + wxString(unsigned long); public: // constructors and destructor @@ -302,7 +329,7 @@ public: wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN) { InitWith((const char*)psz, 0, nLength); } // from multibyte string - wxString(const char *psz, wxMBConv& WXUNUSED(conv), size_t nLength = wxSTRING_MAXLEN) + wxString(const char *psz, wxMBConv& WXUNUSED(conv) , size_t nLength = wxSTRING_MAXLEN) { InitWith(psz, 0, nLength); } #if wxUSE_WCHAR_T @@ -377,9 +404,20 @@ public: // operator version of GetChar wxChar operator[](int n) const { ASSERT_VALID_INDEX( n ); return m_pchData[n]; } - // operator version of GetWritableChar +#ifdef __alpha__ + // operator version of GetChar + wxChar operator[](unsigned int n) const + { ASSERT_VALID_INDEX( n ); return m_pchData[n]; } +#endif + + // operator version of GetWriteableChar wxChar& operator[](size_t n) { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; } +#ifdef __alpha__ + // operator version of GetWriteableChar + wxChar& operator[](unsigned int n) + { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; } +#endif // implicit conversion to C string operator const wxChar*() const { return m_pchData; } @@ -482,6 +520,8 @@ public: // append count copies of given character wxString& Append(wxChar ch, size_t count = 1u) { wxString str(ch, count); return *this << str; } + wxString& Append(const wxChar* psz, size_t nLen) + { ConcatSelf(nLen, psz); return *this; } // prepend a string, return the string itself wxString& Prepend(const wxString& str) @@ -501,11 +541,23 @@ public: // stream-like functions // insert an int into string - wxString& operator<<(int i); + wxString& operator<<(int i) + { return (*this) << Format(_T("%d"), i); } + // insert an unsigned int into string + wxString& operator<<(unsigned int ui) + { return (*this) << Format(_T("%u"), ui); } + // insert a long into string + wxString& operator<<(long l) + { return (*this) << Format(_T("%ld"), l); } + // insert an unsigned long into string + wxString& operator<<(unsigned long ul) + { return (*this) << Format(_T("%lu"), ul); } // insert a float into string - wxString& operator<<(float f); + wxString& operator<<(float f) + { return (*this) << Format(_T("%f"), f); } // insert a double into string - wxString& operator<<(double d); + wxString& operator<<(double d) + { return (*this) << Format(_T("%g"), d); } // string comparison // case-sensitive comparison (returns a value < 0, = 0 or > 0) @@ -586,12 +638,26 @@ public: // check if the string contents matches a mask containing '*' and '?' bool Matches(const wxChar *szMask) const; + // conversion to numbers: all functions return TRUE only if the whole string + // is a number and put the value of this number into the pointer provided + // convert to a signed integer + bool ToLong(long *val) const; + // convert to an unsigned integer + bool ToULong(unsigned long *val) const; + // convert to a double + bool ToDouble(double *val) const; + // formated input/output // as sprintf(), returns the number of characters written or < 0 on error int Printf(const wxChar *pszFormat, ...); // as vprintf(), returns the number of characters written or < 0 on error int PrintfV(const wxChar* pszFormat, va_list argptr); + // returns the string containing the result of Printf() to it + static wxString Format(const wxChar *pszFormat, ...); + // the same as above, but takes a va_list + static wxString FormatV(const wxChar *pszFormat, va_list argptr); + // raw access to string memory // ensure that string has space for at least nLen characters // only works if the data of this string is not shared @@ -604,6 +670,7 @@ public: wxChar *GetWriteBuf(size_t nLen); // call this immediately after GetWriteBuf() has been used void UngetWriteBuf(); + void UngetWriteBuf(size_t nLen); // wxWindows version 1 compatibility functions @@ -685,6 +752,8 @@ public: void clear() { Empty(); } // returns true if the string is empty bool empty() const { return IsEmpty(); } + // inform string about planned change in size + void reserve(size_t size) { Alloc(size); } // lib.string.access // return the character at position n @@ -837,7 +906,8 @@ public: const wxChar* sz, size_t nCount = npos) const; // substring extraction - wxString substr(size_t nStart = 0, size_t nLen = npos) const; + wxString substr(size_t nStart = 0, size_t nLen = npos) const + { return Mid(nStart, nLen); } #endif // wxSTD_STRING_COMPATIBILITY }; @@ -1037,7 +1107,8 @@ inline wxString WXDLLEXPORT operator+(const wxCharBuffer& buf, const wxString& s #include "wx/ioswrap.h" -WXDLLEXPORT istream& operator>>(istream& is, wxString& str); +WXDLLEXPORT istream& operator>>(istream&, wxString&); +WXDLLEXPORT ostream& operator<<(ostream&, const wxString&); #endif // wxSTD_STRING_COMPATIBILITY