// Lightweight object returned by wxString::c_str() and implicitly convertible
// to either const char* or const wchar_t*.
-class wxCStrData
+class WXDLLIMPEXP_BASE wxCStrData
{
private:
// Ctors; for internal use by wxString and wxCStrData only
wxCStrData(char *buf);
wxCStrData(wchar_t *buf);
- ~wxCStrData();
+ inline ~wxCStrData();
+ // methods defined inline below must be declared inline or mingw32 3.4.5
+ // warns about "<symbol> defined locally after being referenced with
+ // dllimport linkage"
+#if wxUSE_UNICODE_WCHAR
+ inline
+#endif
const wchar_t* AsWChar() const;
operator const wchar_t*() const { return AsWChar(); }
- operator bool() const;
+ inline operator bool() const;
+#if !wxUSE_UNICODE
+ inline
+#endif
const char* AsChar() const;
const unsigned char* AsUnsignedChar() const
{ return (const unsigned char *) AsChar(); }
operator const void*() const { return AsChar(); }
- wxString AsString() const;
+ inline wxString AsString() const;
// allow expressions like "c_str()[0]":
+ inline wxUniChar operator[](size_t n) const;
wxUniChar operator[](int n) const { return operator[](size_t(n)); }
- wxUniChar operator[](size_t n) const;
wxUniChar operator[](long n) const { return operator[](size_t(n)); }
#ifndef wxSIZE_T_IS_UINT
wxUniChar operator[](unsigned int n) const { return operator[](size_t(n)); }
// this operator is needed to make expressions like "*c_str()" or
// "*(c_str() + 2)" work
- wxUniChar operator*() const;
+ inline wxUniChar operator*() const;
private:
const wxString *m_str;
wxString(const wxString& str, size_t nLength)
: m_impl(str.Mid(0, nLength).m_impl) {}
- ~wxString();
-
public:
// standard types
typedef wxUniChar value_type;
{ return iterator_name(wxString::AddToIter(m_cur, -n)); } \
iterator_name operator-(size_t n) const \
{ return iterator_name(wxString::AddToIter(m_cur, -(int)n)); } \
- iterator_name operator+=(int n) \
+ iterator_name& operator+=(int n) \
{ m_cur = wxString::AddToIter(m_cur, n); return *this; } \
- iterator_name operator+=(size_t n) \
+ iterator_name& operator+=(size_t n) \
{ m_cur = wxString::AddToIter(m_cur, (int)n); return *this; } \
- iterator_name operator-=(int n) \
+ iterator_name& operator-=(int n) \
{ m_cur = wxString::AddToIter(m_cur, -n); return *this; } \
- iterator_name operator-=(size_t n) \
+ 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 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
// ----------------------------------------------------------------------------