diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-09-20 11:36:24 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-09-20 11:36:24 +0200 |
commit | e1954f5ba5f637c9df801401db3630c8e1138ccf (patch) | |
tree | 3b72573f52d5d461371c0ba12fad803b318d45b6 | |
parent | 95ee4cab864c0bafb23bc7d0e3ac25a0d91e22f8 (diff) |
Related cid#1371287: Work around missing OStringBuffer move semantics
...by adding more assign op overloads instead
Change-Id: I3686d6c29adc47b1a8c48be4260614fd53589c8b
-rw-r--r-- | include/rtl/strbuf.hxx | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx index 2798e92883d1..0fc3284a89f9 100644 --- a/include/rtl/strbuf.hxx +++ b/include/rtl/strbuf.hxx @@ -24,7 +24,7 @@ #include <cassert> #include <cstddef> -#include <string.h> +#include <cstring> #include <rtl/strbuf.h> #include <rtl/string.hxx> @@ -234,6 +234,57 @@ public: return *this; } + /** Assign from a string. + + @since LibreOffice 5.3 + */ + OStringBuffer & operator =(OString const & string) { + sal_Int32 n = string.getLength(); + if (n >= nCapacity) { + ensureCapacity(n + 16); //TODO: check for overflow + } + std::memcpy(pData->buffer, string.pData->buffer, n + 1); + pData->length = n; + return *this; + } + + /** Assign from a string literal. + + @since LibreOffice 5.3 + */ + template<typename T> + typename + libreoffice_internal::ConstCharArrayDetector<T, OStringBuffer &>::Type + operator =(T & literal) { + assert( + libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal)); + sal_Int32 const n + = libreoffice_internal::ConstCharArrayDetector<T>::length; + if (n >= nCapacity) { + ensureCapacity(n + 16); //TODO: check for overflow + } + std::memcpy( + pData->buffer, + libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal), + n + 1); + pData->length = n; + return *this; + } + +#if defined LIBO_INTERNAL_ONLY + /** @overload @since LibreOffice 5.3 */ + template<typename T1, typename T2> + OStringBuffer & operator =(OStringConcat<T1, T2> const & concat) { + sal_Int32 const n = concat.length(); + if (n >= nCapacity) { + ensureCapacity(n + 16); //TODO: check for overflow + } + *concat.addData(pData->buffer) = 0; + pData->length = n; + return *this; + } +#endif + /** Release the string data. */ |