loplugin:stringview whitelist getLength and isEmpty

Change-Id: I38f3410c0b25ff579879b9de1f266af4d8fd51e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150256
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2023-04-12 08:29:04 +02:00
parent 08495e24e8
commit c45bc08dc6
19 changed files with 46 additions and 48 deletions

View File

@ -43,16 +43,9 @@ public:
bool preRun() override
{
auto const fn = handler.getMainFileName();
return !(
loplugin::isSamePathname(fn, SRCDIR "/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx")
|| loplugin::isSamePathname(fn, SRCDIR "/sal/qa/rtl/strings/test_ostring_concat.cxx")
|| loplugin::isSamePathname(fn, SRCDIR "/sal/qa/rtl/strings/test_oustring_concat.cxx")
|| loplugin::isSamePathname(fn, SRCDIR "/sal/qa/rtl/oustring/rtl_OUString2.cxx")
|| loplugin::isSamePathname(fn, SRCDIR "/sal/qa/rtl/strings/test_oustring_compare.cxx")
|| loplugin::isSamePathname(fn,
SRCDIR "/sal/qa/rtl/strings/test_oustring_startswith.cxx")
|| loplugin::isSamePathname(fn, SRCDIR
"/sal/qa/rtl/strings/test_strings_defaultstringview.cxx"));
return !(loplugin::isSamePathname(fn, SRCDIR "/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx")
|| loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/rtl/strings/")
|| loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/rtl/oustring/"));
}
virtual void run() override
@ -368,7 +361,8 @@ bool StringView::VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr)
|| dc.Function("toDouble") || dc.Function("equalsAscii") || dc.Function("equalsAsciiL")
|| dc.Function("equalsIgnoreAsciiCase") || dc.Function("compareToIgnoreAsciiCase")
|| dc.Function("matchIgnoreAsciiCase") || dc.Function("trim")
|| dc.Function("startsWith") || dc.Function("endsWith") || dc.Function("match"))
|| dc.Function("startsWith") || dc.Function("endsWith") || dc.Function("match")
|| dc.Function("isEmpty") || dc.Function("getLength"))
{
handleSubExprThatCouldBeView(expr->getImplicitObjectArgument());
}

View File

@ -196,7 +196,7 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >&
// External file AND/OR remote connection
else if (url.startsWith("sdbc:firebird:"))
{
m_sFirebirdURL = url.copy(OUString("sdbc:firebird:").getLength());
m_sFirebirdURL = url.copy(strlen("sdbc:firebird:"));
if (m_sFirebirdURL.startsWith("file://"))
{
m_bIsFile = true;

View File

@ -204,7 +204,7 @@ namespace dbaui
m_xJavaDriverLabel->set_visible(bEnableJDBC);
m_xJavaDriver->set_visible(bEnableJDBC);
m_xTestJavaDriver->set_visible(bEnableJDBC);
m_xTestJavaDriver->set_sensitive( !m_xJavaDriver->get_text().trim().isEmpty() );
m_xTestJavaDriver->set_sensitive( !o3tl::trim(m_xJavaDriver->get_text()).empty() );
m_xFL3->set_visible(bEnableJDBC);
checkTestConnection();
@ -244,7 +244,7 @@ namespace dbaui
#if HAVE_FEATURE_JAVA
try
{
if ( !m_xJavaDriver->get_text().trim().isEmpty() )
if ( !o3tl::trim(m_xJavaDriver->get_text()).empty() )
{
::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
m_xJavaDriver->set_text(m_xJavaDriver->get_text().trim()); // fdo#68341
@ -266,14 +266,14 @@ namespace dbaui
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
bool bEnableTestConnection = !m_xConnectionURL->get_visible() || !m_xConnectionURL->GetTextNoPrefix().isEmpty();
if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
bEnableTestConnection = bEnableTestConnection && (!m_xJavaDriver->get_text().trim().isEmpty());
bEnableTestConnection = bEnableTestConnection && (!o3tl::trim(m_xJavaDriver->get_text()).empty());
m_xTestConnection->set_sensitive(bEnableTestConnection);
return true;
}
IMPL_LINK(OConnectionTabPage, OnEditModified, weld::Entry&, rEdit, void)
{
if (&rEdit == m_xJavaDriver.get())
m_xTestJavaDriver->set_sensitive( !m_xJavaDriver->get_text().trim().isEmpty() );
m_xTestJavaDriver->set_sensitive( !o3tl::trim(m_xJavaDriver->get_text()).empty() );
checkTestConnection();
// tell the listener we were modified

View File

@ -448,7 +448,7 @@ using namespace ::com::sun::star;
OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
// to get the correct value when saveValue was called by base class
if ( m_xETDriverClass->get_text().trim().isEmpty() )
if ( o3tl::trim(m_xETDriverClass->get_text()).empty() )
{
m_xETDriverClass->set_text(m_sDefaultJdbcDriverName);
m_xETDriverClass->save_value();
@ -467,7 +467,7 @@ using namespace ::com::sun::star;
#if HAVE_FEATURE_JAVA
try
{
if ( !m_xETDriverClass->get_text().trim().isEmpty() )
if ( !o3tl::trim(m_xETDriverClass->get_text()).empty() )
{
// TODO change jvmaccess
::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
@ -488,8 +488,8 @@ using namespace ::com::sun::star;
void OGeneralSpecialJDBCConnectionPageSetup::callModifiedHdl(weld::Widget* pControl)
{
if (pControl == m_xETDriverClass.get())
m_xPBTestJavaDriver->set_sensitive( !m_xETDriverClass->get_text().trim().isEmpty() );
bool bRoadmapState = ((!m_xETDatabasename->get_text().isEmpty() ) && ( !m_xETHostname->get_text().isEmpty() ) && (!m_xNFPortNumber->get_text().isEmpty() ) && ( !m_xETDriverClass->get_text().trim().isEmpty() ));
m_xPBTestJavaDriver->set_sensitive( !o3tl::trim(m_xETDriverClass->get_text()).empty() );
bool bRoadmapState = ((!m_xETDatabasename->get_text().isEmpty() ) && ( !m_xETHostname->get_text().isEmpty() ) && (!m_xNFPortNumber->get_text().isEmpty() ) && ( !o3tl::trim(m_xETDriverClass->get_text()).empty() ));
SetRoadmapStateValue(bRoadmapState);
OGenericAdministrationPage::callModifiedHdl();
}

View File

@ -442,7 +442,7 @@ namespace dbaui
OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue);
// to get the correct value when saveValue was called by base class
if ( m_bUseClass && m_xEDDriverClass->get_text().trim().isEmpty() )
if ( m_bUseClass && o3tl::trim(m_xEDDriverClass->get_text()).empty() )
{
m_xEDDriverClass->set_text(m_sDefaultJdbcDriverName);
m_xEDDriverClass->save_value();
@ -457,7 +457,7 @@ namespace dbaui
#if HAVE_FEATURE_JAVA
try
{
if (!m_xEDDriverClass->get_text().trim().isEmpty())
if (!o3tl::trim(m_xEDDriverClass->get_text()).empty())
{
// TODO change jvmaccess
::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
@ -478,7 +478,7 @@ namespace dbaui
void OGeneralSpecialJDBCDetailsPage::callModifiedHdl(weld::Widget* pControl)
{
if (m_bUseClass && pControl == m_xEDDriverClass.get())
m_xTestJavaDriver->set_sensitive(!m_xEDDriverClass->get_text().trim().isEmpty());
m_xTestJavaDriver->set_sensitive(!o3tl::trim(m_xEDDriverClass->get_text()).empty());
// tell the listener we were modified
OGenericAdministrationPage::callModifiedHdl();

View File

@ -1146,7 +1146,7 @@ void Test::testUnderlineCopyPaste()
aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true );
// Assert changes
CPPUNIT_ASSERT_EQUAL( aTextLen + (OUString("textforunder")).getLength(), rDoc.GetTextLen() );
CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(aTextLen + strlen("textforunder")), rDoc.GetTextLen() );
CPPUNIT_ASSERT_EQUAL( OUString(aParaText + "textforunder" ), rDoc.GetParaAsString(sal_Int32(0)) );
// Check updated text for appropriate Underline

View File

@ -232,9 +232,9 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
current = entry[current] + word.getLength() + 1;
sal_Int32 start=current;
if (offset.hasElements()) {
if (word.getLength() != OUString(&wordData[current]).getLength())
if (word.getLength() != static_cast<sal_Int32>(std::u16string_view(&wordData[current]).size()))
one2one=false;
sal_Int32 convertedLength=OUString(&wordData[current]).getLength();
sal_Int32 convertedLength=std::u16string_view(&wordData[current]).size();
while (wordData[current]) {
offsetRange[count]=nStartPos + currPos + ((current-start) *
word.getLength() / convertedLength);

View File

@ -29,6 +29,7 @@
#include <iostream>
#include <osl/file.hxx>
#include <osl/process.h>
#include <o3tl/string_view.hxx>
#include <rtl/ustring.hxx>
#include <rtl/strbuf.hxx>
#include <unicode/regex.h>
@ -1060,7 +1061,7 @@ bool lcl_isTag( const icu::UnicodeString& rString )
OString XMLUtil::QuotHTML( const OString &rString )
{
if( rString.trim().isEmpty() )
if( o3tl::trim(rString).empty() )
return rString;
UErrorCode nIcuErr = U_ZERO_ERROR;
static const sal_uInt32 nSearchFlags =

View File

@ -2438,7 +2438,7 @@ void XmlStreamObject::implDumpText( TextInputStream& rTextStrm )
entirely. */
mxOut->writeString( aElem );
mxOut->newLine();
if( !aText.trim().isEmpty() )
if( !o3tl::trim(aText).empty() )
{
mxOut->writeString( aText );
mxOut->newLine();

View File

@ -138,7 +138,7 @@ OXMLGroup::OXMLGroup( ORptFilter& _rImport
{
nGroupOn = report::GroupOn::INTERVAL;
_rImport.removeFunction(sExpression);
sExpression = sExpression.copy(OUString("INT_count_").getLength());
sExpression = sExpression.copy(std::string_view("INT_count_").size());
OUString sInterval = sCompleteFormula.getToken(1,'/');
sInterval = sInterval.getToken(0,')');
m_xGroup->setGroupInterval(sInterval.toInt32());

View File

@ -325,7 +325,7 @@ bool SmEditTextWindow::KeyInput(const KeyEvent& rKEvt)
if (index != -1)
{
selected = selected.copy(index, sal_Int32(aSelection.nEndPos-index));
if (selected.trim().isEmpty())
if (o3tl::trim(selected).empty())
autoClose = true;
}
else
@ -336,7 +336,7 @@ bool SmEditTextWindow::KeyInput(const KeyEvent& rKEvt)
else
{
selected = selected.copy(aSelection.nEndPos);
if (selected.trim().isEmpty())
if (o3tl::trim(selected).empty())
autoClose = true;
}
}

View File

@ -176,12 +176,12 @@ void PlaceEditDialog::InitDetails( )
// Create CMIS controls for each server type
// Load the ServerType entries
bool bSkipGDrive = OUString( GDRIVE_CLIENT_ID ).isEmpty() ||
OUString( GDRIVE_CLIENT_SECRET ).isEmpty();
bool bSkipAlfresco = OUString( ALFRESCO_CLOUD_CLIENT_ID ).isEmpty() ||
OUString( ALFRESCO_CLOUD_CLIENT_SECRET ).isEmpty();
bool bSkipOneDrive= OUString( ONEDRIVE_CLIENT_ID ).isEmpty() ||
OUString( ONEDRIVE_CLIENT_SECRET ).isEmpty();
bool bSkipGDrive = std::string_view( GDRIVE_CLIENT_ID ).empty() ||
std::string_view( GDRIVE_CLIENT_SECRET ).empty();
bool bSkipAlfresco = std::string_view( ALFRESCO_CLOUD_CLIENT_ID ).empty() ||
std::string_view( ALFRESCO_CLOUD_CLIENT_SECRET ).empty();
bool bSkipOneDrive= std::string_view( ONEDRIVE_CLIENT_ID ).empty() ||
std::string_view( ONEDRIVE_CLIENT_SECRET ).empty();
Sequence< OUString > aTypesUrlsList( officecfg::Office::Common::Misc::CmisServersUrls::get() );
Sequence< OUString > aTypesNamesList( officecfg::Office::Common::Misc::CmisServersNames::get() );

View File

@ -96,6 +96,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <officecfg/Office/Common.hxx>
#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <bitmaps.hlst>
#include <sal/log.hxx>
@ -4352,7 +4353,7 @@ void ColorListBox::createColorWindow()
void ColorListBox::SelectEntry(const NamedColor& rColor)
{
if (rColor.second.trim().isEmpty())
if (o3tl::trim(rColor.second).empty())
{
SelectEntry(rColor.first);
return;

View File

@ -36,6 +36,7 @@
#include <txtftn.hxx>
#include <txtfrm.hxx>
#include <svl/itemiter.hxx>
#include <o3tl/string_view.hxx>
#include <o3tl/vector_utils.hxx>
#include <svx/swframetypes.hxx>
#include <fmtanchr.hxx>
@ -1253,7 +1254,7 @@ public:
const uno::Reference<document::XDocumentProperties> xDocumentProperties(
xDPS->getDocumentProperties());
OUString sTitle = xDocumentProperties->getTitle();
if (sTitle.trim().isEmpty())
if (o3tl::trim(sTitle).empty())
{
lclAddIssue(m_rIssueCollection, SwResId(STR_DOCUMENT_TITLE),
sfx::AccessibilityIssueID::DOCUMENT_TITLE);

View File

@ -68,6 +68,7 @@
#include <ndindex.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <osl/diagnose.h>
#include <o3tl/string_view.hxx>
#include <wrtsh.hxx>
#include <view.hxx>
@ -1996,7 +1997,7 @@ bool SwFlyFrame::IsShowUnfloatButton(SwWrtShell* pWrtSh) const
if (pLower->IsTextFrame())
{
const SwTextFrame* pTextFrame = static_cast<const SwTextFrame*>(pLower);
if (!pTextFrame->GetText().trim().isEmpty())
if (!o3tl::trim(pTextFrame->GetText()).empty())
return false;
}
pLower = pLower->GetNext();

View File

@ -790,13 +790,13 @@ namespace
OUStringBuffer aBuf;
sal_Int32 nTextLen;
nTextLen = OUString(OUString::number(rFormatter.GetMin())).getLength();
nTextLen = std::u16string_view(OUString::number(rFormatter.GetMin())).size();
string::padToLength(aBuf, nTextLen, '9');
Size aMinTextSize = rSpinField.CalcMinimumSizeForText(
rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
aBuf.setLength(0);
nTextLen = OUString(OUString::number(rFormatter.GetMax())).getLength();
nTextLen = std::u16string_view(OUString::number(rFormatter.GetMax())).size();
string::padToLength(aBuf, nTextLen, '9');
Size aMaxTextSize = rSpinField.CalcMinimumSizeForText(
rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));

View File

@ -77,12 +77,12 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter,
{
const OUString& rCollapsed = pBmpItem->GetBitmap1().GetStock();
const OUString& rExpanded = pBmpItem->GetBitmap2().GetStock();
if (!rCollapsed.trim().isEmpty() || !rExpanded.trim().isEmpty())
if (!o3tl::trim(rCollapsed).empty() || !o3tl::trim(rExpanded).empty())
{
auto aColumn = rJsonWriter.startStruct();
if (!rCollapsed.trim().isEmpty())
if (!o3tl::trim(rCollapsed).empty())
rJsonWriter.put("collapsed", rCollapsed);
if (!rExpanded.trim().isEmpty())
if (!o3tl::trim(rExpanded).empty())
rJsonWriter.put("expanded", rExpanded);
}
}

View File

@ -291,7 +291,7 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< uno::XComponentConte
pCurrentVectorIndex.reset();
aIndexFolderResultVectorVector.clear();
sal_Int32 replIdx = OUString( "#HLP#" ).getLength();
sal_Int32 replIdx = strlen( "#HLP#" );
OUString replWith = "vnd.sun.star.help://";
int nResultCount = aCompleteResultVector.size();

View File

@ -303,7 +303,7 @@ bool OPropertyImport::encounteredAttribute(sal_Int32 nAttributeToken) const
void OPropertyImport::characters(const OUString& _rChars )
{
// ignore them (should be whitespace only)
OSL_ENSURE(_rChars.trim().isEmpty(), "OPropertyImport::Characters: non-whitespace characters!");
OSL_ENSURE(o3tl::trim(_rChars).empty(), "OPropertyImport::Characters: non-whitespace characters!");
}
bool OPropertyImport::handleAttribute(sal_Int32 nAttributeToken, const OUString& _rValue)
@ -370,7 +370,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > OPropertyElementsConte
void OPropertyElementsContext::characters(const OUString& _rChars)
{
OSL_ENSURE(_rChars.trim().isEmpty(), "OPropertyElementsContext::Characters: non-whitespace characters detected!");
OSL_ENSURE(o3tl::trim(_rChars).empty(), "OPropertyElementsContext::Characters: non-whitespace characters detected!");
}
#endif