X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/223d09f6b523aac674ef9b72a883dfa8d37c5d4e..a6e2b3a8316c430a68f91b3c894e856987dd972e:/include/wx/string.h?ds=sidebyside diff --git a/include/wx/string.h b/include/wx/string.h index d21eb47a47..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 @@ -370,21 +397,27 @@ public: wxChar& Last() { wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; } - // under Unix it is tested with configure, assume it works on other - // platforms (there might be overloading problems if size_t and int are - // the same type) -#if !defined(__UNIX__) || wxUSE_SIZE_T_STRING_OPERATOR // operator version of GetChar wxChar operator[](size_t n) const { ASSERT_VALID_INDEX( n ); return m_pchData[n]; } -#endif // 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; } @@ -487,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) @@ -506,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) @@ -591,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 @@ -609,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 @@ -690,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 @@ -842,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 }; @@ -869,8 +934,9 @@ public: const wxString& second); // constructors and destructor - // default ctor - wxArrayString(); + // default ctor: if autoSort is TRUE, the array is always sorted (in + // alphabetical order) + wxArrayString(bool autoSort = FALSE); // copy ctor wxArrayString(const wxArrayString& array); // assignment operator @@ -911,8 +977,9 @@ public: // sensitive (default). Returns index of the first item matched or // wxNOT_FOUND int Index (const wxChar *sz, bool bCase = TRUE, bool bFromEnd = FALSE) const; - // add new element at the end - void Add(const wxString& str); + // add new element at the end (if the array is not sorted), return its + // index + size_t Add(const wxString& str); // add new element at given position void Insert(const wxString& str, size_t uiIndex); // remove first item matching this value @@ -927,16 +994,30 @@ public: // sort array elements using specified comparaison function void Sort(CompareFunction compareFunction); +protected: + void Copy(const wxArrayString& src); // copies the contents of another array + private: - void Grow(); // makes array bigger if needed - void Free(); // free the string stored + void Grow(); // makes array bigger if needed + void Free(); // free all the strings stored - void DoSort(); // common part of all Sort() variants + void DoSort(); // common part of all Sort() variants size_t m_nSize, // current size of the array m_nCount; // current number of elements - wxChar **m_pItems; // pointer to data + wxChar **m_pItems; // pointer to data + + bool m_autoSort; // if TRUE, keep the array always sorted +}; + +class WXDLLEXPORT wxSortedArrayString : public wxArrayString +{ +public: + wxSortedArrayString() : wxArrayString(TRUE) + { } + wxSortedArrayString(const wxArrayString& array) : wxArrayString(TRUE) + { Copy(array); } }; // --------------------------------------------------------------------------- @@ -1026,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