Added the ability to get a mutable char* from a CString, which will copy the internal
buffer if the ref count is greater than 1 so your mutable char* won't affect any other
referrer of that buffer.
* platform/CString.cpp:
(WebCore::CString::mutableData):
(WebCore::CString::copyBufferIfNeeded):
* platform/CString.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16385
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-09-15 Brady Eidson <beidson@apple.com>
+
+ Reviewed by Anders
+
+ Added the ability to get a mutable char* from a CString, which will copy the internal
+ buffer if the ref count is greater than 1 so your mutable char* won't affect any other
+ referrer of that buffer.
+
+ * platform/CString.cpp:
+ (WebCore::CString::mutableData):
+ (WebCore::CString::copyBufferIfNeeded):
+ * platform/CString.h:
+
2006-09-15 Justin Garcia <justin.garcia@apple.com>
Reviewed by harrison
{
return m_buffer ? m_buffer->data() : 0;
}
+
+char* CString::mutableData()
+{
+ copyBufferIfNeeded();
+ if (!m_buffer)
+ return 0;
+ return m_buffer->data();
+}
unsigned CString::length() const
{
return result;
}
+void CString::copyBufferIfNeeded()
+{
+ if (!m_buffer || m_buffer->hasOneRef())
+ return;
+
+ int len = m_buffer->length();
+ RefPtr<CStringBuffer> m_temp = m_buffer;
+ m_buffer = new CStringBuffer(len);
+ memcpy(m_buffer->data(), m_temp->data(), len);
+}
+
}
static CString newUninitialized(size_t length, char*& characterBuffer);
const char* data() const;
+ char* mutableData();
unsigned length() const;
operator const char*() const { return data(); }
DeprecatedCString deprecatedCString() const;
private:
+ void copyBufferIfNeeded();
void init(const char*, unsigned length);
RefPtr<CStringBuffer> m_buffer;
};