diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-09-18 13:34:14 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-19 09:59:20 +0100 |
commit | 5d73752cc7d66edae26392f84e72e32a8cf598ca (patch) | |
tree | 310056bac7689b9343e8f2b220cc2b03550623c5 /tools | |
parent | remove redundant intermediate ByteStrings (diff) | |
download | core-5d73752cc7d66edae26392f84e72e32a8cf598ca.tar.gz core-5d73752cc7d66edae26392f84e72e32a8cf598ca.zip |
rework this in terms of read_uInt8s_AsOString
Diffstat (limited to 'tools')
-rw-r--r-- | tools/inc/tools/string.hxx | 4 | ||||
-rw-r--r-- | tools/source/stream/stream.cxx | 8 | ||||
-rw-r--r-- | tools/source/string/strimp.cxx | 59 | ||||
-rw-r--r-- | tools/source/string/tustring.cxx | 59 |
4 files changed, 61 insertions, 69 deletions
diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx index b2bbfe75c772..54f4f8898b72 100644 --- a/tools/inc/tools/string.hxx +++ b/tools/inc/tools/string.hxx @@ -177,6 +177,7 @@ private: // Append(char) void operator +=(int); // not implemented; to detect misuses // of operator +=(sal_Char) + public: ByteString(); ByteString( const ByteString& rStr ); @@ -282,9 +283,6 @@ public: ByteString GetToken( xub_StrLen nToken, sal_Char cTok = ';' ) const; const sal_Char* GetBuffer() const { return mpData->maStr; } - sal_Char* GetBufferAccess(); - void ReleaseBufferAccess( xub_StrLen nLen = STRING_LEN ); - sal_Char* AllocBuffer( xub_StrLen nLen ); friend sal_Bool operator == ( const ByteString& rStr1, const ByteString& rStr2 ) { return rStr1.Equals( rStr2 ); } diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index f5d8a9f77a9b..ca3d004e08dc 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -1544,13 +1544,7 @@ SvStream& SvStream::ReadByteString( ByteString& rStr ) { sal_uInt16 nLen = 0; operator>>( nLen ); - if( nLen ) - { - char* pTmp = rStr.AllocBuffer( nLen ); - nLen = (sal_uInt16)Read( pTmp, nLen ); - } - else - rStr.Erase(); + rStr = read_uInt8s_AsOString(*this, nLen); return *this; } diff --git a/tools/source/string/strimp.cxx b/tools/source/string/strimp.cxx index d8428750526b..b83b39c312f5 100644 --- a/tools/source/string/strimp.cxx +++ b/tools/source/string/strimp.cxx @@ -1452,63 +1452,4 @@ STRING STRING::GetToken( xub_StrLen nToken, STRCODE cTok, xub_StrLen& rIndex ) c } } -// ----------------------------------------------------------------------- - -STRCODE* STRING::GetBufferAccess() -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - // Daten kopieren, wenn noetig - if ( mpData->mnLen ) - ImplCopyData(); - - // Pointer auf den String zurueckgeben - return mpData->maStr; -} - -// ----------------------------------------------------------------------- - -void STRING::ReleaseBufferAccess( xub_StrLen nLen ) -{ - // Hier ohne Funktionstest, da String nicht konsistent - DBG_CHKTHIS( STRING, NULL ); - DBG_ASSERT( mpData->mnRefCount == 1, "String::ReleaseCharStr() called for String with RefCount" ); - - if ( nLen > mpData->mnLen ) - nLen = ImplStringLen( mpData->maStr ); - OSL_ASSERT(nLen <= mpData->mnLen); - if ( !nLen ) - { - STRING_NEW((STRING_TYPE **)&mpData); - } - // Bei mehr als 8 Zeichen unterschied, kuerzen wir den Buffer - else if ( mpData->mnLen - nLen > 8 ) - { - STRINGDATA* pNewData = ImplAllocData( nLen ); - memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); - STRING_RELEASE((STRING_TYPE *)mpData); - mpData = pNewData; - } - else - mpData->mnLen = nLen; -} - -// ----------------------------------------------------------------------- - -STRCODE* STRING::AllocBuffer( xub_StrLen nLen ) -{ - DBG_CHKTHIS( STRING, DBGCHECKSTRING ); - - STRING_RELEASE((STRING_TYPE *)mpData); - if ( nLen ) - mpData = ImplAllocData( nLen ); - else - { - mpData = NULL; - STRING_NEW((STRING_TYPE **)&mpData); - } - - return mpData->maStr; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/string/tustring.cxx b/tools/source/string/tustring.cxx index 0f9874140769..30c973ecb9c9 100644 --- a/tools/source/string/tustring.cxx +++ b/tools/source/string/tustring.cxx @@ -505,4 +505,63 @@ STRING& STRING::Expand( xub_StrLen nCount, STRCODE cExpandChar ) return *this; } +// ----------------------------------------------------------------------- + +STRCODE* STRING::GetBufferAccess() +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + + // Daten kopieren, wenn noetig + if ( mpData->mnLen ) + ImplCopyData(); + + // Pointer auf den String zurueckgeben + return mpData->maStr; +} + +// ----------------------------------------------------------------------- + +void STRING::ReleaseBufferAccess( xub_StrLen nLen ) +{ + // Hier ohne Funktionstest, da String nicht konsistent + DBG_CHKTHIS( STRING, NULL ); + DBG_ASSERT( mpData->mnRefCount == 1, "String::ReleaseCharStr() called for String with RefCount" ); + + if ( nLen > mpData->mnLen ) + nLen = ImplStringLen( mpData->maStr ); + OSL_ASSERT(nLen <= mpData->mnLen); + if ( !nLen ) + { + STRING_NEW((STRING_TYPE **)&mpData); + } + // Bei mehr als 8 Zeichen unterschied, kuerzen wir den Buffer + else if ( mpData->mnLen - nLen > 8 ) + { + STRINGDATA* pNewData = ImplAllocData( nLen ); + memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); + STRING_RELEASE((STRING_TYPE *)mpData); + mpData = pNewData; + } + else + mpData->mnLen = nLen; +} + +// ----------------------------------------------------------------------- + +STRCODE* STRING::AllocBuffer( xub_StrLen nLen ) +{ + DBG_CHKTHIS( STRING, DBGCHECKSTRING ); + + STRING_RELEASE((STRING_TYPE *)mpData); + if ( nLen ) + mpData = ImplAllocData( nLen ); + else + { + mpData = NULL; + STRING_NEW((STRING_TYPE **)&mpData); + } + + return mpData->maStr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |