diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-02-07 23:21:27 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-02-08 09:09:32 +0100 |
commit | b01e0483ee14826057c42dfa58c3d6200a474791 (patch) | |
tree | df3602677ecf67edb532216fd767e63a347d6ac0 | |
parent | b314b5a0612c9dc7279039dae44a250d4d3ec6b1 (diff) |
Extend loplugin:stringview to O[U]StringBuffer::toString
Change-Id: I7ad212dfff8b34d05e3b45107a1ef033a4efc454
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129651
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | codemaker/source/javamaker/javatype.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/stringview.cxx | 24 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringview.cxx | 14 | ||||
-rw-r--r-- | configmgr/source/components.cxx | 2 | ||||
-rw-r--r-- | svx/source/svdraw/svdmrkv.cxx | 2 | ||||
-rw-r--r-- | unodevtools/source/skeletonmaker/cppcompskeleton.cxx | 2 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfdocument.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdispatchdestination.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 2 |
9 files changed, 41 insertions, 18 deletions
diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index c7c84a208b3a..2bd624299a30 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -328,7 +328,7 @@ public: OString getDescriptor() const; - OString getSignature() const { return m_needsSignature ? m_signatureStart.toString() + m_signatureEnd : OString();} + OString getSignature() const { return m_needsSignature ? m_signatureStart + m_signatureEnd : OString();} private: rtl::Reference< TypeManager > m_manager; diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx index b3a0323d2923..4c31c348b357 100644 --- a/compilerplugins/clang/stringview.cxx +++ b/compilerplugins/clang/stringview.cxx @@ -268,19 +268,29 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr) void StringView::handleCXXMemberCallExpr(CXXMemberCallExpr const* expr) { - auto const dc = loplugin::DeclCheck(expr->getMethodDecl()).Function("copy"); - if (!dc) + auto const dc1 = loplugin::DeclCheck(expr->getMethodDecl()); + if (auto const dc2 = dc1.Function("copy")) { + if (dc2.Class("OString").Namespace("rtl").GlobalNamespace() + || dc2.Class("OUString").Namespace("rtl").GlobalNamespace()) + { + report(DiagnosticsEngine::Warning, "rather than copy, pass with a view using subView()", + expr->getExprLoc()) + << expr->getSourceRange(); + } return; } - if (!(dc.Class("OString").Namespace("rtl").GlobalNamespace() - || dc.Class("OUString").Namespace("rtl").GlobalNamespace())) + if (auto const dc2 = dc1.Function("toString")) { + if (dc2.Class("OStringBuffer").Namespace("rtl").GlobalNamespace() + || dc2.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()) + { + report(DiagnosticsEngine::Warning, "rather than call toString, pass with a view", + expr->getExprLoc()) + << expr->getSourceRange(); + } return; } - report(DiagnosticsEngine::Warning, "rather than copy, pass with a view using subView()", - expr->getExprLoc()) - << expr->getSourceRange(); } /** check for calls to O[U]StringBuffer::append that could be passed as a diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx index c03fbb84cb32..16e294a6eeb7 100644 --- a/compilerplugins/clang/test/stringview.cxx +++ b/compilerplugins/clang/test/stringview.cxx @@ -59,6 +59,20 @@ void f1(OString s1) // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}} ConstructWithView(s1.copy(1)); } +void f1(OUStringBuffer s1) +{ + // expected-error@+1 {{rather than call toString, pass with a view [loplugin:stringview]}} + call_view(s1.toString()); + // expected-error@+1 {{rather than call toString, pass with a view [loplugin:stringview]}} + ConstructWithView(s1.toString()); +} +void f1(OStringBuffer s1) +{ + // expected-error@+1 {{rather than call toString, pass with a view [loplugin:stringview]}} + call_view(s1.toString()); + // expected-error@+1 {{rather than call toString, pass with a view [loplugin:stringview]}} + ConstructWithView(s1.toString()); +} } namespace test2 diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 65bc00da9517..3863103e2763 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -843,7 +843,7 @@ void Components::parseXcsXcuIniLayer( } } prefix.append(':'); - OUString urls(prefix.toString() + "SCHEMA}"); + OUString urls(prefix + "SCHEMA}"); rtl::Bootstrap::expandMacros(urls); if (!urls.isEmpty()) { parseFileList(layer, &parseXcsFile, urls, false); diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index 73e530b2cd5e..38c4bce2ed56 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -1099,7 +1099,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S } if (!aExtraInfo.isEmpty()) { - sSelectionTextView = sSelectionText + ", " + aExtraInfo.toString() + "}"; + sSelectionTextView = sSelectionText + ", " + aExtraInfo + "}"; aExtraInfo.append(handleArrayStr); aExtraInfo.append("}"); sSelectionText += ", " + aExtraInfo.makeStringAndClear(); diff --git a/unodevtools/source/skeletonmaker/cppcompskeleton.cxx b/unodevtools/source/skeletonmaker/cppcompskeleton.cxx index c7dbbf73451d..301aebff8906 100644 --- a/unodevtools/source/skeletonmaker/cppcompskeleton.cxx +++ b/unodevtools/source/skeletonmaker/cppcompskeleton.cxx @@ -661,7 +661,7 @@ static OString generateClassDefinition(std::ostream& o, "css::uno::RuntimeException);\n"; OStringBuffer buffer(256); - buffer.append(parentname.toString()); + buffer.append(parentname); buffer.append("< "); std::set< OUString >::const_iterator iter = interfaces.begin(); while (iter != interfaces.end()) diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx index 4573d414cfc6..3d005a45ff2e 100644 --- a/vcl/source/filter/ipdf/pdfdocument.cxx +++ b/vcl/source/filter/ipdf/pdfdocument.cxx @@ -175,7 +175,7 @@ sal_Int32 PDFDocument::WriteSignatureObject(const OUString& rDescription, bool b } aSigBuffer.append(" >>\nendobj\n\n"); - m_aEditBuffer.WriteOString(aSigBuffer.toString()); + m_aEditBuffer.WriteOString(aSigBuffer); return nSignatureId; } @@ -809,7 +809,7 @@ void PDFDocument::WriteXRef(sal_uInt64 nXRefOffset, PDFReferenceElement const* p aBuffer.append(" 65535 f \n"); else aBuffer.append(" 00000 n \n"); - m_aEditBuffer.WriteOString(aBuffer.toString()); + m_aEditBuffer.WriteOString(aBuffer); } // Write the trailer. @@ -955,7 +955,7 @@ bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificat assert(aCMSHexBuffer.getLength() <= MAX_SIGNATURE_CONTENT_LENGTH); m_aEditBuffer.Seek(nSignatureContentOffset); - m_aEditBuffer.WriteOString(aCMSHexBuffer.toString()); + m_aEditBuffer.WriteOString(aCMSHexBuffer); return true; } diff --git a/writerfilter/source/rtftok/rtfdispatchdestination.cxx b/writerfilter/source/rtftok/rtfdispatchdestination.cxx index 11db48a0ec6d..a113f59a5a97 100644 --- a/writerfilter/source/rtftok/rtfdispatchdestination.cxx +++ b/writerfilter/source/rtftok/rtfdispatchdestination.cxx @@ -87,7 +87,7 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) bFoundCode = true; } - if (aBuf.toString() == "INCLUDEPICTURE") + if (std::string_view(aBuf) == "INCLUDEPICTURE") { // Extract the field argument of INCLUDEPICTURE: we handle that // at a tokenizer level, as DOCX has no such field. @@ -99,8 +99,7 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) break; aBuf.append(ch); } - OUString aFieldCommand - = OStringToOUString(aBuf.toString(), RTL_TEXTENCODING_UTF8); + OUString aFieldCommand = OStringToOUString(aBuf, RTL_TEXTENCODING_UTF8); std::tuple<OUString, std::vector<OUString>, std::vector<OUString>> aResult = writerfilter::dmapper::splitFieldCommand(aFieldCommand); m_aPicturePath diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index fb331f4b265a..f0847e945ebe 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -3640,7 +3640,7 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex) if (m_aStates.top().getDestination() == Destination::FONTENTRY && m_aStates.top().getCurrentEncoding() == RTL_TEXTENCODING_SYMBOL) nEncoding = RTL_TEXTENCODING_MS_1252; - OUString aString = OStringToOUString(m_aHexBuffer.toString(), nEncoding); + OUString aString = OStringToOUString(m_aHexBuffer, nEncoding); m_aHexBuffer.setLength(0); aString = FilterControlChars(m_aStates.top().getDestination(), aString); text(aString); |