From 95ee4cab864c0bafb23bc7d0e3ac25a0d91e22f8 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 20 Sep 2016 11:34:35 +0200 Subject: Related cid#1371289: Work around missing OUStringBuffer move semantics ...by adding more assign op overloads instead Change-Id: I2d2e1b7f19d1b57528707ed5a5cce94b5fa5c2d0 --- include/rtl/ustrbuf.hxx | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'include/rtl') diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 8cfcabe043b4..ecae7f03e129 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -222,6 +222,82 @@ public: return *this; } + /** Assign from a string. + + @since LibreOffice 5.3 + */ + OUStringBuffer & operator =(OUString 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) * sizeof (sal_Unicode)); + 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 + } + char const * from + = libreoffice_internal::ConstCharArrayDetector::toPointer( + literal); + sal_Unicode * to = pData->buffer; + for (sal_Int32 i = 0; i <= n; ++i) { + to[i] = from[i]; + } + pData->length = n; + return *this; + } + +#if defined LIBO_INTERNAL_ONLY + /** @overload @since LibreOffice 5.3 */ + template + typename libreoffice_internal::ConstCharArrayDetector< + T, OUStringBuffer &>::TypeUtf16 + operator =(T & 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) * sizeof (sal_Unicode)); //TODO: check for overflow + pData->length = n; + return *this; + } +#endif + +#if defined LIBO_INTERNAL_ONLY + /** @overload @since LibreOffice 5.3 */ + template + OUStringBuffer & operator =(OUStringConcat 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