diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-16 10:13:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-16 12:12:31 +0200 |
commit | 4a96fb8ec0130e1036913093836bcf28bc37a49b (patch) | |
tree | e7aad9be4ca417e9e64f688cc99bee0638037741 /vcl | |
parent | f33b6e341fb7dd1ab3acd4fe5457b716be316e89 (diff) |
loplugin:bufferadd loosen some constraints
and extend O*StringView to have a constructor that takes a pointer and a
length
Change-Id: I6120e96280f030757e855a6596efdae438b7e1e8
Reviewed-on: https://gerrit.libreoffice.org/80872
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 88 | ||||
-rw-r--r-- | vcl/unx/generic/print/printerjob.cxx | 12 | ||||
-rw-r--r-- | vcl/unx/generic/printer/cpdmgr.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/generic/printer/cupsmgr.cxx | 12 | ||||
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 8 | ||||
-rw-r--r-- | vcl/unx/generic/printer/printerinfomanager.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 5 | ||||
-rw-r--r-- | vcl/workben/svpclient.cxx | 9 | ||||
-rw-r--r-- | vcl/workben/svptest.cxx | 6 |
9 files changed, 54 insertions, 95 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 47d90025172a..b2c885086ead 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -367,11 +367,7 @@ void PDFWriterImpl::createWidgetFieldName( sal_Int32 i_nWidgetIndex, const PDFWr if( nLastTokenIndex > 0 ) { aDomain = aFullName.copy( 0, nLastTokenIndex-1 ); - OStringBuffer aBuf( aDomain.getLength() + 1 + aPartialName.getLength() ); - aBuf.append( aDomain ); - aBuf.append( '.' ); - aBuf.append( aPartialName ); - aFullName = aBuf.makeStringAndClear(); + aFullName = aDomain + "." + aPartialName; } else aFullName = aPartialName; @@ -1666,10 +1662,7 @@ void PDFWriterImpl::appendLiteralStringEncrypt( const OUString& rInString, const void PDFWriterImpl::emitComment( const char* pComment ) { - OStringBuffer aLine( 64 ); - aLine.append( "% " ); - aLine.append( pComment ); - aLine.append( "\n" ); + OString aLine = "% " + rtl::OStringView(pComment) + "\n"; writeBuffer( aLine.getStr(), aLine.getLength() ); } @@ -2016,23 +2009,22 @@ OString PDFWriterImpl::emitStructureAttributes( PDFStructureElement& i_rEle ) if( nLink >= 0 && nLink < static_cast<sal_Int32>(m_aLinks.size()) ) { // update struct parent of link - OStringBuffer aStructParentEntry( 32 ); - aStructParentEntry.append( i_rEle.m_nObject ); - aStructParentEntry.append( " 0 R" ); - m_aStructParentTree.push_back( aStructParentEntry.makeStringAndClear() ); + OString aStructParentEntry = + OString::number( i_rEle.m_nObject ) + + " 0 R"; + m_aStructParentTree.push_back( aStructParentEntry ); m_aLinks[ nLink ].m_nStructParent = m_aStructParentTree.size()-1; sal_Int32 nRefObject = createObject(); - OStringBuffer aRef( 256 ); - aRef.append( nRefObject ); - aRef.append( " 0 obj\n" - "<</Type/OBJR/Obj " ); - aRef.append( m_aLinks[ nLink ].m_nObject ); - aRef.append( " 0 R>>\n" - "endobj\n\n" - ); if (updateObject(nRefObject)) { + OString aRef = + OString::number( nRefObject ) + + " 0 obj\n" + "<</Type/OBJR/Obj " + + OString::number( m_aLinks[ nLink ].m_nObject ) + + " 0 R>>\n" + "endobj\n\n"; writeBuffer( aRef.getStr(), aRef.getLength() ); } @@ -3806,8 +3798,7 @@ void PDFWriterImpl::createDefaultEditAppearance( PDFWidget& rEdit, const PDFWrit relies on /NeedAppearances in the AcroForm dictionary set to "true" */ beginRedirect( pEditStream, rEdit.m_aRect ); - OStringBuffer aAppearance( 32 ); - aAppearance.append( "/Tx BMC\nEMC\n" ); + OString aAppearance = "/Tx BMC\nEMC\n"; writeBuffer( aAppearance.getStr(), aAppearance.getLength() ); endRedirect(); @@ -3830,14 +3821,13 @@ void PDFWriterImpl::createDefaultListBoxAppearance( PDFWidget& rBox, const PDFWr sal_Int32 nBest = getSystemFont( aFont ); beginRedirect( pListBoxStream, rBox.m_aRect ); - OStringBuffer aAppearance( 64 ); setLineColor( COL_TRANSPARENT ); setFillColor( replaceColor( rWidget.BackgroundColor, rSettings.GetFieldColor() ) ); drawRectangle( rBox.m_aRect ); // empty appearance, see createDefaultEditAppearance for reference - aAppearance.append( "/Tx BMC\nEMC\n" ); + OString aAppearance = "/Tx BMC\nEMC\n"; writeBuffer( aAppearance.getStr(), aAppearance.getLength() ); endRedirect(); @@ -4940,9 +4930,7 @@ bool PDFWriterImpl::finalizeSignature() // 2- overwrite the value to the m_nSignatureLastByteRangeNoOffset position sal_uInt64 nWritten = 0; CHECK_RETURN( (osl::File::E_None == m_aFile.setPos(osl_Pos_Absolut, m_nSignatureLastByteRangeNoOffset) ) ); - OStringBuffer aByteRangeNo( 256 ); - aByteRangeNo.append( nLastByteRangeNo ); - aByteRangeNo.append( " ]" ); + OString aByteRangeNo = OString::number( nLastByteRangeNo ) + " ]"; if (m_aFile.write(aByteRangeNo.getStr(), aByteRangeNo.getLength(), nWritten) != osl::File::E_None) { @@ -7423,13 +7411,13 @@ void PDFWriterImpl::drawTransparent( const tools::PolyPolygon& rPolyPoly, sal_uI aObjName.append( m_aTransparentObjects.back().m_nExtGStateObject ); OString aExtName( aObjName.makeStringAndClear() ); - OStringBuffer aLine( 80 ); + OString aLine = // insert XObject - aLine.append( "q /" ); - aLine.append( aExtName ); - aLine.append( " gs /" ); - aLine.append( aTrName ); - aLine.append( " Do Q\n" ); + "q /" + + aExtName + + " gs /" + + aTrName + + " Do Q\n"; writeBuffer( aLine.getStr(), aLine.getLength() ); pushResource( ResXObject, aTrName, m_aTransparentObjects.back().m_nObject ); @@ -7556,13 +7544,13 @@ void PDFWriterImpl::endTransparencyGroup( const tools::Rectangle& rBoundingBox, aObjName.append( m_aTransparentObjects.back().m_nExtGStateObject ); OString aExtName( aObjName.makeStringAndClear() ); - OStringBuffer aLine( 80 ); + OString aLine = // insert XObject - aLine.append( "q /" ); - aLine.append( aExtName ); - aLine.append( " gs /" ); - aLine.append( aTrName ); - aLine.append( " Do Q\n" ); + "q /" + + aExtName + + " gs /" + + aTrName + + " Do Q\n"; writeBuffer( aLine.getStr(), aLine.getLength() ); pushResource( ResXObject, aTrName, m_aTransparentObjects.back().m_nObject ); @@ -9443,10 +9431,8 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const } writeBuffer( aLine.getStr(), aLine.getLength() ); - OStringBuffer aObjName( 16 ); - aObjName.append( "Im" ); - aObjName.append(nObject); - pushResource( ResXObject, aObjName.makeStringAndClear(), nObject ); + OString aObjName = "Im" + OString::number(nObject); + pushResource( ResXObject, aObjName, nObject ); } @@ -9521,11 +9507,9 @@ const PDFWriterImpl::BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx it = m_aBitmaps.begin(); } - OStringBuffer aObjName( 16 ); - aObjName.append( "Im" ); sal_Int32 nObject = it->m_aReferenceXObject.getObject(); - aObjName.append(nObject); - pushResource( ResXObject, aObjName.makeStringAndClear(), nObject ); + OString aObjName = "Im" + OString::number(nObject); + pushResource( ResXObject, aObjName, nObject ); return *it; } @@ -9727,10 +9711,7 @@ void PDFWriterImpl::drawWallpaper( const tools::Rectangle& rRect, const Wallpape tools::Rectangle aConvertRect( aBmpPos, aBmpSize ); m_aPages.back().convertRect( aConvertRect ); - OStringBuffer aNameBuf(16); - aNameBuf.append( "Im" ); - aNameBuf.append( rEmit.m_nObject ); - OString aImageName( aNameBuf.makeStringAndClear() ); + OString aImageName = "Im" + OString::number( rEmit.m_nObject ); // push the pattern OStringBuffer aTilingStream( 32 ); @@ -10345,8 +10326,7 @@ void PDFWriterImpl::beginStructureElementMCSeq() ! m_aStructure[ m_nCurrentStructElement ].m_bOpenMCSeq // already opened sequence ) { - OStringBuffer aLine( 128 ); - aLine.append( "/Artifact BMC\n" ); + OString aLine = "/Artifact BMC\n"; writeBuffer( aLine.getStr(), aLine.getLength() ); // mark element MC sequence as open m_aStructure[ m_nCurrentStructElement ].m_bOpenMCSeq = true; diff --git a/vcl/unx/generic/print/printerjob.cxx b/vcl/unx/generic/print/printerjob.cxx index 73dedc5a2415..7d805ef942e5 100644 --- a/vcl/unx/generic/print/printerjob.cxx +++ b/vcl/unx/generic/print/printerjob.cxx @@ -211,18 +211,14 @@ createSpoolDir () do { - OUStringBuffer aDir( aTmpDir.getLength() + 16 ); - aDir.append( aTmpDir ); - aDir.append( "/psp" ); - aDir.append(nRand); - OUString aResult = aDir.makeStringAndClear(); - if( osl::Directory::create( aResult ) == osl::FileBase::E_None ) + OUString aDir = aTmpDir + "/psp" + OUString::number(nRand); + if( osl::Directory::create( aDir ) == osl::FileBase::E_None ) { - osl::File::setAttributes( aResult, + osl::File::setAttributes( aDir, osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnRead | osl_File_Attribute_OwnExe ); - return aResult; + return aDir; } nRand++; } while( nRand ); diff --git a/vcl/unx/generic/printer/cpdmgr.cxx b/vcl/unx/generic/printer/cpdmgr.cxx index 5a2e1b01d271..cae2a4e1ab03 100644 --- a/vcl/unx/generic/printer/cpdmgr.cxx +++ b/vcl/unx/generic/printer/cpdmgr.cxx @@ -206,9 +206,6 @@ void CPDManager::addNewPrinter(const OUString& aPrinterName, const OUString& aUn rtl_TextEncoding aEncoding = osl_getThreadTextEncoding(); aPrinter.m_aInfo.m_aComment = OStringToOUString(pDest->info, aEncoding); aPrinter.m_aInfo.m_aLocation = OStringToOUString(pDest->location, aEncoding); - OUStringBuffer aBuf( 256 ); - aBuf.append( "CPD:" ); - aBuf.append( aUniqueName ); // note: the parser that goes with the PrinterInfo // is created implicitly by the JobData::operator=() // when it detects the NULL ptr m_pParser. @@ -225,7 +222,7 @@ void CPDManager::addNewPrinter(const OUString& aPrinterName, const OUString& aUn aPrinter.m_aInfo.m_aContext = c_it->second; } aPrinter.m_aInfo.setDefaultBackend(true); - aPrinter.m_aInfo.m_aDriverName = aBuf.makeStringAndClear(); + aPrinter.m_aInfo.m_aDriverName = "CPD:" + aUniqueName; m_aPrinters[ aUniqueName ] = aPrinter; } #endif diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx index a6d1ccbad7bb..12482b2ba878 100644 --- a/vcl/unx/generic/printer/cupsmgr.cxx +++ b/vcl/unx/generic/printer/cupsmgr.cxx @@ -312,11 +312,8 @@ void CUPSManager::initialize() OUString aPrinterName = OStringToOUString( pDest->name, aEncoding ); if( pDest->instance && *pDest->instance ) { - OUStringBuffer aBuf( 256 ); - aBuf.append( aPrinterName ); - aBuf.append( '/' ); - aBuf.append( OStringToOUString( pDest->instance, aEncoding ) ); - aPrinterName = aBuf.makeStringAndClear(); + aPrinterName += "/" + + OStringToOUString( pDest->instance, aEncoding ); } // initialize printer with possible configuration from psprint.conf @@ -338,9 +335,6 @@ void CUPSManager::initialize() aPrinter.m_aInfo.m_aAuthInfoRequired=OStringToOUString(pDest->options[k].value, aEncoding); } - OUStringBuffer aBuf( 256 ); - aBuf.append( "CUPS:" ); - aBuf.append( aPrinterName ); // note: the parser that goes with the PrinterInfo // is created implicitly by the JobData::operator=() // when it detects the NULL ptr m_pParser. @@ -357,7 +351,7 @@ void CUPSManager::initialize() aPrinter.m_aInfo.m_aContext = c_it->second; } aPrinter.m_aInfo.setDefaultBackend(bUsePDF); - aPrinter.m_aInfo.m_aDriverName = aBuf.makeStringAndClear(); + aPrinter.m_aInfo.m_aDriverName = "CUPS:" + aPrinterName; m_aPrinters[ aPrinter.m_aInfo.m_aPrinterName ] = aPrinter; m_aCUPSDestMap[ aPrinter.m_aInfo.m_aPrinterName ] = nPrinter; diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 0d520e09d219..880a7d958000 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -620,10 +620,10 @@ PPDParser::PPDParser(const OUString& rFile, const std::vector<PPDKey*>& keys) pwg_media_t *pPWGMedia = pwgMediaForPWG(o.pData->buffer); if (pPWGMedia != nullptr) { OUStringBuffer aBuf( 256 ); - aBuf.append( "0 0 " ); - aBuf.append( PWG_TO_POINTS(pPWGMedia -> width) ); - aBuf.append( " " ); - aBuf.append( PWG_TO_POINTS(pPWGMedia -> length) ); + aBuf = "0 0 " + + OUString::number(PWG_TO_POINTS(pPWGMedia -> width)) + + " " + + OUString::number(PWG_TO_POINTS(pPWGMedia -> length)); if ( pImageableAreaValue ) pImageableAreaValue->m_aValue = aBuf.makeStringAndClear(); aBuf.append( PWG_TO_POINTS(pPWGMedia -> width) ); diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx index 1977a80b5e7f..8ba1df9810bb 100644 --- a/vcl/unx/generic/printer/printerinfomanager.cxx +++ b/vcl/unx/generic/printer/printerinfomanager.cxx @@ -846,12 +846,10 @@ void SystemQueueInfo::run() for(const auto & rParm : aParms) { aLines.clear(); - OStringBuffer aCmdLine( 128 ); - aCmdLine.append( rParm.pQueueCommand ); #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "trying print queue command \"%s\" ... ", rParm.pQueueCommand ); #endif - aCmdLine.append( " 2>/dev/null" ); + OString aCmdLine = rParm.pQueueCommand + OStringLiteral(" 2>/dev/null"); FILE *pPipe; if( (pPipe = popen( aCmdLine.getStr(), "r" )) ) { diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 370b47cbdb6b..87b795513367 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -2881,10 +2881,7 @@ bool X11SalFrame::appendUnicodeSequence( sal_Unicode c ) (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) { - OUStringBuffer aBuf( rSeq.getLength() + 1 ); - aBuf.append( rSeq ); - aBuf.append( c ); - rSeq = aBuf.makeStringAndClear(); + rSeq += OUStringLiteral1(c); std::vector<ExtTextInputAttr> attribs( rSeq.getLength(), ExtTextInputAttr::Underline ); SalExtTextInputEvent aEv; diff --git a/vcl/workben/svpclient.cxx b/vcl/workben/svpclient.cxx index 744b38138239..8ef179b0c1a2 100644 --- a/vcl/workben/svpclient.cxx +++ b/vcl/workben/svpclient.cxx @@ -180,11 +180,10 @@ void MyWin::parseList( const OString& rList ) aElementType = OStringToOUString( aLine.copy( 13 ), RTL_TEXTENCODING_ASCII_US ); else { - OUStringBuffer aNewElement( 64 ); - aNewElement.append( aElementType ); - aNewElement.append( ": " ); - aNewElement.append( OStringToOUString( aLine, RTL_TEXTENCODING_ASCII_US ) ); - m_aSvpBitmaps->InsertEntry( aNewElement.makeStringAndClear() ); + OUString aNewElement = + aElementType + ": " + + OStringToOUString( aLine, RTL_TEXTENCODING_ASCII_US ); + m_aSvpBitmaps->InsertEntry( aNewElement ); } } } diff --git a/vcl/workben/svptest.cxx b/vcl/workben/svptest.cxx index a79cda4df507..72ff179821a8 100644 --- a/vcl/workben/svptest.cxx +++ b/vcl/workben/svptest.cxx @@ -238,13 +238,11 @@ void MyWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rR sal_uInt8 nBlue = (i << 2) & 0xC0; rRenderContext.SetTextColor(Color(nRed, nGreen, nBlue)); - OUStringBuffer aPrintText(1024); - - aPrintText.append( "SVP test program" ); + OUString aPrintText = "SVP test program"; rRenderContext.DrawText(tools::Rectangle(Point((aPaperSize.Width() - 4000) / 2, 2000), Size(aPaperSize.Width() - 2100, aPaperSize.Height() - 4000)), - aPrintText.makeStringAndClear(), + aPrintText, DrawTextFlags::MultiLine); } |