]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/string.h
check that the version of __sync_sub_and_fetch that returns a value is supported...
[wxWidgets.git] / include / wx / string.h
index 813dc956aaac5144a5d8fa14fe06cc21e2936a82..2d79486f836222ee9c9e1080d84986d5c5c3666e 100644 (file)
@@ -380,8 +380,9 @@ protected:
 
 #if wxUSE_UNICODE_UTF8
 // see the comment near wxString::iterator for why we need this
-struct WXDLLIMPEXP_BASE wxStringIteratorNode
+class WXDLLIMPEXP_BASE wxStringIteratorNode
 {
+public:
     wxStringIteratorNode()
         : m_str(NULL), m_citer(NULL), m_iter(NULL), m_prev(NULL), m_next(NULL) {}
     wxStringIteratorNode(const wxString *str,
@@ -933,7 +934,7 @@ public:
   wxString(const wxString& stringSrc) : m_impl(stringSrc.m_impl) { }
 
     // string containing nRepeat copies of ch
-  wxString(wxUniChar ch, size_t nRepeat = 1)
+  wxString(wxUniChar ch, size_t nRepeat = 1 )
     { assign(nRepeat, ch); }
   wxString(size_t nRepeat, wxUniChar ch)
     { assign(nRepeat, ch); }
@@ -1087,19 +1088,25 @@ public:
 
   void resize(size_t nSize, wxUniChar ch = wxT('\0'))
   {
+    const size_t len = length();
+    if ( nSize == len)
+        return;
+
 #if wxUSE_UNICODE_UTF8
-    if ( !ch.IsAscii() )
+    if ( nSize < len )
     {
-        size_t len = length();
-        if ( nSize == len)
-            return;
-        else if ( nSize < len )
-            erase(nSize);
-        else
-            append(nSize - len, ch);
+        // we can't use wxStringImpl::resize() for truncating the string as it
+        // counts in bytes, not characters
+        erase(nSize);
+        return;
     }
+
+    // we also can't use (presumably more efficient) resize() if we have to
+    // append characters taking more than one byte
+    if ( !ch.IsAscii() )
+        append(nSize - len, ch);
     else
-#endif
+#endif // wxUSE_UNICODE_UTF8
         m_impl.resize(nSize, (wxStringCharType)ch);
   }
 
@@ -1365,11 +1372,7 @@ public:
 #if wxUSE_WCHAR_T
     const wxWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
 #endif // wxUSE_WCHAR_T
-#ifdef __WXOSX__
     const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLocal ) ); }
-#else
-    const wxChar* fn_str() const { return c_str(); }
-#endif
 #endif // Unicode/ANSI
 
   // overloaded assignment
@@ -2644,8 +2647,8 @@ private:
 #endif // wxUSE_UNICODE_UTF8
 
   friend class WXDLLIMPEXP_FWD_BASE wxCStrData;
-  friend class wxImplStringBuffer;
-  friend class wxImplStringBufferLength;
+  friend class wxStringInternalBuffer;
+  friend class wxStringInternalBufferLength;
 };
 
 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
@@ -2707,16 +2710,16 @@ inline wxString operator+(wchar_t ch, const wxString& string)
 #if !wxUSE_STL_BASED_WXSTRING
 // string buffer for direct access to string data in their native
 // representation:
-class wxImplStringBuffer
+class wxStringInternalBuffer
 {
 public:
     typedef wxStringCharType CharType;
 
-    wxImplStringBuffer(wxString& str, size_t lenWanted = 1024)
+    wxStringInternalBuffer(wxString& str, size_t lenWanted = 1024)
         : m_str(str), m_buf(NULL)
         { m_buf = m_str.DoGetWriteBuf(lenWanted); }
 
-    ~wxImplStringBuffer() { m_str.DoUngetWriteBuf(); }
+    ~wxStringInternalBuffer() { m_str.DoUngetWriteBuf(); }
 
     operator wxStringCharType*() const { return m_buf; }
 
@@ -2724,22 +2727,22 @@ private:
     wxString&         m_str;
     wxStringCharType *m_buf;
 
-    DECLARE_NO_COPY_CLASS(wxImplStringBuffer)
+    DECLARE_NO_COPY_CLASS(wxStringInternalBuffer)
 };
 
-class wxImplStringBufferLength
+class wxStringInternalBufferLength
 {
 public:
     typedef wxStringCharType CharType;
 
-    wxImplStringBufferLength(wxString& str, size_t lenWanted = 1024)
+    wxStringInternalBufferLength(wxString& str, size_t lenWanted = 1024)
         : m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
     {
         m_buf = m_str.DoGetWriteBuf(lenWanted);
         wxASSERT(m_buf != NULL);
     }
 
-    ~wxImplStringBufferLength()
+    ~wxStringInternalBufferLength()
     {
         wxASSERT(m_lenSet);
         m_str.DoUngetWriteBuf(m_len);
@@ -2754,13 +2757,13 @@ private:
     size_t            m_len;
     bool              m_lenSet;
 
-    DECLARE_NO_COPY_CLASS(wxImplStringBufferLength)
+    DECLARE_NO_COPY_CLASS(wxStringInternalBufferLength)
 };
 
 #endif // !wxUSE_STL_BASED_WXSTRING
 
 template<typename T>
-class wxStringTypeBufferBase
+class WXDLLIMPEXP_BASE wxStringTypeBufferBase
 {
 public:
     typedef T CharType;
@@ -2778,7 +2781,7 @@ protected:
 };
 
 template<typename T>
-class wxStringTypeBufferLengthBase
+class WXDLLIMPEXP_BASE wxStringTypeBufferLengthBase
 {
 public:
     typedef T CharType;
@@ -2787,12 +2790,6 @@ public:
         : m_str(str), m_buf(lenWanted), m_len(0), m_lenSet(false)
         { }
 
-    ~wxStringTypeBufferLengthBase()
-    {
-        wxASSERT(m_lenSet);
-        m_str.assign(m_buf.data(), m_len);
-    }
-
     operator CharType*() { return m_buf.data(); }
     void SetLength(size_t length) { m_len = length; m_lenSet = true; }
 
@@ -2834,30 +2831,37 @@ public:
 };
 
 #if wxUSE_STL_BASED_WXSTRING
-class wxImplStringBuffer : public wxStringTypeBufferBase<wxStringCharType>
+
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxStringTypeBufferBase<wxStringCharType> )
+
+class wxStringInternalBuffer : public wxStringTypeBufferBase<wxStringCharType>
 {
 public:
-    wxImplStringBuffer(wxString& str, size_t lenWanted = 1024)
+    wxStringInternalBuffer(wxString& str, size_t lenWanted = 1024)
         : wxStringTypeBufferBase<wxStringCharType>(str, lenWanted) {}
-    ~wxImplStringBuffer()
+    ~wxStringInternalBuffer()
         { m_str.m_impl.assign(m_buf.data()); }
 
-    DECLARE_NO_COPY_CLASS(wxImplStringBuffer)
+    DECLARE_NO_COPY_CLASS(wxStringInternalBuffer)
 };
 
-class wxImplStringBufferLength : public wxStringTypeBufferLengthBase<wxStringCharType>
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(
+    wxStringTypeBufferLengthBase<wxStringCharType> )
+
+class wxStringInternalBufferLength
+    : public wxStringTypeBufferLengthBase<wxStringCharType>
 {
 public:
-    wxImplStringBufferLength(wxString& str, size_t lenWanted = 1024)
+    wxStringInternalBufferLength(wxString& str, size_t lenWanted = 1024)
         : wxStringTypeBufferLengthBase<wxStringCharType>(str, lenWanted) {}
 
-    ~wxImplStringBufferLength()
+    ~wxStringInternalBufferLength()
     {
         wxASSERT(m_lenSet);
         m_str.m_impl.assign(m_buf.data(), m_len);
     }
 
-    DECLARE_NO_COPY_CLASS(wxImplStringBufferLength)
+    DECLARE_NO_COPY_CLASS(wxStringInternalBufferLength)
 };
 #endif // wxUSE_STL_BASED_WXSTRING
 
@@ -2866,10 +2870,42 @@ public:
 typedef wxStringTypeBuffer<wxChar>        wxStringBuffer;
 typedef wxStringTypeBufferLength<wxChar>  wxStringBufferLength;
 #else // if !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
-typedef wxImplStringBuffer                wxStringBuffer;
-typedef wxImplStringBufferLength          wxStringBufferLength;
+typedef wxStringInternalBuffer                wxStringBuffer;
+typedef wxStringInternalBufferLength          wxStringBufferLength;
 #endif // !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
 
+#if wxUSE_UNICODE_UTF8
+typedef wxStringInternalBuffer                wxUTF8StringBuffer;
+typedef wxStringInternalBufferLength          wxUTF8StringBufferLength;
+#elif wxUSE_UNICODE_WCHAR
+
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxStringTypeBufferBase<char> )
+
+class WXDLLIMPEXP_BASE wxUTF8StringBuffer : public wxStringTypeBufferBase<char>
+{
+public:
+    wxUTF8StringBuffer(wxString& str, size_t lenWanted = 1024)
+        : wxStringTypeBufferBase<char>(str, lenWanted) {}
+    ~wxUTF8StringBuffer();
+
+    DECLARE_NO_COPY_CLASS(wxUTF8StringBuffer)
+};
+
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxStringTypeBufferLengthBase<char> )
+
+class WXDLLIMPEXP_BASE wxUTF8StringBufferLength
+    : public wxStringTypeBufferLengthBase<char>
+{
+public:
+    wxUTF8StringBufferLength(wxString& str, size_t lenWanted = 1024)
+        : wxStringTypeBufferLengthBase<char>(str, lenWanted) {}
+    ~wxUTF8StringBufferLength();
+
+    DECLARE_NO_COPY_CLASS(wxUTF8StringBufferLength)
+};
+#endif // wxUSE_UNICODE_UTF8/wxUSE_UNICODE_WCHAR
+
+
 // ---------------------------------------------------------------------------
 // wxString comparison functions: operator versions are always case sensitive
 // ---------------------------------------------------------------------------
@@ -2992,7 +3028,15 @@ WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCharBuffer&);
 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxWCharBuffer&);
 #endif
 
-#endif  // wxSTD_STRING_COMPATIBILITY
+#if wxUSE_UNICODE && defined(HAVE_WOSTREAM)
+
+WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxString&);
+WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxCStrData&);
+WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxWCharBuffer&);
+
+#endif  // wxUSE_UNICODE && defined(HAVE_WOSTREAM)
+
+#endif  // wxUSE_STD_IOSTREAM
 
 // ---------------------------------------------------------------------------
 // wxCStrData implementation