From c8fa03b1f565461364b9f6423b65680e09281c14 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 26 Jul 2018 13:15:05 +0200 Subject: 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 --- tools/source/inet/inetmime.cxx | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx index 0ec6bcdbb70e..7d344c060873 100644 --- a/tools/source/inet/inetmime.cxx +++ b/tools/source/inet/inetmime.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -305,7 +306,7 @@ bool translateUTF8Char(const sal_Char *& rBegin, return true; } -void appendISO88591(OUString & rText, sal_Char const * pBegin, +void appendISO88591(OUStringBuffer & rText, sal_Char const * pBegin, sal_Char const * pEnd); struct Parameter @@ -339,14 +340,14 @@ bool parseParameters(ParameterList const & rInput, // appendISO88591 -void appendISO88591(OUString & rText, sal_Char const * pBegin, +void appendISO88591(OUStringBuffer & rText, sal_Char const * pBegin, sal_Char const * pEnd) { sal_Int32 nLength = pEnd - pBegin; std::unique_ptr pBuffer(new sal_Unicode[nLength]); for (sal_Unicode * p = pBuffer.get(); pBegin != pEnd;) *p++ = static_cast(*pBegin++); - rText += OUString(pBuffer.get(), nLength); + rText.append(pBuffer.get(), nLength); } // parseParameters @@ -376,7 +377,7 @@ bool parseParameters(ParameterList const & rInput, = getCharsetEncoding(it->m_aCharset.getStr(), it->m_aCharset.getStr() + it->m_aCharset.getLength()); - OUString aValue; + OUStringBuffer aValue; bool bBadEncoding = false; itNext = it; do @@ -401,7 +402,7 @@ bool parseParameters(ParameterList const & rInput, bBadEncoding = true; break; } - aValue += OUString(pUnicode, static_cast(nSize)); + aValue.append(pUnicode, static_cast(nSize)); delete[] pUnicode; ++itNext; } @@ -409,22 +410,22 @@ bool parseParameters(ParameterList const & rInput, if (bBadEncoding) { - aValue.clear(); + aValue.setLength(0); itNext = it; do { if (itNext->m_bExtended) { for (sal_Int32 i = 0; i < itNext->m_aValue.getLength(); ++i) - aValue += OUStringLiteral1( - sal_Unicode( - static_cast(itNext->m_aValue[i])) - | 0xF800); // map to unicode corporate use sub area + aValue.append( + static_cast( + static_cast(itNext->m_aValue[i]) + | 0xF800)); // map to unicode corporate use sub area } else { for (sal_Int32 i = 0; i < itNext->m_aValue.getLength(); ++i) - aValue += OUStringLiteral1( static_cast(itNext->m_aValue[i]) ); + aValue.append( static_cast(itNext->m_aValue[i]) ); } ++itNext; } @@ -432,7 +433,7 @@ bool parseParameters(ParameterList const & rInput, } auto const ret = pOutput->insert( {it->m_aAttribute, - {it->m_aCharset, it->m_aLanguage, aValue, !bBadEncoding}}); + {it->m_aCharset, it->m_aLanguage, aValue.makeStringAndClear(), !bBadEncoding}}); SAL_INFO_IF(!ret.second, "tools", "INetMIME: dropping duplicate parameter: " << it->m_aAttribute); } @@ -1156,7 +1157,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) const sal_Char * pBegin = rBody.getStr(); const sal_Char * pEnd = pBegin + rBody.getLength(); - OUString sDecoded; + OUStringBuffer sDecoded; const sal_Char * pCopyBegin = pBegin; /* bool bStartEncodedWord = true; */ @@ -1408,7 +1409,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) if (bEncodedWord) { appendISO88591(sDecoded, pCopyBegin, pWSPBegin); - sDecoded += OUString( + sDecoded.append( pUnicodeBuffer, static_cast< sal_Int32 >(nUnicodeSize)); delete[] pUnicodeBuffer; @@ -1424,7 +1425,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) } if (!sEncodedText.isEmpty()) - sDecoded += sEncodedText; + sDecoded.append(sEncodedText); if (p == pEnd) break; @@ -1454,7 +1455,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) appendISO88591(sDecoded, pCopyBegin, p - 1); sal_Unicode aUTF16Buf[2]; sal_Int32 nUTF16Len = putUTF32Character(aUTF16Buf, nCharacter) - aUTF16Buf; - sDecoded += OUString(aUTF16Buf, nUTF16Len); + sDecoded.append(aUTF16Buf, nUTF16Len); p = pUTF8End; pCopyBegin = p; } @@ -1466,7 +1467,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) } appendISO88591(sDecoded, pCopyBegin, pEnd); - return sDecoded; + return sDecoded.makeStringAndClear(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit