summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-11-22 14:08:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-11-23 14:00:08 +0100
commitec1c4c49301758c54394f9943252e192ad54638b (patch)
treeb53af3cb9154a388495b1af35c3f8ff41d6ebe1f /sal
parentdb0f2c29bf3a6ad5a08f8524ea0e65aa90792bb2 (diff)
O[U]String::replaceAt overloads that take string_view
which results in lots of nice string_view improvements picked up by the plugins Change-Id: Ib0ec3887816b3d4436d003b739d9814f83e244b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125657 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/bootstrap.cxx2
-rw-r--r--sal/rtl/string.cxx36
-rw-r--r--sal/rtl/strtmpl.hxx74
-rw-r--r--sal/rtl/ustring.cxx7
-rw-r--r--sal/util/sal.map6
5 files changed, 124 insertions, 1 deletions
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index e651a8436363..93d1c5a11648 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -255,7 +255,7 @@ static OUString & getIniFileName_Impl()
// rc files in LIBO_ETC_FOLDER (typically "Resources").
sal_Int32 off = fileName.lastIndexOf( "/MacOS/" );
if (off != -1)
- fileName = fileName.replaceAt(off + 1, strlen("MacOS"), LIBO_ETC_FOLDER);
+ fileName = fileName.replaceAt(off + 1, strlen("MacOS"), u"" LIBO_ETC_FOLDER);
#endif
}
#endif
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index b8a96d43a07b..d67246dc159c 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -659,6 +659,35 @@ void SAL_CALL rtl_string_newConcat(rtl_String** ppThis, rtl_String* pLeft, rtl_S
rtl::str::newConcat(ppThis, pLeft, pRight);
}
+static void rtl_string_newConcatL(
+ rtl_String ** newString, rtl_String * left, char const * right,
+ sal_Int32 rightLength)
+{
+ assert(newString != nullptr);
+ assert(left != nullptr);
+ assert(right != nullptr || rightLength == 0);
+ assert(rightLength >= 0);
+ if (left->length > std::numeric_limits<sal_Int32>::max() - rightLength) {
+#if !defined(__COVERITY__)
+ throw std::length_error("rtl_string_newConcatL");
+#else
+ //coverity doesn't report std::bad_alloc as an unhandled exception when
+ //potentially thrown from destructors but does report std::length_error
+ throw std::bad_alloc();
+#endif
+ }
+ sal_Int32 n = left->length + rightLength;
+ rtl_string_assign(newString, left);
+ rtl_string_ensureCapacity(newString, n);
+ if (rightLength != 0) {
+ memcpy(
+ (*newString)->buffer + (*newString)->length, right,
+ rightLength);
+ }
+ (*newString)->buffer[n] = 0;
+ (*newString)->length = n;
+}
+
void SAL_CALL rtl_string_ensureCapacity(rtl_String** ppThis, sal_Int32 size) SAL_THROW_EXTERN_C()
{
rtl::str::ensureCapacity(ppThis, size);
@@ -671,6 +700,13 @@ void SAL_CALL rtl_string_newReplaceStrAt(rtl_String** ppThis, rtl_String* pStr,
rtl::str::newReplaceStrAt(ppThis, pStr, nIndex, nCount, pNewSubStr);
}
+void SAL_CALL rtl_string_newReplaceStrAt_WithLength(rtl_String** ppThis, rtl_String* pStr, sal_Int32 nIndex,
+ sal_Int32 nCount, char const * subStr, sal_Int32 substrLen)
+ SAL_THROW_EXTERN_C()
+{
+ rtl::str::newReplaceStrAt(ppThis, pStr, nIndex, nCount, subStr, substrLen);
+}
+
void SAL_CALL rtl_string_newReplace(rtl_String** ppThis, rtl_String* pStr, char cOld, char cNew)
SAL_THROW_EXTERN_C()
{
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index f26c21225177..7a909bb5efe3 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -1466,6 +1466,80 @@ void newReplaceStrAt ( IMPL_RTL_STRINGDATA** ppTh
/* ----------------------------------------------------------------------- */
+template <typename IMPL_RTL_STRINGDATA, typename IMPL_RTL_STRCODE>
+void newReplaceStrAt ( IMPL_RTL_STRINGDATA** ppThis,
+ IMPL_RTL_STRINGDATA* pStr,
+ sal_Int32 nIndex,
+ sal_Int32 nCount,
+ const IMPL_RTL_STRCODE* pNewSubStr,
+ sal_Int32 nNewSubStrLen )
+{
+ assert(ppThis);
+ assert(nIndex >= 0 && nIndex <= pStr->length);
+ assert(nCount >= 0);
+ assert(nCount <= pStr->length - nIndex);
+ assert(pNewSubStr);
+ assert(nNewSubStrLen >= 0);
+ /* Append? */
+ if ( nIndex >= pStr->length )
+ {
+ if constexpr (sizeof(IMPL_RTL_STRCODE) == sizeof(char))
+ rtl_string_newConcatL( ppThis, pStr, pNewSubStr, nNewSubStrLen );
+ else
+ rtl_uString_newConcatUtf16L( ppThis, pStr, pNewSubStr, nNewSubStrLen );
+ return;
+ }
+
+ /* not more than the String length could be deleted */
+ if ( nCount >= pStr->length-nIndex )
+ {
+ nCount = pStr->length-nIndex;
+
+ /* Assign of NewSubStr? */
+ if ( !nIndex && (nCount >= pStr->length) )
+ {
+ newFromStr_WithLength( ppThis, pNewSubStr, nNewSubStrLen );
+ return;
+ }
+ }
+
+ /* Assign of Str? */
+ if ( !nCount && !nNewSubStrLen )
+ {
+ assign( ppThis, pStr );
+ return;
+ }
+
+ IMPL_RTL_STRINGDATA* pOrg = *ppThis;
+ sal_Int32 nNewLen;
+
+ /* Calculate length of the new string */
+ nNewLen = pStr->length-nCount + nNewSubStrLen;
+
+ /* Alloc New Buffer */
+ *ppThis = Alloc<IMPL_RTL_STRINGDATA>( nNewLen );
+ OSL_ASSERT(*ppThis != nullptr);
+ auto* pBuffer = (*ppThis)->buffer;
+ if ( nIndex )
+ {
+ Copy( pBuffer, pStr->buffer, nIndex );
+ pBuffer += nIndex;
+ }
+ if ( nNewSubStrLen )
+ {
+ Copy( pBuffer, pNewSubStr, nNewSubStrLen );
+ pBuffer += nNewSubStrLen;
+ }
+ Copy( pBuffer, pStr->buffer+nIndex+nCount, pStr->length-nIndex-nCount );
+
+ RTL_LOG_STRING_NEW( *ppThis );
+ /* must be done last, if pStr or pNewSubStr == *ppThis */
+ if ( pOrg )
+ release( pOrg );
+}
+
+/* ----------------------------------------------------------------------- */
+
template <typename IMPL_RTL_STRINGDATA>
void newReplace ( IMPL_RTL_STRINGDATA** ppThis,
IMPL_RTL_STRINGDATA* pStr,
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index ee84510bcc7f..64f13cabc7ee 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -1866,6 +1866,13 @@ void SAL_CALL rtl_uString_newReplaceStrAt(rtl_uString** ppThis, rtl_uString* pSt
rtl::str::newReplaceStrAt(ppThis, pStr, nIndex, nCount, pNewSubStr);
}
+void SAL_CALL rtl_uString_newReplaceStrAtUtf16L(rtl_uString** ppThis, rtl_uString* pStr, sal_Int32 nIndex,
+ sal_Int32 nCount, sal_Unicode const * subStr, sal_Int32 substrLen)
+ SAL_THROW_EXTERN_C()
+{
+ rtl::str::newReplaceStrAt(ppThis, pStr, nIndex, nCount, subStr, substrLen);
+}
+
void SAL_CALL rtl_uString_newReplace(rtl_uString** ppThis, rtl_uString* pStr, sal_Unicode cOld,
sal_Unicode cNew) SAL_THROW_EXTERN_C()
{
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 49efb2a436cd..c5c3e4d55641 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -755,6 +755,12 @@ PRIVATE_1.7 { # LibreOffice 7.1
rtl_uString_newReplaceAllFromIndexUtf16LUtf16L;
} PRIVATE_1.5;
+PRIVATE_1.8 { # LibreOffice 7.3
+ global:
+ rtl_string_newReplaceStrAt_WithLength;
+ rtl_uString_newReplaceStrAtUtf16L;
+} PRIVATE_1.7;
+
PRIVATE_textenc.1 { # LibreOffice 3.6
global:
_ZN3sal6detail7textenc20convertCharToUnicode*;