summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 12:54:07 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 19:54:57 +0200
commit6510cbc486867db25d1d772f4a3b0b7b9bb2fc08 (patch)
tree629597e0e801659b06edb181bda017cdd823e04b /comphelper
parent443799ad8c0f5a2ae78ca03fb38618a2273682aa (diff)
elide temporary OUStringBuffer in INetURLObject
which requires a version of replaceAt for OUStringBuffer, which I'll put in comphelper::string:: for now Change-Id: I70b319b018e29a7dac26965dd92f6c4f9ea470ec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134679 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/string.cxx30
1 files changed, 30 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 8daeb377482a..0041f53d153d 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -624,6 +624,36 @@ OUString setToken(const OUString& rIn, sal_Int32 nToken, sal_Unicode cTok,
return rIn;
}
+/** Similar to OUString::replaceAt, but for an OUStringBuffer.
+
+ Replace n = count characters
+ from position index in this string with newStr.
+ */
+void replaceAt(OUStringBuffer& rIn, sal_Int32 nIndex, sal_Int32 nCount, std::u16string_view newStr )
+{
+ assert(nIndex >= 0 && nIndex <= rIn.getLength());
+ assert(nCount >= 0);
+ assert(nCount <= rIn.getLength() - nIndex);
+
+ /* Append? */
+ const sal_Int32 nOldLength = rIn.getLength();
+ if ( nIndex == nOldLength )
+ {
+ rIn.append(newStr);
+ return;
+ }
+
+ sal_Int32 nNewLength = nOldLength + newStr.size() - nCount;
+ if (static_cast<sal_Int32>(newStr.size()) > nCount)
+ rIn.ensureCapacity(nOldLength + newStr.size() - nCount);
+
+ sal_Unicode* pStr = const_cast<sal_Unicode*>(rIn.getStr());
+ memmove(pStr + nIndex + newStr.size(), pStr + nIndex + nCount, nOldLength - nIndex + nCount);
+ memcpy(pStr + nIndex, newStr.data(), newStr.size());
+
+ rIn.setLength(nNewLength);
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */