summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-06-12 09:51:38 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-06-12 13:35:49 +0100
commitdf4c929bc36c168a55c3467c783fd0256b90dc45 (patch)
tree645c086662ca4b710e46c7427af39c2a05ba5c1f
parent17ebc5540e3f80b04d38ba2000a1db96822874f6 (diff)
don't need to realloc string
Change-Id: I17ec5a54b0088b56bd8c8431eb255626dbb1fac8
-rw-r--r--comphelper/inc/comphelper/string.hxx3
-rw-r--r--editeng/source/editeng/editdoc.cxx16
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