The buffer's destructor will not destroy @a str. The returned buffer's
data is valid only as long as @a str is valid.
+
+ @param str String data.
+ @param len If specified, length of the string, otherwise the string
+ is considered to be NUL-terminated.
*/
- static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str);
+ static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str, size_t len = wxNO_LEN);
/**
Creates owned buffer from @a str and takes ownership of it.
The buffer's destructor will free @a str when its reference count
reaches zero (initial count is 1).
+
+ @param str String data.
+ @param len If specified, length of the string, otherwise the string
+ is considered to be NUL-terminated.
*/
- static const wxScopedCharTypeBuffer CreateOwned(const CharType *str);
+ static const wxScopedCharTypeBuffer CreateOwned(const CharType *str, size_t len = wxNO_LEN);
/**
Copy constructor.
/// Returns const pointer to the stored data.
const CharType *data() const;
+ /// Returns length of the string stored.
+ size_t length() const;
+
/// Implicit conversion to C string.
operator const CharType *() const;
/**
Creates (owned) buffer from @a str and takes ownership of it.
+ @param str String data.
+ @param len If specified, length of the string, otherwise the string
+ is considered to be NUL-terminated.
+
@see wxScopedCharTypeBuffer<T>::CreateOwned()
*/
- wxCharTypeBuffer(const CharType *str = NULL);
+ wxCharTypeBuffer(const CharType *str = NULL, size_t len = wxNO_LEN);
/**
Can only be called on buffers that don't share data with another
buffer (i.e. reference count of the data is 1).
+
+ @see shrink()
*/
bool extend(size_t len);
+
+ /**
+ Shrinks the buffer to have size @a len and NUL-terminates the string
+ at this length.
+
+ Can only be called on buffers that don't share data with another
+ buffer (i.e. reference count of the data is 1).
+
+ @param len Length to shrink to. Must not be larger than current length.
+
+ @note The string is not reallocated to take less memory.
+
+ @since 2.9.0
+
+ @see extend()
+ */
+ bool shrink(size_t len);
};
/**