wxString(const wxString& str, size_t nLength)
: m_impl(str.Mid(0, nLength).m_impl) {}
- ~wxString();
-
public:
// standard types
typedef wxUniChar value_type;
iterator_name& operator-=(size_t n) \
{ m_cur = wxString::AddToIter(m_cur, -(int)n); return *this; } \
\
- unsigned operator-(const iterator_name& i) const \
+ difference_type operator-(const iterator_name& i) const \
{ return wxString::DiffIters(m_cur, i.m_cur); } \
\
bool operator==(const iterator_name& i) const \
friend class WXDLLIMPEXP_BASE wxCStrData; \
\
private: \
- underlying_iterator m_cur;
+ underlying_iterator m_cur
class const_iterator;
class iterator
{
WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
- wxUniCharRef::CreateForString(m_cur))
+ wxUniCharRef::CreateForString(m_cur));
friend class const_iterator;
};
// NB: reference_type is intentionally value, not reference, the character
// may be encoded differently in wxString data:
WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar,
- wxUniChar(*m_cur))
+ wxUniChar(*m_cur));
public:
const_iterator(const iterator& i) : m_cur(i.m_cur) {}
private:
wxStringImpl m_impl;
+
+ // buffers for compatibility conversion from (char*)c_str() and
+ // (wchar_t*)c_str():
+ // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
+ template<typename T>
+ struct ConvertedBuffer
+ {
+ ConvertedBuffer() : m_buf(NULL) {}
+ ~ConvertedBuffer()
+ { free(m_buf); }
+
+ operator const T*() const { return m_buf; }
+
+ ConvertedBuffer& operator=(T *str)
+ {
+ free(m_buf);
+ m_buf = str;
+ return *this;
+ }
+
+ T *m_buf;
+ };
+#if wxUSE_UNICODE
+ ConvertedBuffer<char> m_convertedToChar;
+#endif
+#if !wxUSE_UNICODE_WCHAR
+ ConvertedBuffer<wchar_t> m_convertedToWChar;
+#endif
+ friend class WXDLLIMPEXP_BASE wxCStrData;
};
#ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
inline wxCStrData::operator bool() const
{
return !m_str->empty();
-};
+}
// simple cases for AsChar() and AsWChar(), the complicated ones are
// in string.cpp
return m_str->at(m_offset + n);
}
+// ----------------------------------------------------------------------------
+// more wxCStrData operators
+// ----------------------------------------------------------------------------
+
+// we need to define those to allow "size_t pos = p - s.c_str()" where p is
+// some pointer into the string
+inline size_t operator-(const char *p, const wxCStrData& cs)
+{
+ return p - cs.AsChar();
+}
+
+inline size_t operator-(const wchar_t *p, const wxCStrData& cs)
+{
+ return p - cs.AsWChar();
+}
+
// ----------------------------------------------------------------------------
// implementation of wx[W]CharBuffer inline methods using wxCStrData
// ----------------------------------------------------------------------------