summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-09-20 11:34:35 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-09-20 11:34:35 +0200
commit95ee4cab864c0bafb23bc7d0e3ac25a0d91e22f8 (patch)
tree75cbe1c7e51d51912bd3fc034aec4767aeaf3a9d /include
parent7e965ee623a31392d86eb925acaf8ea664a33da7 (diff)
Related cid#1371289: Work around missing OUStringBuffer move semantics
...by adding more assign op overloads instead Change-Id: I2d2e1b7f19d1b57528707ed5a5cce94b5fa5c2d0
Diffstat (limited to 'include')
-rw-r--r--include/rtl/ustrbuf.hxx78
1 files changed, 77 insertions, 1 deletions
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 <cassert>
#include <cstddef>
-#include <string.h>
+#include <cstring>
#include <rtl/ustrbuf.h>
#include <rtl/ustring.hxx>
@@ -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 T>
+ typename
+ libreoffice_internal::ConstCharArrayDetector<T, OUStringBuffer &>::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
+ }
+ char const * from
+ = libreoffice_internal::ConstCharArrayDetector<T>::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 T>
+ typename libreoffice_internal::ConstCharArrayDetector<
+ T, OUStringBuffer &>::TypeUtf16
+ operator =(T & 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) * sizeof (sal_Unicode)); //TODO: check for overflow
+ pData->length = n;
+ return *this;
+ }
+#endif
+
+#if defined LIBO_INTERNAL_ONLY
+ /** @overload @since LibreOffice 5.3 */
+ template<typename T1, typename T2>
+ OUStringBuffer & operator =(OUStringConcat<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.
*/