From e1954f5ba5f637c9df801401db3630c8e1138ccf Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 20 Sep 2016 11:36:24 +0200 Subject: Related cid#1371287: Work around missing OStringBuffer move semantics ...by adding more assign op overloads instead Change-Id: I3686d6c29adc47b1a8c48be4260614fd53589c8b --- include/rtl/strbuf.hxx | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'include/rtl') 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 #include -#include +#include #include #include @@ -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 + libreoffice_internal::ConstCharArrayDetector::Type + operator =(T & literal) { + assert( + libreoffice_internal::ConstCharArrayDetector::isValid(literal)); + sal_Int32 const n + = libreoffice_internal::ConstCharArrayDetector::length; + if (n >= nCapacity) { + ensureCapacity(n + 16); //TODO: check for overflow + } + std::memcpy( + pData->buffer, + libreoffice_internal::ConstCharArrayDetector::toPointer(literal), + n + 1); + pData->length = n; + return *this; + } + +#if defined LIBO_INTERNAL_ONLY + /** @overload @since LibreOffice 5.3 */ + template + OStringBuffer & operator =(OStringConcat 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. */ -- cgit