X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e90c1d2a19361551eb07778280f22be3e759cf64..c51deffc32ff80f4ed13a1095bbf2ff44de89505:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index 535b48f81c..29be6c6770 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -156,6 +156,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; } @@ -302,7 +311,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 +379,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; } @@ -573,7 +588,7 @@ public: // remove spaces from left or from right (default) side wxString& Trim(bool bFromRight = TRUE); // add nCount copies chPad in the beginning or at the end (default) - wxString& Pad(size_t nCount, wxChar chPad = T(' '), bool bFromRight = TRUE); + wxString& Pad(size_t nCount, wxChar chPad = wxT(' '), bool bFromRight = TRUE); // truncate string to given length wxString& Truncate(size_t uiLen); @@ -685,11 +700,13 @@ public: // return the maximum size of the string size_t max_size() const { return wxSTRING_MAXLEN; } // resize the string, filling the space with c if c != 0 - void resize(size_t nSize, wxChar ch = T('\0')); + void resize(size_t nSize, wxChar ch = wxT('\0')); // delete the contents of the string 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 @@ -869,8 +886,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 +929,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 +946,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 +1059,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