summaryrefslogtreecommitdiff
path: root/sal/rtl/source
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-12-04 19:27:34 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-12-06 13:35:17 +0100
commitb88a26f02276ec2e98287cd2e5f2abea1ea9e949 (patch)
tree42997756a94ee8bf4614f01a19994927783660e7 /sal/rtl/source
parent5c61b8e87b6a8cda82a0857fdae4d2b2215552fb (diff)
rtl_(u)String_ensureCapacity
Ensure there will be enough extra space in a string, to be used for string appending. A bit like rtl_(u)String_newConcat(), but without the function actually appending anything. Unlike the stringbuffer variant this does not allocate any extra. Change-Id: Ic6f84bf014a713f9912c81d8f1405c593978822d
Diffstat (limited to 'sal/rtl/source')
-rw-r--r--sal/rtl/source/strtmpl.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx
index 8001e0a250a7..afeb2db8ca60 100644
--- a/sal/rtl/source/strtmpl.cxx
+++ b/sal/rtl/source/strtmpl.cxx
@@ -1318,6 +1318,29 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis,
/* ----------------------------------------------------------------------- */
+void SAL_CALL IMPL_RTL_STRINGNAME( ensureCapacity )( IMPL_RTL_STRINGDATA** ppThis,
+ sal_Int32 size )
+ SAL_THROW_EXTERN_C()
+{
+ IMPL_RTL_STRINGDATA* const pOrg = *ppThis;
+ if ( pOrg->refCount == 1 && pOrg->length >= size )
+ return;
+ assert( pOrg->length <= size ); // do not truncate
+ IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( size );
+ rtl_str_ImplCopy( pTempStr->buffer, pOrg->buffer, pOrg->length );
+ // right now the length is still the same as of the original
+ pTempStr->length = pOrg->length;
+ pTempStr->buffer[ pOrg->length ] = '\0';
+ *ppThis = pTempStr;
+ RTL_LOG_STRING_NEW( *ppThis );
+
+ /* must be done last, if pStr == *ppThis */
+ if ( pOrg )
+ IMPL_RTL_STRINGNAME( release )( pOrg );
+}
+
+/* ----------------------------------------------------------------------- */
+
void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppThis,
IMPL_RTL_STRINGDATA* pStr,
sal_Int32 nIndex,