+#if wxUSE_UNICODE_UTF8
+ class iterator
+ {
+ // NB: In UTF-8 build, (non-const) iterator needs to keep reference
+ // to the underlying wxStringImpl, because UTF-8 is variable-length
+ // encoding and changing the value pointer to by an iterator using
+ // its operator* requires calling wxStringImpl::replace() if the old
+ // and new values differ in their encoding's length.
+
+ WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
+ wxUniCharRef::CreateForString(m_str, m_cur));
+
+ public:
+ iterator(const iterator& i) : m_cur(i.m_cur), m_str(i.m_str) {}
+
+ iterator operator+(int n) const
+ { return iterator(m_str, wxString::AddToIter(m_cur, n)); }
+ iterator operator+(size_t n) const
+ { return iterator(m_str, wxString::AddToIter(m_cur, (int)n)); }
+ iterator operator-(int n) const
+ { return iterator(m_str, wxString::AddToIter(m_cur, -n)); }
+ iterator operator-(size_t n) const
+ { return iterator(m_str, wxString::AddToIter(m_cur, -(int)n)); }
+
+ private:
+ iterator(wxString *str, underlying_iterator ptr)
+ : m_cur(ptr), m_str(str->m_impl) {}
+ iterator(wxStringImpl& str, underlying_iterator ptr)
+ : m_cur(ptr), m_str(str) {}
+
+ wxStringImpl& m_str;
+
+ friend class const_iterator;
+ };
+#else // !wxUSE_UNICODE_UTF8