diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-26 13:15:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-27 11:15:46 +0200 |
commit | c8fa03b1f565461364b9f6423b65680e09281c14 (patch) | |
tree | 78ff35dfeb569354b41e89b9d55d77b46f7d3d95 /svl | |
parent | 82a4ef72d6e34c2f5075069a1b353f7fd41c7595 (diff) |
new loplugin:stringloop, and applied in various
look for OUString being appended to in a loop, better to use
OUStringBuffer to accumulate the results.
Change-Id: Ia36e06e2781a7c546ce9cbad62727aa4c5f10c4b
Reviewed-on: https://gerrit.libreoffice.org/58092
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/items/slstitm.cxx | 9 | ||||
-rw-r--r-- | svl/source/items/style.cxx | 9 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 12 | ||||
-rw-r--r-- | svl/source/passwordcontainer/passwordcontainer.cxx | 26 |
4 files changed, 29 insertions, 27 deletions
diff --git a/svl/source/items/slstitm.cxx b/svl/source/items/slstitm.cxx index 5399706c2e85..64d960226d86 100644 --- a/svl/source/items/slstitm.cxx +++ b/svl/source/items/slstitm.cxx @@ -25,6 +25,7 @@ #include <osl/diagnose.h> #include <tools/stream.hxx> #include <stringio.hxx> +#include <rtl/ustrbuf.hxx> SfxPoolItem* SfxStringListItem::CreateDefault() { return new SfxStringListItem; } @@ -165,22 +166,22 @@ void SfxStringListItem::SetString( const OUString& rStr ) OUString SfxStringListItem::GetString() { - OUString aStr; + OUStringBuffer aStr; if ( mpList ) { std::vector<OUString>::const_iterator iter = mpList->begin(); for (;;) { - aStr += *iter; + aStr.append(*iter); ++iter; if (iter == mpList->end()) break; - aStr += "\r"; + aStr.append("\r"); } } - return convertLineEnd(aStr, GetSystemLineEnd()); + return convertLineEnd(aStr.makeStringAndClear(), GetSystemLineEnd()); } diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index 5856393f57e9..0ab10a4c7801 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -36,6 +36,7 @@ #include <algorithm> #include <comphelper/servicehelper.hxx> #include <o3tl/make_unique.hxx> +#include <rtl/ustrbuf.hxx> #include <string.h> @@ -328,7 +329,7 @@ bool SfxStyleSheetBase::IsUsed() const OUString SfxStyleSheetBase::GetDescription( MapUnit eMetric ) { SfxItemIter aIter( GetItemSet() ); - OUString aDesc; + OUStringBuffer aDesc; const SfxPoolItem* pItem = aIter.FirstItem(); IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag()); @@ -341,13 +342,13 @@ OUString SfxStyleSheetBase::GetDescription( MapUnit eMetric ) *pItem, eMetric, aItemPresentation, aIntlWrapper ) ) { if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() ) - aDesc += " + "; + aDesc.append(" + "); if ( !aItemPresentation.isEmpty() ) - aDesc += aItemPresentation; + aDesc.append(aItemPresentation); } pItem = aIter.NextItem(); } - return aDesc; + return aDesc.makeStringAndClear(); } SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 213e83a60a8c..f9e0b944b615 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1930,7 +1930,7 @@ bool SvNumberformat::GetNewCurrencySymbol( OUString& rSymbol, // static OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr ) { - OUString aTmp; + OUStringBuffer aTmp; sal_Int32 nStartPos, nPos, nLen; nLen = rStr.getLength(); nStartPos = 0; @@ -1939,12 +1939,12 @@ OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr ) sal_Int32 nEnd; if ( (nEnd = GetQuoteEnd( rStr, nPos )) >= 0 ) { - aTmp += rStr.copy( nStartPos, ++nEnd - nStartPos ); + aTmp.append(rStr.copy( nStartPos, ++nEnd - nStartPos )); nStartPos = nEnd; } else { - aTmp += rStr.copy( nStartPos, nPos - nStartPos ); + aTmp.append(rStr.copy( nStartPos, nPos - nStartPos )); nStartPos = nPos + 2; sal_Int32 nDash; nEnd = nStartPos - 1; @@ -1975,15 +1975,15 @@ OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr ) { nPos = nDash; } - aTmp += rStr.copy( nStartPos, nPos - nStartPos ); + aTmp.append(rStr.copy( nStartPos, nPos - nStartPos )); nStartPos = nClose + 1; } } if ( nLen > nStartPos ) { - aTmp += rStr.copy( nStartPos, nLen - nStartPos ); + aTmp.append(rStr.copy( nStartPos, nLen - nStartPos )); } - return aTmp; + return aTmp.makeStringAndClear(); } void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUStringBuffer& rOutString) const diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx index 6becfd9be78d..3a4aecef9874 100644 --- a/svl/source/passwordcontainer/passwordcontainer.cxx +++ b/svl/source/passwordcontainer/passwordcontainer.cxx @@ -36,6 +36,7 @@ #include <rtl/cipher.h> #include <rtl/digest.h> #include <rtl/byteseq.hxx> +#include <rtl/ustrbuf.hxx> using namespace osl; using namespace utl; @@ -48,12 +49,12 @@ using namespace com::sun::star::ucb; static OUString createIndex(const std::vector< OUString >& lines) { - OUString aResult; + OUStringBuffer aResult; for( size_t i = 0; i < lines.size(); i++ ) { if( i ) - aResult += "__"; + aResult.append("__"); OString line = OUStringToOString( lines[i], RTL_TEXTENCODING_UTF8 ); const sal_Char* pLine = line.getStr(); @@ -61,19 +62,18 @@ static OUString createIndex(const std::vector< OUString >& lines) { if (rtl::isAsciiAlphanumeric(static_cast<unsigned char>(*pLine))) { - aResult += OUStringLiteral1(*pLine); + aResult.append(*pLine); } else { - aResult += "_" - + OUString::number( *pLine, 16 ); + aResult.append("_").append( OUString::number( *pLine, 16 ) ); } pLine++; } } - return aResult; + return aResult.makeStringAndClear(); } @@ -86,7 +86,7 @@ static std::vector< OUString > getInfoFromInd( const OUString& aInd ) const sal_Char* pLine = line.getStr(); do { - OUString newItem; + OUStringBuffer newItem; if( !aStart ) pLine += 2; else @@ -95,7 +95,7 @@ static std::vector< OUString > getInfoFromInd( const OUString& aInd ) while( *pLine && !( pLine[0] == '_' && pLine[1] == '_' )) if( *pLine != '_' ) { - newItem += OUStringLiteral1( *pLine ); + newItem.append( *pLine ); pLine++; } else @@ -115,11 +115,11 @@ static std::vector< OUString > getInfoFromInd( const OUString& aInd ) aNum += OUStringLiteral1( pLine[i] ); } - newItem += OUStringLiteral1( aNum.toUInt32( 16 ) ); + newItem.append( OUStringLiteral1( aNum.toUInt32( 16 ) ) ); pLine += 3; } - aResult.push_back( newItem ); + aResult.push_back( newItem.makeStringAndClear() ); } while( pLine[0] == '_' && pLine[1] == '_' ); if( *pLine ) @@ -766,11 +766,11 @@ UrlRecord PasswordContainer::find( OUString PasswordContainer::GetDefaultMasterPassword() { - OUString aResult; + OUStringBuffer aResult; for ( sal_Int32 nInd = 0; nInd < RTL_DIGEST_LENGTH_MD5; nInd++ ) - aResult += "aa"; + aResult.append("aa"); - return aResult; + return aResult.makeStringAndClear(); } OUString PasswordContainer::RequestPasswordFromUser( PasswordRequestMode aRMode, const uno::Reference< task::XInteractionHandler >& xHandler ) |