From df4c929bc36c168a55c3467c783fd0256b90dc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 12 Jun 2012 09:51:38 +0100 Subject: [PATCH] don't need to realloc string Change-Id: I17ec5a54b0088b56bd8c8431eb255626dbb1fac8 --- comphelper/inc/comphelper/string.hxx | 3 ++- editeng/source/editeng/editdoc.cxx | 16 +++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 8a763e85e2f8..908832789688 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -49,7 +49,8 @@ namespace comphelper { namespace string { /** Allocate a new string containing space for a given number of characters. The reference count of the new string will be 1. The length of the string - will be nLen. This function does not handle out-of-memory conditions. + will be nLen. This function throws std::bad_alloc on out-of-memory + conditions. The characters of the capacity are not cleared, and the length is set to nLen, unlike the similar method of rtl_uString_new_WithLength which diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 110daf5e58d0..fe747c35786a 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -26,7 +26,7 @@ * ************************************************************************/ - +#include #include #include #include @@ -2037,7 +2037,7 @@ XubString EditDoc::GetText( LineEnd eEnd ) const sal_uLong nLen = GetTextLen(); size_t nNodes = Count(); if (nNodes == 0) - return String(); + return rtl::OUString(); rtl::OUString aSep = EditDoc::GetSepStr( eEnd ); sal_Int32 nSepSize = aSep.getLength(); @@ -2047,10 +2047,11 @@ XubString EditDoc::GetText( LineEnd eEnd ) const if ( nLen > 0xFFFb / sizeof(xub_Unicode) ) { OSL_FAIL( "Text too large for String" ); - return String(); + return rtl::OUString(); } - xub_Unicode* pStr = new xub_Unicode[nLen+1]; - xub_Unicode* pCur = pStr; + + rtl_uString* newStr = comphelper::string::rtl_uString_alloc(nLen); + xub_Unicode* pCur = newStr->buffer; size_t nLastNode = nNodes-1; for ( sal_uInt16 nNode = 0; nNode < nNodes; nNode++ ) { @@ -2063,10 +2064,7 @@ XubString EditDoc::GetText( LineEnd eEnd ) const pCur += nSepSize; } } - *pCur = '\0'; - String aASCIIText( pStr ); - delete[] pStr; - return aASCIIText; + return rtl::OUString(newStr, SAL_NO_ACQUIRE); } XubString EditDoc::GetParaAsString( sal_uInt16 nNode ) const