diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-07 09:13:47 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-08-07 16:14:45 +0100 |
commit | aac04652fda01b0299e17087b151f07d6115e894 (patch) | |
tree | 26a71ba651eb138d81f538b0d43b66f8da8e305d | |
parent | db95e0b75903a34a1b88a3701334e154f32eeceb (diff) |
String::AllocBuffer replacements
Change-Id: I278cd66fb4819721bb473796c28598aaf04eb123
-rw-r--r-- | basic/source/sbx/sbxscan.cxx | 7 | ||||
-rw-r--r-- | editeng/source/editeng/editobj.cxx | 16 | ||||
-rw-r--r-- | editeng/source/items/flditem.cxx | 34 | ||||
-rw-r--r-- | svl/inc/svl/zformat.hxx | 2 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 50 | ||||
-rw-r--r-- | sw/source/core/edit/edglss.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 29 | ||||
-rw-r--r-- | sw/source/filter/ascii/parasc.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/basflt/iodetect.cxx | 9 | ||||
-rw-r--r-- | tools/inc/tools/stream.hxx | 7 | ||||
-rw-r--r-- | tools/source/stream/stream.cxx | 55 | ||||
-rw-r--r-- | vcl/source/gdi/cvtsvm.cxx | 14 |
12 files changed, 87 insertions, 158 deletions
diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx index 9a47d8e67689..32db97fba4e8 100644 --- a/basic/source/sbx/sbxscan.cxx +++ b/basic/source/sbx/sbxscan.cxx @@ -785,9 +785,10 @@ void SbxValue::Format( XubString& rRes, const XubString* pFmt ) const if( nMin < 10 && aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_NN ) ) { // Minute in two digits - sal_Unicode* p = rRes.AllocBuffer( 2 ); - *p++ = '0'; - *p = sal_Unicode( '0' + nMin ); + sal_Unicode aBuf[2]; + aBuf[0] = '0'; + aBuf[1] = '0' + nMin; + rRes = rtl::OUString(aBuf, SAL_N_ELEMENTS(aBuf)); } else { diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index ef84d0b8d5b1..605bf68c95a0 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -26,7 +26,7 @@ * ************************************************************************/ - +#include <comphelper/string.hxx> #include <rtl/strbuf.hxx> #include <vcl/wrkwin.hxx> #include <vcl/dialog.hxx> @@ -1444,6 +1444,8 @@ void BinTextObject::CreateData( SvStream& rIStream ) rIStream >> bUnicodeStrings; if ( bUnicodeStrings ) { + using comphelper::string::rtl_uString_alloc; + for ( sal_uInt16 nPara = 0; nPara < nParagraphs; nPara++ ) { ContentInfo& rC = aContents[nPara]; @@ -1453,18 +1455,18 @@ void BinTextObject::CreateData( SvStream& rIStream ) rIStream >> nL; if ( nL ) { - rC.GetText().AllocBuffer( nL ); - rIStream.Read(rC.GetText().GetBufferAccess(), nL*sizeof(sal_Unicode)); - rC.GetText().ReleaseBufferAccess(nL); + rtl_uString *pStr = rtl_uString_alloc(nL); + rIStream.Read(pStr->buffer, nL*sizeof(sal_Unicode)); + rC.GetText() = rtl::OUString(pStr, SAL_NO_ACQUIRE); } // StyleSheetName rIStream >> nL; if ( nL ) { - rC.GetStyle().AllocBuffer(nL); - rIStream.Read(rC.GetStyle().GetBufferAccess(), nL*sizeof(sal_Unicode) ); - rC.GetStyle().ReleaseBufferAccess(nL); + rtl_uString *pStr = rtl_uString_alloc(nL); + rIStream.Read(pStr->buffer, nL*sizeof(sal_Unicode) ); + rC.GetStyle() = rtl::OUString(pStr, SAL_NO_ACQUIRE); } } } diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx index 6a42e4bb3716..632e00eb95b8 100644 --- a/editeng/source/items/flditem.cxx +++ b/editeng/source/items/flditem.cxx @@ -26,6 +26,7 @@ * ************************************************************************/ +#include <comphelper/string.hxx> #include <vcl/metaact.hxx> #include <svl/zforlist.hxx> #include <tools/urlobj.hxx> @@ -550,25 +551,28 @@ int SvxURLField::operator==( const SvxFieldData& rOther ) const // ----------------------------------------------------------------------- -static void write_unicode( SvPersistStream & rStm, const String& rString ) +static void write_unicode( SvPersistStream & rStm, const rtl::OUString& rString ) { - sal_uInt16 nL = rString.Len(); + sal_uInt16 nL = sal::static_int_cast<sal_uInt16>(rString.getLength()); rStm << nL; - rStm.Write( rString.GetBuffer(), nL*sizeof(sal_Unicode) ); + //endian specific?, yipes! + rStm.Write( rString.getStr(), nL*sizeof(sal_Unicode) ); } -static void read_unicode( SvPersistStream & rStm, rtl::OUString& rString ) +static rtl::OUString read_unicode( SvPersistStream & rStm ) { + rtl_uString *pStr = NULL; sal_uInt16 nL = 0; rStm >> nL; - String aStr; if ( nL ) { - aStr.AllocBuffer( nL ); - rStm.Read( aStr.GetBufferAccess(), nL*sizeof(sal_Unicode) ); - aStr.ReleaseBufferAccess( nL ); + using comphelper::string::rtl_uString_alloc; + pStr = rtl_uString_alloc(nL); + //endian specific?, yipes! + rStm.Read(pStr->buffer, nL*sizeof(sal_Unicode)); } - rString = aStr; + //take ownership of buffer and return, otherwise return empty string + return pStr ? rtl::OUString(pStr, SAL_NO_ACQUIRE) : rtl::OUString(); } void SvxURLField::Load( SvPersistStream & rStm ) @@ -578,9 +582,9 @@ void SvxURLField::Load( SvPersistStream & rStm ) rStm >> nFormat; eFormat= (SvxURLFormat)nFormat; - read_unicode( rStm, aURL ); - read_unicode( rStm, aRepresentation ); - read_unicode( rStm, aTargetFrame ); + aURL = read_unicode( rStm ); + aRepresentation = read_unicode( rStm ); + aTargetFrame = read_unicode( rStm ); } // ----------------------------------------------------------------------- @@ -1088,9 +1092,9 @@ void SvxAuthorField::Load( SvPersistStream & rStm ) { sal_uInt16 nType = 0, nFormat = 0; - read_unicode( rStm, aName ); - read_unicode( rStm, aFirstName ); - read_unicode( rStm, aShortName ); + aName = read_unicode( rStm ); + aFirstName = read_unicode( rStm ); + aShortName = read_unicode( rStm ); rStm >> nType; rStm >> nFormat; diff --git a/svl/inc/svl/zformat.hxx b/svl/inc/svl/zformat.hxx index 0b7438c712f2..05a30e2d640c 100644 --- a/svl/inc/svl/zformat.hxx +++ b/svl/inc/svl/zformat.hxx @@ -239,7 +239,7 @@ public: // Load a string which might contain an Euro symbol, // in fact that could be any string used in number formats. - static void LoadString( SvStream& rStream, String& rStr ); + static rtl::OUString LoadString( SvStream& rStream ); /** * Get output string from a numeric value that fits the number of diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 5f30f3c37177..729ea17c6171 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -170,9 +170,9 @@ void ImpSvNumberformatInfo::Save(SvStream& rStream, sal_uInt16 nAnz) const void ImpSvNumberformatInfo::Load(SvStream& rStream, sal_uInt16 nAnz) { - for (sal_uInt16 i = 0; i < nAnz; i++) + for (sal_uInt16 i = 0; i < nAnz; ++i) { - SvNumberformat::LoadString( rStream, sStrArray[i] ); + sStrArray[i] = SvNumberformat::LoadString( rStream ); rStream >> nTypeArray[i]; } sal_Bool bStreamThousand; @@ -1565,7 +1565,7 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream, { rHdr.StartEntry(); sal_uInt16 nOp1, nOp2; - SvNumberformat::LoadString( rStream, sFormatstring ); + sFormatstring = SvNumberformat::LoadString( rStream ); sal_Bool bStreamStandard, bStreamUsed; rStream >> eType >> fLimit1 >> fLimit2 >> nOp1 >> nOp2 >> bStreamStandard >> bStreamUsed; @@ -1623,7 +1623,7 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream, String aComment; // wird nach dem NewCurrency-Geraffel richtig gesetzt if ( rHdr.BytesLeft() ) { // ab SV_NUMBERFORMATTER_VERSION_NEWSTANDARD - SvNumberformat::LoadString( rStream, aComment ); + aComment = SvNumberformat::LoadString( rStream ); rStream >> nNewStandardDefined; } @@ -1752,32 +1752,27 @@ void SvNumberformat::ConvertLanguage( SvNumberFormatter& rConverter, } // static -void SvNumberformat::LoadString( SvStream& rStream, String& rStr ) +rtl::OUString SvNumberformat::LoadString( SvStream& rStream ) { CharSet eStream = rStream.GetStreamCharSet(); rtl::OString aStr = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStream); sal_Char cStream = NfCurrencyEntry::GetEuroSymbol( eStream ); if (aStr.indexOf(cStream) == -1) { // simple conversion to unicode - rStr = rtl::OStringToOUString(aStr, eStream); + return rtl::OStringToOUString(aStr, eStream); } - else + + sal_Unicode cTarget = NfCurrencyEntry::GetEuroSymbol(); + rtl::OUStringBuffer aBuf(aStr.getLength()); + for (sal_Int32 i = 0; i < aStr.getLength(); ++i) { - sal_Unicode cTarget = NfCurrencyEntry::GetEuroSymbol(); - register const sal_Char* p = aStr.getStr(); - register const sal_Char* const pEnd = p + aStr.getLength(); - register sal_Unicode* pUni = rStr.AllocBuffer(aStr.getLength()); - while ( p < pEnd ) - { - if ( *p == cStream ) - *pUni = cTarget; - else - *pUni = rtl::OUString(p, 1, eStream).toChar(); - ++p; - ++pUni; - } - *pUni = 0; + if (aStr[i] == cStream) + aBuf.append(cTarget); + else + aBuf.append(rtl::OUString(aStr.getStr()+i, 1, eStream).toChar()); } + + return aBuf.makeStringAndClear(); } void SvNumberformat::Save( SvStream& rStream, ImpSvNumMultipleWriteHeader& rHdr ) const @@ -4735,16 +4730,17 @@ String SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, { // speed up the most common case if ( 0 <= nVal && nVal < 10 ) { - sal_Unicode* p = aStr.AllocBuffer( 2 ); - *p++ = '0'; - *p = sal_Unicode( '0' + nVal ); + sal_Unicode aBuf[2]; + aBuf[0] = '0'; + aBuf[1] = '0' + nVal; + aStr = rtl::OUString(aBuf, SAL_N_ELEMENTS(aBuf)); } else - aStr = String::CreateFromInt32( nVal ); + aStr = rtl::OUString::valueOf( nVal ); } else { - String aValStr( String::CreateFromInt32( nVal ) ); + String aValStr( rtl::OUString::valueOf( nVal ) ); if ( aValStr.Len() >= nMinDigits ) aStr = aValStr; else @@ -4755,7 +4751,7 @@ String SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, } } else - aStr = String::CreateFromInt32( nVal ); + aStr = rtl::OUString::valueOf( nVal ); ImpTransliterate( aStr, rNum ); return aStr; } diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx index 71dd8b047814..50f479fe68d1 100644 --- a/sw/source/core/edit/edglss.cxx +++ b/sw/source/core/edit/edglss.cxx @@ -26,6 +26,7 @@ * ************************************************************************/ +#include <comphelper/string.hxx> #include <osl/endian.h> #include <hintids.hxx> #include <svl/urihelper.hxx> @@ -344,15 +345,16 @@ sal_Bool SwEditShell::GetSelectedText( String &rBuf, int nHndlParaBrk ) const sal_Unicode *p = (sal_Unicode*)aStream.GetBuffer(); if( p ) - rBuf = p; + rBuf = rtl::OUString(p); else { - sal_Unicode* pStrBuf = rBuf.AllocBuffer( xub_StrLen( - ( lLen / sizeof( sal_Unicode ))) ); + using comphelper::string::rtl_uString_alloc; + rtl_uString *pStr = rtl_uString_alloc(lLen / sizeof( sal_Unicode )); aStream.Seek( 0 ); aStream.ResetError(); - aStream.Read( pStrBuf, lLen ); - pStrBuf[ lLen / sizeof( sal_Unicode ) ] = '\0'; + //endian specific?, yipes! + aStream.Read(pStr->buffer, lLen); + rBuf = rtl::OUString(pStr, SAL_NO_ACQUIRE); } } } diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 28d4557f318b..d419533f4b22 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -27,7 +27,7 @@ ************************************************************************/ #include <com/sun/star/table/TableSortField.hpp> - +#include <comphelper/string.hxx> #include <osl/endian.h> #include <rtl/ustrbuf.hxx> #include <unotools/collatorwrapper.hxx> @@ -211,30 +211,13 @@ void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer) { aStream << (sal_Unicode)'\0'; - long lUniLen = (lLen / sizeof( sal_Unicode )); - ::rtl::OUStringBuffer aStrBuffer( lUniLen ); aStream.Seek( 0 ); aStream.ResetError(); - while(lUniLen) - { - String sBuf; - sal_Int32 nLocalLen = 0; - if( lUniLen >= STRING_MAXLEN ) - { - nLocalLen = STRING_MAXLEN - 1; - } - else - { - nLocalLen = lUniLen; - } - sal_Unicode *const pStrBuf = - sBuf.AllocBuffer( xub_StrLen( nLocalLen + 1)); - aStream.Read( pStrBuf, 2 * nLocalLen ); - pStrBuf[ nLocalLen ] = '\0'; - aStrBuffer.append( pStrBuf, nLocalLen ); - lUniLen -= nLocalLen; - } - rBuffer = aStrBuffer.makeStringAndClear(); + + long lUniLen = (lLen / sizeof( sal_Unicode )); + rtl_uString *pStr = comphelper::string::rtl_uString_alloc(lUniLen); + aStream.Read(pStr->buffer, lUniLen * sizeof(sal_Unicode)); + rBuffer = rtl::OUString(pStr, SAL_NO_ACQUIRE); } xWrt->bShowProgress = bOldShowProgress; } diff --git a/sw/source/filter/ascii/parasc.cxx b/sw/source/filter/ascii/parasc.cxx index 1dea0d1b18f1..ec68e011f138 100644 --- a/sw/source/filter/ascii/parasc.cxx +++ b/sw/source/filter/ascii/parasc.cxx @@ -26,7 +26,7 @@ * ************************************************************************/ - +#include <boost/scoped_array.hpp> #include <tools/stream.hxx> #include <hintids.hxx> #include <rtl/tencinfo.h> @@ -303,7 +303,7 @@ sal_uLong SwASCIIParser::ReadChars() bSwapUnicode = rInput.IsEndianSwap(); } - String sWork; + boost::scoped_array<sal_Unicode> aWork; sal_uLong nArrOffset = 0; do { @@ -331,7 +331,8 @@ sal_uLong SwASCIIParser::ReadChars() { sal_uInt32 nInfo; sal_Size nNewLen = lGCount, nCntBytes; - sal_Unicode* pBuf = sWork.AllocBuffer( static_cast< xub_StrLen >(nNewLen) ); + aWork.reset(new sal_Unicode[nNewLen]); + sal_Unicode* pBuf = aWork.get(); nNewLen = rtl_convertTextToUnicode( hConverter, hContext, pArr, lGCount, pBuf, nNewLen, @@ -345,9 +346,8 @@ sal_uLong SwASCIIParser::ReadChars() &nCntBytes ); if( 0 != ( nArrOffset = lGCount - nCntBytes ) ) memmove( pArr, pArr + nCntBytes, nArrOffset ); - sWork.ReleaseBufferAccess( static_cast< xub_StrLen >(nNewLen) ); - pStt = pLastStt = sWork.GetBufferAccess(); + pStt = pLastStt = aWork.get(); pEnd = pStt + nNewLen; } else diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx index 6c211f8e8bc7..88c26d7ff43e 100644 --- a/sw/source/filter/basflt/iodetect.cxx +++ b/sw/source/filter/basflt/iodetect.cxx @@ -28,7 +28,7 @@ #include <iodetect.hxx> - +#include <boost/scoped_array.hpp> #include <osl/endian.h> #include <sot/storage.hxx> #include <svtools/parhtml.hxx> @@ -450,8 +450,8 @@ bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen, if (eCharSet != RTL_TEXTENCODING_DONTKNOW) { - String sWork; - sal_Unicode *pNewBuf = sWork.AllocBuffer( static_cast< xub_StrLen >(rLen)); + boost::scoped_array<sal_Unicode> aWork(new sal_Unicode[rLen]); + sal_Unicode *pNewBuf = aWork.get(); sal_Size nNewLen; if (eCharSet != RTL_TEXTENCODING_UCS2) { @@ -495,9 +495,6 @@ bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen, } } - sWork.ReleaseBufferAccess( static_cast< xub_StrLen >(nNewLen) ); - pNewBuf = sWork.GetBufferAccess(); - for (sal_uLong nCnt = 0; nCnt < nNewLen; ++nCnt, ++pNewBuf) { switch (*pNewBuf) diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx index a955e7d081f0..a72f2037fe3f 100644 --- a/tools/inc/tools/stream.hxx +++ b/tools/inc/tools/stream.hxx @@ -576,12 +576,11 @@ namespace streamdetail template<typename prefix, typename S, sal_Size (*writeOper)(SvStream&, const S&, sal_Size)> sal_Size write_lenPrefixed_seq_From_str(SvStream& rStrm, const S &rStr) { - SAL_WARN_IF(rStr.getLength() > std::numeric_limits<prefix>::max(), - "tools.stream", - "string too long for prefix count to fit in output type"); - sal_Size nWritten = 0; prefix nUnits = std::min<sal_Size>(rStr.getLength(), std::numeric_limits<prefix>::max()); + SAL_WARN_IF(static_cast<sal_Size>(nUnits) != static_cast<sal_Size>(rStr.getLength()), + "tools.stream", + "string too long for prefix count to fit in output type"); rStrm << nUnits; if (rStrm.good()) { diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index b188cabdc0af..0f3e9b53b139 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -1399,32 +1399,7 @@ rtl::OUString SvStream::ReadUniOrByteString( rtl_TextEncoding eSrcCharSet ) { // read UTF-16 string directly from stream ? if (eSrcCharSet == RTL_TEXTENCODING_UNICODE) - { - String aStr; - sal_uInt32 nLen(0); - operator>> (nLen); - if (nLen) - { - if (nLen > STRING_MAXLEN) - { - SetError(SVSTREAM_GENERALERROR); - return aStr; - } - sal_Unicode *pStr = aStr.AllocBuffer( - static_cast< xub_StrLen >(nLen)); - BOOST_STATIC_ASSERT(STRING_MAXLEN <= SAL_MAX_SIZE / 2); - Read( pStr, nLen << 1 ); - - if (bSwap) - { - for (sal_Unicode *pEnd = pStr + nLen; pStr < pEnd; pStr++) - SwapUShort(*pStr); - } - } - - return aStr; - } - + return read_lenPrefixed_uInt16s_ToOUString<sal_uInt32>(*this); return read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*this, eSrcCharSet); } @@ -1434,31 +1409,9 @@ SvStream& SvStream::WriteUniOrByteString( const rtl::OUString& rStr, rtl_TextEnc { // write UTF-16 string directly into stream ? if (eDestCharSet == RTL_TEXTENCODING_UNICODE) - { - sal_Int32 nLen = rStr.getLength(); - operator<< (nLen); - if (nLen) - { - if (bSwap) - { - const sal_Unicode *pStr = rStr.getStr(); - const sal_Unicode *pEnd = pStr + nLen; - - for (; pStr < pEnd; pStr++) - { - sal_Unicode c = *pStr; - SwapUShort(c); - WRITENUMBER_WITHOUT_SWAP(sal_uInt16,c) - } - } - else - Write( rStr.getStr(), nLen << 1 ); - } - - return *this; - } - - write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(*this, rStr, eDestCharSet); + write_lenPrefixed_uInt16s_FromOUString<sal_uInt32>(*this, rStr); + else + write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(*this, rStr, eDestCharSet); return *this; } diff --git a/vcl/source/gdi/cvtsvm.cxx b/vcl/source/gdi/cvtsvm.cxx index f4a0152b4b88..feaeaddbd293 100644 --- a/vcl/source/gdi/cvtsvm.cxx +++ b/vcl/source/gdi/cvtsvm.cxx @@ -302,18 +302,14 @@ void ImplWriteRasterOpAction( SvStream& rOStm, sal_Int16 nRasterOp ) sal_Bool ImplWriteUnicodeComment( SvStream& rOStm, const String& rString ) { - xub_StrLen i, nStringLen = rString.Len(); + xub_StrLen nStringLen = rString.Len(); if ( nStringLen ) { sal_uInt32 nSize = ( nStringLen << 1 ) + 4; sal_uInt16 nType = GDI_UNICODE_COMMENT; rOStm << nType << nSize; - for ( i = 0; i < nStringLen; i++ ) - { - sal_Unicode nUni = rString.GetChar( i ); - rOStm << nUni; - } + write_uInt16s_FromOUString(rOStm, rString); } return nStringLen != 0; } @@ -336,11 +332,7 @@ void ImplReadUnicodeComment( sal_uInt32 nStrmPos, SvStream& rIStm, String& rStri nStringLen = sal::static_int_cast<xub_StrLen>(( nActionSize - 4 ) >> 1); if ( nStringLen && ( nType == GDI_UNICODE_COMMENT ) ) - { - sal_Unicode* pBuffer = rString.AllocBuffer( nStringLen ); - while ( nStringLen-- ) - rIStm >> *pBuffer++; - } + rString = read_uInt16s_ToOUString(rIStm, nStringLen); } rIStm.Seek( nOld ); } |