]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/string.h
moved vararg handling code in wxMessageOutput to single method and added simple Outpu...
[wxWidgets.git] / include / wx / string.h
index dd56e13c7afdfca876af5dabaae9a41dfd60429a..5f3801ef5126193e7eac677cd47f2614b8b128ce 100644 (file)
@@ -169,7 +169,7 @@ inline int Stricmp(const char *psz1, const char *psz2)
 
 // 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
@@ -182,13 +182,22 @@ public:
     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(); }
@@ -197,11 +206,11 @@ public:
 
     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)); }
@@ -239,7 +248,7 @@ public:
 
     // 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;
@@ -562,8 +571,6 @@ public:
   wxString(const wxString& str, size_t nLength)
       : m_impl(str.Mid(0, nLength).m_impl) {}
 
-  ~wxString();
-
 public:
   // standard types
   typedef wxUniChar value_type;
@@ -622,16 +629,16 @@ public:
             { 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                     \
@@ -657,14 +664,14 @@ public:
           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;
   };
@@ -674,7 +681,7 @@ public:
       // 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) {}
@@ -1992,6 +1999,35 @@ private:
 
 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
@@ -2299,7 +2335,7 @@ inline wxCStrData::~wxCStrData()
 inline wxCStrData::operator bool() const
 {
     return !m_str->empty();
-};
+}
 
 // simple cases for AsChar() and AsWChar(), the complicated ones are
 // in string.cpp
@@ -2338,6 +2374,22 @@ inline wxUniChar wxCStrData::operator[](size_t n) const
     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
 // ----------------------------------------------------------------------------