// headers
// ----------------------------------------------------------------------------
-#ifdef __WXMAC__
+#if defined(__WXMAC__) || defined(__VISAGECPP__)
#include <ctype.h>
#endif
#include <std.h>
#endif
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <stdlib.h>
+#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
+ // problem in VACPP V4 with including stdlib.h multiple times
+ // strconv includes it anyway
+# include <stdio.h>
+# include <string.h>
+# include <stdarg.h>
+# include <limits.h>
+#else
+# include <string.h>
+# include <stdio.h>
+# include <stdarg.h>
+# include <limits.h>
+# include <stdlib.h>
+#endif
#ifdef HAVE_STRINGS_H
#include <strings.h> // for strcasecmp()
#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; }
// 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
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 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
};
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