#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; }
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
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; }
// 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);
// 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
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
// 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
// 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); }
};
// ---------------------------------------------------------------------------
#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