diff options
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 3 | ||||
-rw-r--r-- | 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 <comphelper/string.hxx> #include <vcl/wrkwin.hxx> #include <vcl/dialog.hxx> #include <vcl/msgbox.hxx> @@ -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 |