typedef value_type *iterator;
typedef const value_type *const_iterator;
+#define wxSTRING_REVERSE_ITERATOR(name, const_or_not) \
+ class name \
+ { \
+ public: \
+ typedef wxChar value_type; \
+ typedef const_or_not value_type& reference; \
+ typedef const_or_not value_type *pointer; \
+ typedef const_or_not value_type *iterator_type; \
+ \
+ name(iterator_type i) : m_cur(i) { } \
+ name(const name& ri) : m_cur(ri.m_cur) { } \
+ \
+ iterator_type base() const { return m_cur; } \
+ \
+ reference operator*() const { return *(m_cur - 1); } \
+ \
+ name& operator++() { --m_cur; return *this; } \
+ name operator++(int) { name tmp = *this; --m_cur; return tmp; } \
+ name& operator--() { ++m_cur; return *this; } \
+ name operator--(int) { name tmp = *this; ++m_cur; return tmp; } \
+ \
+ bool operator==(name ri) const { return m_cur == ri.m_cur; } \
+ bool operator!=(name ri) const { return !(*this == ri); } \
+ \
+ private: \
+ iterator_type m_cur; \
+ }
+
+ wxSTRING_REVERSE_ITERATOR(const_reverse_iterator, const);
+
+ #define wxSTRING_CONST
+ wxSTRING_REVERSE_ITERATOR(reverse_iterator, wxSTRING_CONST);
+ #undef wxSTRING_CONST
+
+ #undef wxSTRING_REVERSE_ITERATOR
+
+
// constructors and destructor
// ctor for an empty string
wxStringBase() { Init(); }
{ InitWith(psz, 0, npos); }
wxStringBase(const wxChar *psz, size_t nLength)
{ InitWith(psz, 0, nLength); }
- wxStringBase(const wxChar *psz, wxMBConv& WXUNUSED(conv), size_t nLength = npos)
+ wxStringBase(const wxChar *psz,
+ const wxMBConv& WXUNUSED(conv),
+ size_t nLength = npos)
{ InitWith(psz, 0, nLength); }
// take nLen chars starting at nPos
wxStringBase(const wxStringBase& str, size_t nPos, size_t nLen)
// first valid index position
const_iterator begin() const { return m_pchData; }
+ iterator begin();
// position one after the last valid one
const_iterator end() const { return m_pchData + length(); }
-
- // first valid index position
- iterator begin();
- // position one after the last valid one
iterator end();
+ // first element of the reversed string
+ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
+ reverse_iterator rbegin() { return reverse_iterator(end()); }
+ // one beyond the end of the reversed string
+ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
+ reverse_iterator rend() { return reverse_iterator(begin()); }
+
// insert another string
wxStringBase& insert(size_t nPos, const wxStringBase& str)
{
: wxStringBase(psz ? psz : wxT("")) { }
wxString(const wxChar *psz, size_t nLength)
: wxStringBase(psz, nLength) { }
- wxString(const wxChar *psz, wxMBConv& WXUNUSED(conv), size_t nLength = npos)
+ wxString(const wxChar *psz,
+ const wxMBConv& WXUNUSED(conv),
+ size_t nLength = npos)
: wxStringBase(psz, nLength == npos ? wxStrlen(psz) : nLength) { }
// even if we're not built with wxUSE_STL == 1 it is very convenient to allow
#if wxUSE_UNICODE
// from multibyte string
- wxString(const char *psz, wxMBConv& conv, size_t nLength = npos);
+ wxString(const char *psz, const wxMBConv& conv, size_t nLength = npos);
// from wxWCharBuffer (i.e. return from wxGetString)
wxString(const wxWCharBuffer& psz) : wxStringBase(psz.data()) { }
#else // ANSI
#if wxUSE_WCHAR_T
// from wide (Unicode) string
- wxString(const wchar_t *pwz, wxMBConv& conv = wxConvLibc, size_t nLength = npos);
+ wxString(const wchar_t *pwz,
+ const wxMBConv& conv = wxConvLibc,
+ size_t nLength = npos);
#endif // !wxUSE_WCHAR_T
// from wxCharBuffer
// type differs because a function may either return pointer to the buffer
// directly or have to use intermediate buffer for translation.
#if wxUSE_UNICODE
- const wxCharBuffer mb_str(wxMBConv& conv = wxConvLibc) const;
+ const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
const wxChar* wc_str() const { return c_str(); }
// for compatibility with !wxUSE_UNICODE version
- const wxChar* wc_str(wxMBConv& WXUNUSED(conv)) const { return c_str(); }
+ const wxChar* wc_str(const wxMBConv& WXUNUSED(conv)) const { return c_str(); }
#if wxMBFILES
const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
const wxChar* mb_str() const { return c_str(); }
// for compatibility with wxUSE_UNICODE version
- const wxChar* mb_str(wxMBConv& WXUNUSED(conv)) const { return c_str(); }
+ const wxChar* mb_str(const wxMBConv& WXUNUSED(conv)) const { return c_str(); }
const wxWX2MBbuf mbc_str() const { return mb_str(); }
#if wxUSE_WCHAR_T
- const wxWCharBuffer wc_str(wxMBConv& conv) const;
+ const wxWCharBuffer wc_str(const wxMBConv& conv) const;
#endif // wxUSE_WCHAR_T
#ifdef __WXOSX__
const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLocal ) ); }
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;