Related: fdo#38838 String::ReleaseBufferAccess is now no more

Change-Id: Ib5390183e3d98a23f9243debfe3624561ca92535
This commit is contained in:
Caolán McNamara 2013-09-08 14:52:59 +01:00
parent 3b21a1657b
commit ce9c390e1a
3 changed files with 11 additions and 43 deletions

View File

@ -274,7 +274,6 @@ public:
const sal_Unicode* GetBuffer() const { return mpData->maStr; }
sal_Unicode* GetBufferAccess();
void ReleaseBufferAccess( xub_StrLen nLen = STRING_LEN );
friend sal_Bool operator == ( const UniString& rStr1, const UniString& rStr2 )
{ return rStr1.Equals( rStr2 ); }

View File

@ -3158,31 +3158,25 @@ void ScInterpreter::ScUpper()
void ScInterpreter::ScPropper()
{
//2do: what to do with I18N-CJK ?!?
String aStr( GetString() );
const xub_StrLen nLen = aStr.Len();
// #i82487# don't try to write to empty string's BufferAccess
// (would crash now that the empty string is const)
OUStringBuffer aStr(GetString());
const sal_Int32 nLen = aStr.getLength();
if ( nLen > 0 )
{
String aUpr( ScGlobal::pCharClass->uppercase( aStr ) );
String aLwr( ScGlobal::pCharClass->lowercase( aStr ) );
sal_Unicode* pStr = aStr.GetBufferAccess();
const sal_Unicode* pUpr = aUpr.GetBuffer();
const sal_Unicode* pLwr = aLwr.GetBuffer();
*pStr = *pUpr;
xub_StrLen nPos = 1;
OUString aUpr(ScGlobal::pCharClass->uppercase(aStr.toString()));
OUString aLwr(ScGlobal::pCharClass->lowercase(aStr.toString()));
aStr[0] = aUpr[0];
sal_Int32 nPos = 1;
while( nPos < nLen )
{
OUString aTmpStr( pStr[nPos-1] );
OUString aTmpStr( aStr[nPos-1] );
if ( !ScGlobal::pCharClass->isLetter( aTmpStr, 0 ) )
pStr[nPos] = pUpr[nPos];
aStr[nPos] = aUpr[nPos];
else
pStr[nPos] = pLwr[nPos];
nPos++;
aStr[nPos] = aLwr[nPos];
++nPos;
}
aStr.ReleaseBufferAccess( nLen );
}
PushString( aStr );
PushString(aStr.makeStringAndClear());
}

View File

@ -240,31 +240,6 @@ STRCODE* STRING::GetBufferAccess()
return mpData->maStr;
}
void STRING::ReleaseBufferAccess( xub_StrLen nLen )
{
// String not consinstent, thus no functionality test
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);
}
// shorten buffer is difference > 8 chars
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;
}
STRING& STRING::Insert( STRCODE c, xub_StrLen nIndex )
{
DBG_CHKTHIS( STRING, DBGCHECKSTRING );