We know the length here

Change-Id: I630b7fbda7c9ebf578e74260a0d67eea32e9e429
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129549
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2022-02-06 07:09:38 +01:00
parent 05b067f05c
commit 5bd55c22c1
7 changed files with 20 additions and 20 deletions

View File

@@ -135,7 +135,7 @@ OUString VCLXAccessibleEdit::implGetText()
sal_Unicode cEchoChar = pEdit->GetEchoChar(); sal_Unicode cEchoChar = pEdit->GetEchoChar();
if ( !cEchoChar ) if ( !cEchoChar )
cEchoChar = '*'; cEchoChar = '*';
OUStringBuffer sTmp; OUStringBuffer sTmp(aText.getLength());
aText = comphelper::string::padToLength(sTmp, aText.getLength(), aText = comphelper::string::padToLength(sTmp, aText.getLength(),
cEchoChar).makeStringAndClear(); cEchoChar).makeStringAndClear();
} }

View File

@@ -1610,8 +1610,9 @@ void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool)
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
else else
{ {
OUStringBuffer aStr; const sal_Int32 nCount = std::max(rPar.Get(1)->GetLong(), sal_Int32(0));
comphelper::string::padToLength(aStr, rPar.Get(1)->GetLong(), '\t'); OUStringBuffer aStr(nCount);
comphelper::string::padToLength(aStr, nCount, '\t');
rPar.Get(0)->PutString(aStr.makeStringAndClear()); rPar.Get(0)->PutString(aStr.makeStringAndClear());
} }
} }

View File

@@ -4585,7 +4585,7 @@ void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, SbxDataType t, sal_uInt3
if( bFixedString ) if( bFixedString )
{ {
sal_uInt16 nCount = static_cast<sal_uInt16>( nOp2 >> 17 ); // len = all bits above 0x10000 sal_uInt16 nCount = static_cast<sal_uInt16>( nOp2 >> 17 ); // len = all bits above 0x10000
OUStringBuffer aBuf; OUStringBuffer aBuf(nCount);
comphelper::string::padToLength(aBuf, nCount); comphelper::string::padToLength(aBuf, nCount);
pVar->PutString(aBuf.makeStringAndClear()); pVar->PutString(aBuf.makeStringAndClear());
} }

View File

@@ -302,7 +302,7 @@ SbxArray* StringToByteArray(const OUString& rStr)
OUString ByteArrayToString(SbxArray* pArr) OUString ByteArrayToString(SbxArray* pArr)
{ {
sal_uInt32 nCount = pArr->Count(); sal_uInt32 nCount = pArr->Count();
OUStringBuffer aStrBuf; OUStringBuffer aStrBuf((nCount + 1) / 2);
sal_Unicode aChar = 0; sal_Unicode aChar = 0;
for( sal_uInt32 i = 0 ; i < nCount ; i++ ) for( sal_uInt32 i = 0 ; i < nCount ; i++ )
{ {

View File

@@ -18,6 +18,8 @@
*/ */
#include <file/FStringFunctions.hxx> #include <file/FStringFunctions.hxx>
#include <comphelper/string.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
using namespace connectivity; using namespace connectivity;
@@ -61,7 +63,7 @@ ORowSetValue OOp_Char::operate(const std::vector<ORowSetValue>& lhs) const
if (lhs.empty()) if (lhs.empty())
return ORowSetValue(); return ORowSetValue();
OUStringBuffer sRet; OUStringBuffer sRet(static_cast<sal_Int32>(lhs.size()));
std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin(); std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend(); std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
for (; aIter != aEnd; ++aIter) for (; aIter != aEnd; ++aIter)
@@ -151,13 +153,9 @@ ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) const
if (lhs.isNull()) if (lhs.isNull())
return lhs; return lhs;
const char c = ' '; sal_Int32 nCount = std::max(lhs.getInt32(), sal_Int32(0));
OUStringBuffer sRet; OUStringBuffer sRet(nCount);
sal_Int32 nCount = lhs.getInt32(); comphelper::string::padToLength(sRet, nCount, ' ');
for (sal_Int32 i = 0; i < nCount; ++i)
{
sRet.appendAscii(&c, 1);
}
return sRet.makeStringAndClear(); return sRet.makeStringAndClear();
} }
@@ -184,11 +182,12 @@ ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs, const ORowSetValue& rh
if (lhs.isNull() || rhs.isNull()) if (lhs.isNull() || rhs.isNull())
return lhs; return lhs;
OUStringBuffer sRet; const OUString s = lhs.getString();
sal_Int32 nCount = rhs.getInt32(); const sal_Int32 nCount = std::max(rhs.getInt32(), sal_Int32(0));
OUStringBuffer sRet(s.getLength() * nCount);
for (sal_Int32 i = 0; i < nCount; ++i) for (sal_Int32 i = 0; i < nCount; ++i)
{ {
sRet.append(lhs.getString()); sRet.append(s);
} }
return sRet.makeStringAndClear(); return sRet.makeStringAndClear();
} }

View File

@@ -3595,7 +3595,7 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
aTmpFont.SetEscapement( 0 ); aTmpFont.SetEscapement( 0 );
aTmpFont.SetPropr( 100 ); aTmpFont.SetPropr( 100 );
aTmpFont.SetPhysFont(rOutDev); aTmpFont.SetPhysFont(rOutDev);
OUStringBuffer aBlanks; OUStringBuffer aBlanks(nTextLen);
comphelper::string::padToLength( aBlanks, nTextLen, ' ' ); comphelper::string::padToLength( aBlanks, nTextLen, ' ' );
Point aUnderlinePos( aOutPos ); Point aUnderlinePos( aOutPos );
if ( nOrientation ) if ( nOrientation )
@@ -3726,7 +3726,7 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, tools::Rectangle aClipRect, Po
else if ( nChars == 2 ) else if ( nChars == 2 )
nChars = 3; // looks better nChars = 3; // looks better
OUStringBuffer aBuf; OUStringBuffer aBuf(nChars);
comphelper::string::padToLength(aBuf, nChars, rTextPortion.GetExtraValue()); comphelper::string::padToLength(aBuf, nChars, rTextPortion.GetExtraValue());
OUString aText(aBuf.makeStringAndClear()); OUString aText(aBuf.makeStringAndClear());
aTmpFont.QuickDrawText( &rOutDev, aTmpPos, aText, 0, aText.getLength() ); aTmpFont.QuickDrawText( &rOutDev, aTmpPos, aText, 0, aText.getLength() );

View File

@@ -124,9 +124,9 @@ OUString lcl_ValueString( sal_Int32 nValue, sal_uInt16 nMinDigits )
OUString aStr = OUString::number( std::abs( nValue ) ); OUString aStr = OUString::number( std::abs( nValue ) );
if ( aStr.getLength() < nMinDigits ) if ( aStr.getLength() < nMinDigits )
{ {
OUStringBuffer aZero; OUStringBuffer aZero(nMinDigits);
comphelper::string::padToLength(aZero, nMinDigits - aStr.getLength(), '0'); comphelper::string::padToLength(aZero, nMinDigits - aStr.getLength(), '0');
aStr = aZero.makeStringAndClear() + aStr; aStr = aZero.append(aStr).makeStringAndClear();
} }
// nMinDigits doesn't include the '-' sign -> add after inserting zeros // nMinDigits doesn't include the '-' sign -> add after inserting zeros
if ( nValue < 0 ) if ( nValue < 0 )