// constants
// ----------------------------------------------------------------------------
+#if WXWIN_COMPATIBILITY_2_6
+
+// deprecated in favour of wxString::npos, don't use in new code
+//
// maximum possible length for a string means "take all string" everywhere
#define wxSTRING_MAXLEN wxStringBase::npos
+#endif // WXWIN_COMPATIBILITY_2_6
+
// ----------------------------------------------------------------------------
// global data
// ----------------------------------------------------------------------------
// return the length of the string
size_type size() const { return length(); }
// return the maximum size of the string
- size_type max_size() const { return wxSTRING_MAXLEN; }
+ size_type max_size() const { return npos; }
// resize the string, filling the space with c if c != 0
void resize(size_t nSize, wxChar ch = wxT('\0'));
// delete the contents of the string
#if wxUSE_UNICODE
// from multibyte string
- wxString(const char *psz, const wxMBConv& conv, size_t nLength = npos);
+ wxString(const char *psz,
+ const wxMBConv& conv = wxConvLibc,
+ size_t nLength = npos);
// from wxWCharBuffer (i.e. return from wxGetString)
wxString(const wxWCharBuffer& psz) : wxStringBase(psz.data()) { }
#else // ANSI
// from wxWCharBuffer
wxString& operator=(const wxWCharBuffer& psz)
{ (void) operator=((const wchar_t *)psz); return *this; }
+ // from C string
+ wxString& operator=(const char* psz)
+ { return operator=(wxString(psz)); }
#else // ANSI
// from another kind of C string
wxString& operator=(const unsigned char* psz);
// string += string
wxString& operator<<(const wxString& s)
{
-#if !wxUSE_STL
+#if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL
wxASSERT_MSG( s.GetStringData()->IsValid(),
_T("did you forget to call UngetWriteBuf()?") );
#endif
// string += buffer (i.e. from wxGetString)
#if wxUSE_UNICODE
wxString& operator<<(const wxWCharBuffer& s)
- { (void)operator<<((const wchar_t *)s); return *this; }
- void operator+=(const wxWCharBuffer& s)
- { (void)operator<<((const wchar_t *)s); }
+ { return operator<<((const wchar_t *)s); }
+ wxString& operator+=(const wxWCharBuffer& s)
+ { return operator<<((const wchar_t *)s); }
#else // !wxUSE_UNICODE
wxString& operator<<(const wxCharBuffer& s)
- { (void)operator<<((const char *)s); return *this; }
- void operator+=(const wxCharBuffer& s)
- { (void)operator<<((const char *)s); }
+ { return operator<<((const char *)s); }
+ wxString& operator+=(const wxCharBuffer& s)
+ { return operator<<((const char *)s); }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+#if wxUSE_UNICODE
+ // string += C string in Unicode build (with conversion)
+ wxString& operator<<(const char *s)
+ { return operator<<(wxString(s)); }
+ wxString& operator+=(const char *s)
+ { return operator+=(wxString(s)); }
+#endif // wxUSE_UNICODE
+
// string += C string
wxString& Append(const wxString& s)
{
wxString operator()(size_t start, size_t len) const
{ return Mid(start, len); }
- // check that the string starts with prefix and return the rest of the
- // string in the provided pointer if it is not NULL, otherwise return
- // false
+ // check if the string starts with the given prefix and return the rest
+ // of the string in the provided pointer if it is not NULL; otherwise
+ // return false
bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
+ // check if the string ends with the given suffix and return the
+ // beginning of the string before the suffix in the provided pointer if
+ // it is not NULL; otherwise return false
+ bool EndsWith(const wxChar *suffix, wxString *rest = NULL) const;
// get first nCount characters
wxString Left(size_t nCount) const;
bool ToLong(long *val, int base = 10) const;
// convert to an unsigned integer
bool ToULong(unsigned long *val, int base = 10) const;
+ // convert to wxLongLong
+#if defined(wxLongLong_t)
+ bool ToLongLong(wxLongLong_t *val, int base = 10) const;
+ // convert to wxULongLong
+ bool ToULongLong(wxULongLong_t *val, int base = 10) const;
+#endif // wxLongLong_t
// convert to a double
bool ToDouble(double *val) const;
+
+
// formatted input/output
// as sprintf(), returns the number of characters written or < 0 on error
// (take 'this' into account in attribute parameter count)
// minimize the string's memory
// only works if the data of this string is not shared
bool Shrink();
-#if !wxUSE_STL
+#if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL
+ // These are deprecated, use wxStringBuffer or wxStringBufferLength instead
+ //
// get writable buffer of at least nLen bytes. Unget() *must* be called
// a.s.a.p. to put string back in a reasonable state!
- wxChar *GetWriteBuf(size_t nLen);
+ wxDEPRECATED( wxChar *GetWriteBuf(size_t nLen) );
// call this immediately after GetWriteBuf() has been used
- void UngetWriteBuf();
- void UngetWriteBuf(size_t nLen);
-#endif
+ wxDEPRECATED( void UngetWriteBuf() );
+ wxDEPRECATED( void UngetWriteBuf(size_t nLen) );
+#endif // WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL
// wxWidgets version 1 compatibility functions
// string += char
wxString& operator+=(wxChar ch)
{ return (wxString&)wxStringBase::operator+=(ch); }
+
+private:
+#if !wxUSE_STL
+ // helpers for wxStringBuffer and wxStringBufferLength
+ wxChar *DoGetWriteBuf(size_t nLen);
+ void DoUngetWriteBuf();
+ void DoUngetWriteBuf(size_t nLen);
+
+ friend class WXDLLIMPEXP_BASE wxStringBuffer;
+ friend class WXDLLIMPEXP_BASE wxStringBufferLength;
+#endif
};
// notice that even though for many compilers the friend declarations above are
wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string);
-// define wxArrayString, for compatibility
-#if WXWIN_COMPATIBILITY_2_4 && !wxUSE_STL
- #include "wx/arrstr.h"
-#endif
-
#if wxUSE_STL
// return an empty wxString (not very useful with wxUSE_STL == 1)
inline const wxString wxGetEmptyString() { return wxString(); }
public:
wxStringBuffer(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL)
- { m_buf = m_str.GetWriteBuf(lenWanted); }
+ { m_buf = m_str.DoGetWriteBuf(lenWanted); }
- ~wxStringBuffer() { m_str.UngetWriteBuf(); }
+ ~wxStringBuffer() { m_str.DoUngetWriteBuf(); }
operator wxChar*() const { return m_buf; }
wxStringBufferLength(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
{
- m_buf = m_str.GetWriteBuf(lenWanted);
+ m_buf = m_str.DoGetWriteBuf(lenWanted);
wxASSERT(m_buf != NULL);
}
~wxStringBufferLength()
{
wxASSERT(m_lenSet);
- m_str.UngetWriteBuf(m_len);
+ m_str.DoUngetWriteBuf(m_len);
}
operator wxChar*() const { return m_buf; }
inline bool operator!=(wxChar c, const wxString& s) { return !s.IsSameAs(c); }
inline bool operator!=(const wxString& s, wxChar c) { return !s.IsSameAs(c); }
+// comparison with C string in Unicode build
+#if wxUSE_UNICODE
+inline bool operator==(const wxString& s1, const char* s2)
+ { return s1 == wxString(s2); }
+inline bool operator==(const char* s1, const wxString& s2)
+ { return wxString(s1) == s2; }
+inline bool operator!=(const wxString& s1, const char* s2)
+ { return s1 != wxString(s2); }
+inline bool operator!=(const char* s1, const wxString& s2)
+ { return wxString(s1) != s2; }
+inline bool operator< (const wxString& s1, const char* s2)
+ { return s1 < wxString(s2); }
+inline bool operator< (const char* s1, const wxString& s2)
+ { return wxString(s1) < s2; }
+inline bool operator> (const wxString& s1, const char* s2)
+ { return s1 > wxString(s2); }
+inline bool operator> (const char* s1, const wxString& s2)
+ { return wxString(s1) > s2; }
+inline bool operator<=(const wxString& s1, const char* s2)
+ { return s1 <= wxString(s2); }
+inline bool operator<=(const char* s1, const wxString& s2)
+ { return wxString(s1) <= s2; }
+inline bool operator>=(const wxString& s1, const char* s2)
+ { return s1 >= wxString(s2); }
+inline bool operator>=(const char* s1, const wxString& s2)
+ { return wxString(s1) >= s2; }
+#endif // wxUSE_UNICODE
+
// ---------------------------------------------------------------------------
// Implementation only from here until the end of file
// ---------------------------------------------------------------------------
#include "wx/iosfwrap.h"
-WXDLLIMPEXP_BASE wxSTD istream& operator>>(wxSTD istream&, wxString&);
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
#endif // wxSTD_STRING_COMPATIBILITY