[Libreoffice-commits] core.git: codemaker/source compilerplugins/clang connectivity/source dbaccess/source include/rtl sc/source sfx2/source uui/source vcl/workben

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 17 16:17:38 UTC 2019


 codemaker/source/javamaker/javatype.cxx                   |    4 --
 compilerplugins/clang/bufferadd.cxx                       |   21 --------------
 compilerplugins/clang/test/bufferadd.cxx                  |   18 ++++++++++++
 connectivity/source/drivers/firebird/DatabaseMetaData.cxx |   16 ++++------
 dbaccess/source/core/recovery/settingsimport.cxx          |    3 --
 include/rtl/strbuf.hxx                                    |    7 ++++
 include/rtl/ustrbuf.hxx                                   |    7 ++++
 sc/source/core/data/documen4.cxx                          |    9 ++----
 sc/source/filter/excel/xecontent.cxx                      |    4 +-
 sfx2/source/view/lokhelper.cxx                            |   10 +++---
 uui/source/iahndl.cxx                                     |    9 +-----
 vcl/workben/svpclient.cxx                                 |    8 ++---
 12 files changed, 58 insertions(+), 58 deletions(-)

New commits:
commit 3ebbb150242cf049a9ddab7f498c63f3a44aa034
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Oct 17 15:14:02 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 17 18:16:28 2019 +0200

    loplugin:buffereadd find stuff involving adding *StringBuffer
    
    and create conversion methods on *StringBuffer to make this work
    
    Change-Id: I3cf5ee3e139826168894b46eff8ee4bcde00cb7e
    Reviewed-on: https://gerrit.libreoffice.org/80949
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx
index 28d6081e8c8b..0616d8f08771 100644
--- a/codemaker/source/javamaker/javatype.cxx
+++ b/codemaker/source/javamaker/javatype.cxx
@@ -378,9 +378,7 @@ void MethodDescriptor::addTypeParameter(OUString const & name) {
 }
 
 OString MethodDescriptor::getDescriptor() const {
-    OStringBuffer buf(m_descriptorStart);
-    buf.append(m_descriptorEnd);
-    return buf.makeStringAndClear();
+    return rtl::OStringView(m_descriptorStart) + m_descriptorEnd;
 }
 
 
diff --git a/compilerplugins/clang/bufferadd.cxx b/compilerplugins/clang/bufferadd.cxx
index 659b110403e3..4346e9ca28b2 100644
--- a/compilerplugins/clang/bufferadd.cxx
+++ b/compilerplugins/clang/bufferadd.cxx
@@ -175,19 +175,6 @@ void BufferAdd::findBufferAssignOrAdd(const Stmt* parentStmt, Stmt const* stmt)
                 auto cxxConstructExpr = dyn_cast<CXXConstructExpr>(ignore(varDeclLHS->getInit()));
                 if (cxxConstructExpr)
                 {
-                    if (cxxConstructExpr->getNumArgs() == 0)
-                    {
-                        addToGoodMap(varDeclLHS, parentStmt);
-                        return;
-                    }
-                    auto tc2 = loplugin::TypeCheck(cxxConstructExpr->getArg(0)->getType());
-                    if (tc2.LvalueReference().Class("OUStringBuffer")
-                        || tc2.LvalueReference().Class("OStringBuffer")
-                        || tc2.Class("OUStringBuffer") || tc2.Class("OStringBuffer"))
-                    {
-                        badMap.insert(varDeclLHS);
-                        return;
-                    }
                     addToGoodMap(varDeclLHS, parentStmt);
                     return;
                 }
@@ -286,10 +273,6 @@ bool BufferAdd::isMethodOkToMerge(CXXMemberCallExpr const* memberCall)
     auto methodDecl = memberCall->getMethodDecl();
     if (methodDecl->getNumParams() == 0)
         return true;
-    auto tc2 = loplugin::TypeCheck(methodDecl->getParamDecl(0)->getType());
-    if (tc2.LvalueReference().Class("OUStringBuffer")
-        || tc2.LvalueReference().Class("OStringBuffer"))
-        return false;
 
     auto name = methodDecl->getName();
     if (name == "appendUninitialized" || name == "setLength" || name == "remove" || name == "insert"
@@ -338,9 +321,7 @@ bool BufferAdd::isSideEffectFree(Expr const* expr)
         if (auto calleeMethodDecl = dyn_cast_or_null<CXXMethodDecl>(callExpr->getCalleeDecl()))
             if (calleeMethodDecl && calleeMethodDecl->getIdentifier())
             {
-                auto name = calleeMethodDecl->getName();
-                if (callExpr->getNumArgs() > 0
-                    && (name == "number" || name == "unacquired" || name == "boolean"))
+                if (callExpr->getNumArgs() > 0)
                 {
                     auto tc = loplugin::TypeCheck(calleeMethodDecl->getParent());
                     if (tc.Class("OUString") || tc.Class("OString"))
diff --git a/compilerplugins/clang/test/bufferadd.cxx b/compilerplugins/clang/test/bufferadd.cxx
index 7d8d9a693b9f..a9f28b13b55a 100644
--- a/compilerplugins/clang/test/bufferadd.cxx
+++ b/compilerplugins/clang/test/bufferadd.cxx
@@ -46,6 +46,24 @@ void f4(sal_Unicode const* pPathBegin)
     v.append(pPathBegin, 12);
     v.append("aaaa");
 }
+void f5(OUStringBuffer& input)
+{
+    // expected-error at +1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}}
+    OUStringBuffer v(input);
+    v.append("aaaa");
+}
+struct Footer
+{
+    OStringBuffer m_descriptorStart;
+    OString m_descriptorEnd;
+    OString f8() const
+    {
+        // expected-error at +1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}}
+        OStringBuffer buf(m_descriptorStart);
+        buf.append(m_descriptorEnd);
+        return buf.makeStringAndClear();
+    }
+};
 }
 
 namespace test2
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index b0344b5f8b8f..c152694a5963 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1566,22 +1566,18 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
     SAL_INFO("connectivity.firebird", "getPrimaryKeys() with "
              "Table: " << sTable);
 
-    OUStringBuffer aQueryBuf("SELECT "
+    OUString sAppend = "WHERE constr.RDB$RELATION_NAME = '%' ";
+    OUString sQuery = "SELECT "
         "constr.RDB$RELATION_NAME, "    // 1. Table Name
         "inds.RDB$FIELD_NAME, "         // 2. Column Name
         "inds.RDB$FIELD_POSITION, "     // 3. Sequence Number
         "constr.RDB$CONSTRAINT_NAME "   // 4 Constraint name
         "FROM RDB$RELATION_CONSTRAINTS constr "
         "JOIN RDB$INDEX_SEGMENTS inds "
-        "on (constr.RDB$INDEX_NAME = inds.RDB$INDEX_NAME) ");
-
-    OUString sAppend = "WHERE constr.RDB$RELATION_NAME = '%' ";
-    aQueryBuf.append(sAppend.replaceAll("%", sTable));
-
-    aQueryBuf.append("AND constr.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' "
-                    "ORDER BY inds.RDB$FIELD_NAME");
-
-    OUString sQuery = aQueryBuf.makeStringAndClear();
+        "on (constr.RDB$INDEX_NAME = inds.RDB$INDEX_NAME) " +
+        sAppend.replaceAll("%", sTable) +
+        "AND constr.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' "
+                    "ORDER BY inds.RDB$FIELD_NAME";
 
     uno::Reference< XStatement > xStatement = m_pConnection->createStatement();
     uno::Reference< XResultSet > xRs = xStatement->executeQuery(sQuery);
diff --git a/dbaccess/source/core/recovery/settingsimport.cxx b/dbaccess/source/core/recovery/settingsimport.cxx
index 1c46b8b0717a..b64787aa82a4 100644
--- a/dbaccess/source/core/recovery/settingsimport.cxx
+++ b/dbaccess/source/core/recovery/settingsimport.cxx
@@ -139,8 +139,7 @@ namespace dbaccess
         o_rValue.clear();
 
         // the characters building up th evalue
-        OUStringBuffer aCharacters( getAccumulatedCharacters() );
-        const OUString sValue = aCharacters.makeStringAndClear();
+        const OUString sValue = getAccumulatedCharacters().toString();
 
         const OUString& rItemType( getItemType() );
         ENSURE_OR_RETURN_VOID( !rItemType.isEmpty(), "no item type -> no item value" );
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index afead770298d..ffb67d25c42d 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -1035,6 +1035,13 @@ public:
         *pInternalCapacity = &nCapacity;
     }
 
+#if defined LIBO_INTERNAL_ONLY
+    operator OStringView() const
+    {
+        return OStringView(getStr(), getLength());
+    }
+#endif
+
 private:
     /**
         A pointer to the data structure which contains the data.
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 1f12ef9caeb9..1d73a7fbd843 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -1634,6 +1634,13 @@ public:
         return OUStringBuffer( pNew, count + 16 );
     }
 
+#if defined LIBO_INTERNAL_ONLY
+    operator OUStringView() const
+    {
+        return OUStringView(getStr(), getLength());
+    }
+#endif
+
 private:
     OUStringBuffer( rtl_uString * value, const sal_Int32 capacity )
     {
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 1d36d52e3bfb..8b55b15a6f50 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -1171,11 +1171,10 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
             GetName( nThisTab, aTabName );
             OUString aTemplate = ScResId(STR_PROGRESS_COMPARING);
             sal_Int32 nIndex = 0;
-            OUStringBuffer aProText = aTemplate.getToken( 0, '#', nIndex );
-            aProText.append(aTabName);
-            aProText.append(aTemplate.getToken( 0, '#', nIndex ));
-            ScProgress aProgress( GetDocumentShell(),
-                                        aProText.makeStringAndClear(), 3*nThisEndRow, true );  // 2x FindOrder, 1x here
+            OUString aProText = aTemplate.getToken( 0, '#', nIndex ) +
+                aTabName +
+                aTemplate.getToken( 0, '#', nIndex );
+            ScProgress aProgress( GetDocumentShell(), aProText, 3*nThisEndRow, true );  // 2x FindOrder, 1x here
             long nProgressStart = 2*nThisEndRow;                    // start for here
 
             std::unique_ptr<SCCOLROW[]> pTempRows(new SCCOLROW[nThisEndRow+1]);
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index fc354d0ba69b..38155ca6eaa8 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -989,8 +989,8 @@ bool RequiresFixedFormula(ScConditionMode eMode)
 OString GetFixedFormula(ScConditionMode eMode, const ScAddress& rAddress, const OString& rText)
 {
     OStringBuffer aBuffer;
-    OStringBuffer aPosBuffer = XclXmlUtils::ToOString(aBuffer, rAddress);
-    OString aPos = aPosBuffer.makeStringAndClear();
+    XclXmlUtils::ToOString(aBuffer, rAddress);
+    OString aPos = aBuffer.makeStringAndClear();
     switch (eMode)
     {
         case ScConditionMode::Error:
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 5d72a583d67b..09e6d59129f3 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -284,11 +284,11 @@ void SfxLokHelper::notifyAllViews(int nType, const OString& rPayload)
 
 void SfxLokHelper::notifyContextChange(SfxViewShell const* pViewShell, const OUString& aApplication, const OUString& aContext)
 {
-    OStringBuffer aBuffer;
-    aBuffer.append(OUStringToOString(aApplication.replace(' ', '_'), RTL_TEXTENCODING_UTF8));
-    aBuffer.append(' ');
-    aBuffer.append(OUStringToOString(aContext.replace(' ', '_'), RTL_TEXTENCODING_UTF8));
-    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_CHANGED, aBuffer.makeStringAndClear().getStr());
+    OString aBuffer =
+        OUStringToOString(aApplication.replace(' ', '_'), RTL_TEXTENCODING_UTF8) +
+        " " +
+        OUStringToOString(aContext.replace(' ', '_'), RTL_TEXTENCODING_UTF8);
+    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_CHANGED, aBuffer.getStr());
 }
 
 
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index 5b026a4082d9..87b4825043cb 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -891,21 +891,16 @@ UUIInteractionHelper::getInteractionHandlerList(
             // Iterate over children.
             for ( const auto& rElem : aElems )
             {
-                OUStringBuffer aElemBuffer;
-                aElemBuffer.append( "['" );
-                aElemBuffer.append( rElem );
-
                 try
                 {
                     InteractionHandlerData aInfo;
 
                     // Obtain service name.
-                    OUStringBuffer aKeyBuffer = aElemBuffer;
-                    aKeyBuffer.append( "']/ServiceName" );
+                    OUString aKeyBuffer = "['" + rElem + "']/ServiceName";
 
                     OUString aValue;
                     if ( !( xHierNameAccess->getByHierarchicalName(
-                                aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
+                                aKeyBuffer ) >>= aValue ) )
                     {
                         OSL_FAIL( "GetInteractionHandlerList - "
                                     "Error getting item value!" );
diff --git a/vcl/workben/svpclient.cxx b/vcl/workben/svpclient.cxx
index 8ef179b0c1a2..74ccb9f9205f 100644
--- a/vcl/workben/svpclient.cxx
+++ b/vcl/workben/svpclient.cxx
@@ -254,10 +254,10 @@ IMPL_LINK_NOARG( MyWin, SelectHdl, ListBox&, void)
     if( nPos == -1 )
         return;
 
-    OStringBuffer aCommand( 64 );
-    aCommand.append( "get " );
-    aCommand.append( OUStringToOString( aEntry.copy( nPos+2 ), RTL_TEXTENCODING_ASCII_US ) );
-    OString aAnswer( processCommand( aCommand.makeStringAndClear() ) );
+    OString aCommand =
+        "get " +
+        OUStringToOString( aEntry.copy( nPos+2 ), RTL_TEXTENCODING_ASCII_US );
+    OString aAnswer( processCommand( aCommand ) );
     SvMemoryStream aStream( aAnswer.getLength() );
     aStream.WriteBytes( aAnswer.getStr(), aAnswer.getLength() );
     aStream.Seek( STREAM_SEEK_TO_BEGIN );


More information about the Libreoffice-commits mailing list