Extend loplugin:stringviewparam to starts/endsWith: sw
Change-Id: I7271bba6c61a56be15335c81d8950a29a07eb6d4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122473
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
diff --git a/sw/inc/iodetect.hxx b/sw/inc/iodetect.hxx
index 1d5713a..9069b01 100644
--- a/sw/inc/iodetect.hxx
+++ b/sw/inc/iodetect.hxx
@@ -21,6 +21,8 @@
#define INCLUDED_SW_INC_IODETECT_HXX
#include <memory>
#include <string_view>
#include <o3tl/string_view.hxx>
#include <rtl/ustring.hxx>
#include <tools/lineend.hxx>
#include <tools/solar.h>
@@ -59,9 +61,9 @@ struct SwIoDetect
{
}
bool IsFilter( const OUString& rNm ) const
bool IsFilter( std::u16string_view rNm ) const
{
return rNm.startsWith(sName);
return o3tl::starts_with(rNm, sName);
}
};
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index f24cfda..65462bf 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -35,9 +35,11 @@
#include <optional>
#include <sal/log.hxx>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <algorithm>
#include <string_view>
using namespace std;
@@ -756,7 +758,7 @@ OUString SwFormToken::GetString() const
@return the type of the token
*/
static FormTokenType lcl_GetTokenType(const OUString & sToken,
static FormTokenType lcl_GetTokenType(std::u16string_view sToken,
sal_Int32 & rTokenLen)
{
static struct
@@ -779,7 +781,7 @@ static FormTokenType lcl_GetTokenType(const OUString & sToken,
for(const auto & i : aTokenArr)
{
if( sToken.startsWith( i.sTokenStart ) )
if( o3tl::starts_with( sToken, i.sTokenStart ) )
{
rTokenLen = i.nTokenLength;
return i.eTokenType;
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 0a93658..4851035 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <hintids.hxx>
#include <vcl/svapp.hxx>
#include <svl/hint.hxx>
@@ -115,6 +116,7 @@
#include <cassert>
#include <memory>
#include <set>
#include <string_view>
#include <limits>
using namespace css;
@@ -2468,12 +2470,12 @@ beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName)
// allow to retarget the SfxItemSet working on, default correctly. Only
// use pSourceSet below this point (except in header/footer processing)
static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, const OUString& rPropertyName)
static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, std::u16string_view rPropertyName)
{
if(eFamily != SfxStyleFamily::Page)
return &rSet;
const bool isFooter = rPropertyName.startsWith("Footer");
if(!isFooter && !rPropertyName.startsWith("Header") && rPropertyName != UNO_NAME_FIRST_IS_SHARED)
const bool isFooter = o3tl::starts_with(rPropertyName, u"Footer");
if(!isFooter && !o3tl::starts_with(rPropertyName, u"Header") && rPropertyName != u"" UNO_NAME_FIRST_IS_SHARED)
return &rSet;
const SvxSetItem* pSetItem;
if(!lcl_GetHeaderFooterItem(rSet, rPropertyName, isFooter, pSetItem))
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index f764fe9..a782114 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -138,6 +138,7 @@
#include <txtatr.hxx>
#include <frameformats.hxx>
#include <o3tl/string_view.hxx>
#include <o3tl/unit_conversion.hxx>
#include <osl/file.hxx>
#include <utility>
@@ -152,6 +153,7 @@
#include <com/sun/star/embed/Aspects.hpp>
#include <algorithm>
#include <cstddef>
#include <stdarg.h>
#include <string_view>
@@ -1787,33 +1789,34 @@ void DocxAttributeOutput::DoWriteBookmarksEnd(std::vector<OUString>& rEnds)
// - "permission-for-user:<permission-id>:<permission-user-name>"
// - "permission-for-group:<permission-id>:<permission-group-name>"
//
void DocxAttributeOutput::DoWritePermissionTagStart(const OUString & permission)
void DocxAttributeOutput::DoWritePermissionTagStart(std::u16string_view permission)
{
OUString permissionIdAndName;
std::u16string_view permissionIdAndName;
if (permission.startsWith("permission-for-group:", &permissionIdAndName))
if (o3tl::starts_with(permission, u"permission-for-group:", &permissionIdAndName))
{
const sal_Int32 separatorIndex = permissionIdAndName.indexOf(':');
assert(separatorIndex != -1);
const OUString permissionId = permissionIdAndName.copy(0, separatorIndex);
const OUString permissionName = permissionIdAndName.copy(separatorIndex + 1);
const std::size_t separatorIndex = permissionIdAndName.find(u':');
assert(separatorIndex != std::u16string_view::npos);
const std::u16string_view permissionId = permissionIdAndName.substr(0, separatorIndex);
const std::u16string_view permissionName = permissionIdAndName.substr(separatorIndex + 1);
m_pSerializer->singleElementNS(XML_w, XML_permStart,
FSNS(XML_w, XML_id), BookmarkToWord(permissionId),
FSNS(XML_w, XML_edGrp), BookmarkToWord(permissionName));
FSNS(XML_w, XML_id), BookmarkToWord(OUString(permissionId)),
FSNS(XML_w, XML_edGrp), BookmarkToWord(OUString(permissionName)));
}
else
{
auto const ok = permission.startsWith("permission-for-user:", &permissionIdAndName);
auto const ok = o3tl::starts_with(
permission, u"permission-for-user:", &permissionIdAndName);
assert(ok); (void)ok;
const sal_Int32 separatorIndex = permissionIdAndName.indexOf(':');
assert(separatorIndex != -1);
const OUString permissionId = permissionIdAndName.copy(0, separatorIndex);
const OUString permissionName = permissionIdAndName.copy(separatorIndex + 1);
const std::size_t separatorIndex = permissionIdAndName.find(u':');
assert(separatorIndex != std::u16string_view::npos);
const std::u16string_view permissionId = permissionIdAndName.substr(0, separatorIndex);
const std::u16string_view permissionName = permissionIdAndName.substr(separatorIndex + 1);
m_pSerializer->singleElementNS(XML_w, XML_permStart,
FSNS(XML_w, XML_id), BookmarkToWord(permissionId),
FSNS(XML_w, XML_ed), BookmarkToWord(permissionName));
FSNS(XML_w, XML_id), BookmarkToWord(OUString(permissionId)),
FSNS(XML_w, XML_ed), BookmarkToWord(OUString(permissionName)));
}
}
@@ -1825,20 +1828,20 @@ void DocxAttributeOutput::DoWritePermissionTagStart(const OUString & permission)
// - "permission-for-user:<permission-id>:<permission-user-name>"
// - "permission-for-group:<permission-id>:<permission-group-name>"
//
void DocxAttributeOutput::DoWritePermissionTagEnd(const OUString & permission)
void DocxAttributeOutput::DoWritePermissionTagEnd(std::u16string_view permission)
{
OUString permissionIdAndName;
std::u16string_view permissionIdAndName;
auto const ok = permission.startsWith("permission-for-group:", &permissionIdAndName) ||
permission.startsWith("permission-for-user:", &permissionIdAndName);
auto const ok = o3tl::starts_with(permission, u"permission-for-group:", &permissionIdAndName) ||
o3tl::starts_with(permission, u"permission-for-user:", &permissionIdAndName);
assert(ok); (void)ok;
const sal_Int32 separatorIndex = permissionIdAndName.indexOf(':');
assert(separatorIndex != -1);
const OUString permissionId = permissionIdAndName.copy(0, separatorIndex);
const std::size_t separatorIndex = permissionIdAndName.find(u':');
assert(separatorIndex != std::u16string_view::npos);
const std::u16string_view permissionId = permissionIdAndName.substr(0, separatorIndex);
m_pSerializer->singleElementNS(XML_w, XML_permEnd,
FSNS(XML_w, XML_id), BookmarkToWord(permissionId));
FSNS(XML_w, XML_id), BookmarkToWord(OUString(permissionId)));
}
/// Write the start permissions
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 7f880cc..e8b47fe 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -703,8 +703,8 @@ private:
void DoWriteBookmarkStartIfExist(sal_Int32 nRunPos);
void DoWriteBookmarkEndIfExist(sal_Int32 nRunPos);
void DoWritePermissionTagStart(const OUString & permission);
void DoWritePermissionTagEnd(const OUString & permission);
void DoWritePermissionTagStart(std::u16string_view permission);
void DoWritePermissionTagEnd(std::u16string_view permission);
void DoWritePermissionsStart();
void DoWritePermissionsEnd();
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index fae7931..46a0d36 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <string_view>
#include "rtfexport.hxx"
#include "rtfexportfilter.hxx"
@@ -51,6 +55,7 @@
#include <svtools/rtfkeywd.hxx>
#include <filter/msfilter/rtfutil.hxx>
#include <unotools/docinfohelper.hxx>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <rtl/tencinfo.h>
#include <sal/log.hxx>
@@ -1445,17 +1450,17 @@ private:
bool m_bOutOutlineOnly;
public:
SwRTFWriter(const OUString& rFilterName, const OUString& rBaseURL);
SwRTFWriter(std::u16string_view rFilterName, const OUString& rBaseURL);
ErrCode WriteStream() override;
};
}
SwRTFWriter::SwRTFWriter(const OUString& rFilterName, const OUString& rBaseURL)
SwRTFWriter::SwRTFWriter(std::u16string_view rFilterName, const OUString& rBaseURL)
{
SetBaseURL(rBaseURL);
// export outline nodes, only (send outline to clipboard/presentation)
m_bOutOutlineOnly = rFilterName.startsWith("O");
m_bOutOutlineOnly = o3tl::starts_with(rFilterName, u"O");
}
ErrCode SwRTFWriter::WriteStream()
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index b9cc9d2..19991a2 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -77,11 +77,13 @@
#include "ww8par.hxx"
#include "writerhelper.hxx"
#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <unotools/fltrcfg.hxx>
#include <xmloff/odffields.hxx>
#include <osl/diagnose.h>
#include <algorithm>
#include <string_view>
#define MAX_FIELDLEN 64000
@@ -98,9 +100,9 @@ using namespace nsSwDocInfoSubType;
namespace
{
// #120879# - helper method to identify a bookmark name to match the internal TOC bookmark naming convention
bool IsTOCBookmarkName(const OUString& rName)
bool IsTOCBookmarkName(std::u16string_view rName)
{
return rName.startsWith("_Toc") || rName.startsWith(OUString(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()+"_Toc"));
return o3tl::starts_with(rName, u"_Toc") || o3tl::starts_with(rName, OUString(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()+"_Toc"));
}
OUString EnsureTOCBookmarkName(const OUString& rName)
diff --git a/sw/source/ui/envelp/envfmt.cxx b/sw/source/ui/envelp/envfmt.cxx
index 5df8d7d..56c5f91 100644
--- a/sw/source/ui/envelp/envfmt.cxx
+++ b/sw/source/ui/envelp/envfmt.cxx
@@ -23,6 +23,7 @@
#include <editeng/tstpitem.hxx>
#include <editeng/lrspitem.hxx>
#include <svtools/unitconv.hxx>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <cmdid.h>
@@ -165,7 +166,7 @@ IMPL_LINK(SwEnvFormatPage, SendEditHdl, const OString&, rIdent, void)
Edit(rIdent, true);
}
void SwEnvFormatPage::Edit(const OString& rIdent, bool bSender)
void SwEnvFormatPage::Edit(std::string_view rIdent, bool bSender)
{
SwWrtShell* pSh = GetParentSwEnvDlg()->pSh;
OSL_ENSURE(pSh, "Shell missing");
@@ -174,7 +175,7 @@ void SwEnvFormatPage::Edit(const OString& rIdent, bool bSender)
bSender ? RES_POOLCOLL_SEND_ADDRESS : RES_POOLCOLL_ENVELOPE_ADDRESS));
OSL_ENSURE(pColl, "Text collection missing");
if (rIdent.startsWith("character"))
if (o3tl::starts_with(rIdent, "character"))
{
SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
@@ -193,7 +194,7 @@ void SwEnvFormatPage::Edit(const OString& rIdent, bool bSender)
pCollSet->Put(aOutputSet);
}
}
else if (rIdent.startsWith("paragraph"))
else if (o3tl::starts_with(rIdent, "paragraph"))
{
SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
diff --git a/sw/source/ui/envelp/envfmt.hxx b/sw/source/ui/envelp/envfmt.hxx
index 610f595..fb089f8 100644
--- a/sw/source/ui/envelp/envfmt.hxx
+++ b/sw/source/ui/envelp/envfmt.hxx
@@ -19,6 +19,10 @@
#ifndef INCLUDED_SW_SOURCE_UI_ENVELP_ENVFMT_HXX
#define INCLUDED_SW_SOURCE_UI_ENVELP_ENVFMT_HXX
#include <sal/config.h>
#include <string_view>
#include <vcl/weld.hxx>
#include <envlop.hxx>
@@ -50,7 +54,7 @@ class SwEnvFormatPage : public SfxTabPage
SfxItemSet* GetCollItemSet(SwTextFormatColl const* pColl, bool bSender);
void Edit(const OString& rIdent, bool bSender);
void Edit(std::string_view rIdent, bool bSender);
SwEnvDlg* GetParentSwEnvDlg() { return m_pDialog; }
diff --git a/sw/source/uibase/inc/unotools.hxx b/sw/source/uibase/inc/unotools.hxx
index 4e56f9f..3479625 100644
--- a/sw/source/uibase/inc/unotools.hxx
+++ b/sw/source/uibase/inc/unotools.hxx
@@ -19,6 +19,10 @@
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_UNOTOOLS_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_UNOTOOLS_HXX
#include <sal/config.h>
#include <string_view>
#include <vcl/idle.hxx>
#include <vcl/weld.hxx>
#include <vcl/customweld.hxx>
@@ -55,7 +59,7 @@ class SW_DLLPUBLIC SwOneExampleFrame final : public weld::CustomWidgetController
bool m_bIsInitialized;
DECL_DLLPRIVATE_LINK( TimeoutHdl, Timer*, void );
void PopupHdl(const OString& rId);
void PopupHdl(std::string_view rId);
SAL_DLLPRIVATE void CreateControl();
SAL_DLLPRIVATE void DisposeControl();
diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx
index 73edc7e..a006690 100644
--- a/sw/source/uibase/utlui/unotools.cxx
+++ b/sw/source/uibase/utlui/unotools.cxx
@@ -17,12 +17,18 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <string_view>
#include <swtypes.hxx>
#include <strings.hrc>
#include <unotools.hxx>
#include <unoprnms.hxx>
#include <i18nutil/unicode.hxx>
#include <o3tl/string_view.hxx>
#include <rtl/string.h>
#include <svtools/colorcfg.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/jobset.hxx>
@@ -488,12 +494,12 @@ bool SwOneExampleFrame::CreatePopup(const Point& rPt)
return true;
}
void SwOneExampleFrame::PopupHdl(const OString& rId)
void SwOneExampleFrame::PopupHdl(std::string_view rId)
{
OString sZoomValue;
if (rId.startsWith("zoom", &sZoomValue))
std::string_view sZoomValue;
if (o3tl::starts_with(rId, "zoom", &sZoomValue))
{
sal_Int16 nZoom = sZoomValue.toInt32();
sal_Int16 nZoom = rtl_str_toInt64_WithLength(sZoomValue.data(), 10, sZoomValue.length());
uno::Reference< view::XViewSettingsSupplier > xSettings(m_xController, uno::UNO_QUERY);
uno::Reference< beans::XPropertySet > xViewProps = xSettings->getViewSettings();