Kaydet (Commit) 5252652a authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Introduce OStringBuffer::appendUninitialized

...corresponding to the OUStringBuffer couterpart

Change-Id: I3ab03343696e6755cf1ccc470e4decc2f41d2558
üst 04ae3d0c
......@@ -101,7 +101,9 @@ SAL_DLLPUBLIC void SAL_CALL rtl_stringbuffer_ensureCapacity(
@param[in,out] This the String to operate on.
@param[in,out] capacity the capacity of the string buffer
@param[in] offset the offset.
@param[in] str a character array.
@param[in] str a character array. Since LibreOffice 4.4, as a
special case, if str is null then the len added
characters are left uninitialized.
@param[in] len the number of characters to append.
*/
SAL_DLLPUBLIC void SAL_CALL rtl_stringbuffer_insert(
......
......@@ -490,6 +490,7 @@ public:
OStringBuffer & append( const sal_Char * str, sal_Int32 len)
{
assert( len >= 0 );
assert( len == 0 || str != 0 );
rtl_stringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
return *this;
}
......@@ -644,6 +645,28 @@ public:
return append( sz, rtl_str_valueOfDouble( sz, d ) );
}
/**
Unsafe way to make space for a fixed amount of characters to be appended
into this OStringBuffer.
A call to this function must immediately be followed by code that
completely fills the uninitialized block pointed to by the return value.
@param length the length of the uninitialized block of char entities;
must be non-negative
@return a pointer to the start of the uninitialized block; only valid
until this OStringBuffer's capacity changes
@since LibreOffice 4.4
*/
char * appendUninitialized(sal_Int32 length) {
assert(length >= 0);
sal_Int32 n = getLength();
rtl_stringbuffer_insert(&pData, &nCapacity, n, 0, length);
return pData->buffer + n;
}
/**
Inserts the string into this string buffer.
......@@ -729,6 +752,7 @@ public:
{
assert( offset >= 0 && offset <= pData->length );
assert( len >= 0 );
assert( len == 0 || str != 0 );
rtl_stringbuffer_insert( &pData, &nCapacity, offset, str, len );
return *this;
}
......
......@@ -222,6 +222,7 @@ struct StringTraits
sal_Int32 * pOffset, sal_Char const * pChars,
sal_Int32 nLen)
{
assert(pChars != nullptr);
rtl_stringbuffer_insert(pBuffer, pCapacity, *pOffset, pChars, nLen);
*pOffset += nLen;
}
......@@ -230,6 +231,7 @@ struct StringTraits
sal_Int32 * pOffset, sal_Char const * pStr,
sal_Int32 nLen)
{
assert(pStr != nullptr);
rtl_stringbuffer_insert(pBuffer, pCapacity, *pOffset, pStr, nLen);
*pOffset += nLen;
}
......
......@@ -114,11 +114,14 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This,
memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Char) );
/* insert the new characters */
if( len == 1 )
if( str != nullptr )
{
if( len == 1 )
/* optimized for 1 character */
pBuf[offset] = *str;
else
memcpy( pBuf + offset, str, len * sizeof(sal_Char) );
pBuf[offset] = *str;
else
memcpy( pBuf + offset, str, len * sizeof(sal_Char) );
}
(*This)->length = nOldLen + len;
pBuf[ nOldLen + len ] = 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment