[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 22 19:14:55 UTC 2021


 include/sfx2/classificationhelper.hxx     |   26 +++++++++++++++++---------
 include/sfx2/sfxhelp.hxx                  |    6 +++++-
 sfx2/source/appl/sfxhelp.cxx              |   13 ++++++++-----
 sfx2/source/doc/graphhelp.cxx             |   13 +++++++------
 sfx2/source/doc/graphhelp.hxx             |    3 ++-
 sfx2/source/view/classificationhelper.cxx |    7 ++++---
 6 files changed, 43 insertions(+), 25 deletions(-)

New commits:
commit ea29e9936a3e628f95ca4ae1d5816adfce87318f
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Sep 22 20:01:38 2021 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Sep 22 21:14:15 2021 +0200

    Extend loplugin:stringviewparam to starts/endsWith: sfx2
    
    Change-Id: Icac2c5877059208ed348aa824071803e415f374f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122482
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index ca9ffc386b5d..5a4fa6b1eeab 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -11,8 +11,10 @@
 #define INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX
 
 #include <memory>
+#include <string_view>
 #include <vector>
 
+#include <o3tl/string_view.hxx>
 #include <rtl/ustring.hxx>
 #include <sfx2/dllapi.h>
 #include <sfx2/infobar.hxx>
@@ -100,7 +102,7 @@ public:
     std::vector<OUString> const& GetIntellectualPropertyPartNumbers() const;
 
     /// Does a best-effort conversion of rType to SfxClassificationPolicyType.
-    static SfxClassificationPolicyType stringToPolicyType(const OUString& rType);
+    static SfxClassificationPolicyType stringToPolicyType(std::u16string_view rType);
     /// Returns the string representation of a SfxClassificationPolicyType element.
     static const OUString& policyTypeToString(SfxClassificationPolicyType eType);
 
@@ -154,16 +156,19 @@ public:
         return makeTextKey() + ":n" + OUString::number(m_nTextNumber++);
     }
 
-    bool isMarkingTextKey(OUString const& aKey) const { return aKey.startsWith(makeTextKey()); }
+    bool isMarkingTextKey(std::u16string_view aKey) const
+    {
+        return o3tl::starts_with(aKey, makeTextKey());
+    }
 
     OUString makeCategoryNameKey() const
     {
         return getPolicyKey() + "BusinessAuthorizationCategory:Name";
     }
 
-    bool isCategoryNameKey(OUString const& aKey) const
+    bool isCategoryNameKey(std::u16string_view aKey) const
     {
-        return aKey.startsWith(makeCategoryNameKey());
+        return o3tl::starts_with(aKey, makeCategoryNameKey());
     }
 
     OUString makeCategoryIdentifierKey() const
@@ -171,9 +176,9 @@ public:
         return getPolicyKey() + "BusinessAuthorizationCategory:Identifier";
     }
 
-    bool isCategoryIdentifierKey(OUString const& aKey) const
+    bool isCategoryIdentifierKey(std::u16string_view aKey) const
     {
-        return aKey.startsWith(makeCategoryIdentifierKey());
+        return o3tl::starts_with(aKey, makeCategoryIdentifierKey());
     }
 
     OUString makeMarkingKey() const { return getPolicyKey() + "Custom:Marking"; }
@@ -183,7 +188,10 @@ public:
         return makeMarkingKey() + ":n" + OUString::number(m_nMarkingNumber++);
     }
 
-    bool isMarkingKey(OUString const& aKey) const { return aKey.startsWith(makeMarkingKey()); }
+    bool isMarkingKey(std::u16string_view aKey) const
+    {
+        return o3tl::starts_with(aKey, makeMarkingKey());
+    }
 
     OUString makeIntellectualPropertyPartKey() const
     {
@@ -195,9 +203,9 @@ public:
         return makeIntellectualPropertyPartKey() + ":n" + OUString::number(m_nIPPartNumber++);
     }
 
-    bool isIntellectualPropertyPartKey(OUString const& aKey) const
+    bool isIntellectualPropertyPartKey(std::u16string_view aKey) const
     {
-        return aKey.startsWith(makeIntellectualPropertyPartKey());
+        return o3tl::starts_with(aKey, makeIntellectualPropertyPartKey());
     }
 
     OUString makeFullTextualRepresentationKey() const
diff --git a/include/sfx2/sfxhelp.hxx b/include/sfx2/sfxhelp.hxx
index b0f3ff00657f..a8f725d067a6 100644
--- a/include/sfx2/sfxhelp.hxx
+++ b/include/sfx2/sfxhelp.hxx
@@ -19,6 +19,10 @@
 #ifndef INCLUDED_SFX2_SFXHELP_HXX
 #define INCLUDED_SFX2_SFXHELP_HXX
 
+#include <sal/config.h>
+
+#include <string_view>
+
 #include <rtl/ustring.hxx>
 #include <sal/config.h>
 #include <sfx2/dllapi.h>
@@ -34,7 +38,7 @@ private:
     SAL_DLLPRIVATE static bool Start_Impl(const OUString& rURL, weld::Widget* pWidget, const OUString& rKeyword);
     SAL_DLLPRIVATE virtual void SearchKeyword( const OUString& rKeyWord ) override;
     SAL_DLLPRIVATE virtual bool Start(const OUString& rURL, weld::Widget* pWidget = nullptr) override;
-    SAL_DLLPRIVATE static OUString GetHelpModuleName_Impl(const OUString &rHelpId);
+    SAL_DLLPRIVATE static OUString GetHelpModuleName_Impl(std::u16string_view rHelpId);
     SAL_DLLPRIVATE static OUString CreateHelpURL_Impl( const OUString& aCommandURL, const OUString& rModuleName );
 
     SAL_DLLPRIVATE static bool Start_Impl( const OUString& rURL, const vcl::Window* pWindow );
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index b9c7f4b6d47d..5f0b3f7f60ff 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -23,6 +23,7 @@
 #include <string_view>
 #include <algorithm>
 #include <cassert>
+#include <cstddef>
 #ifdef MACOSX
 #include <premac.h>
 #include <Foundation/NSString.h>
@@ -50,6 +51,7 @@
 #include <unotools/pathoptions.hxx>
 #include <rtl/byteseq.hxx>
 #include <rtl/ustring.hxx>
+#include <o3tl/string_view.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <osl/process.h>
 #include <osl/file.hxx>
@@ -443,7 +445,7 @@ namespace
     }
 }
 
-OUString SfxHelp::GetHelpModuleName_Impl(const OUString& rHelpID)
+OUString SfxHelp::GetHelpModuleName_Impl(std::u16string_view rHelpID)
 {
     OUString aFactoryShortName;
 
@@ -452,11 +454,12 @@ OUString SfxHelp::GetHelpModuleName_Impl(const OUString& rHelpID)
     //otherwise unknown. Cosmetic, same help is shown in any case because its
     //in the shared section, but title bar would state "Writer" when context is
     //expected to be "Calc"
-    OUString sRemainder;
-    if (rHelpID.startsWith("modules/", &sRemainder))
+    std::u16string_view sRemainder;
+    if (o3tl::starts_with(rHelpID, u"modules/", &sRemainder))
     {
-        sal_Int32 nEndModule = sRemainder.indexOf('/');
-        aFactoryShortName = nEndModule != -1 ? sRemainder.copy(0, nEndModule) : sRemainder;
+        std::size_t nEndModule = sRemainder.find(u'/');
+        aFactoryShortName = nEndModule != std::u16string_view::npos
+            ? sRemainder.substr(0, nEndModule) : sRemainder;
     }
 
     if (aFactoryShortName.isEmpty())
diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx
index cc1299c01b1c..6371d10112e4 100644
--- a/sfx2/source/doc/graphhelp.cxx
+++ b/sfx2/source/doc/graphhelp.cxx
@@ -39,6 +39,7 @@
 #include <unotools/ucbstreamhelper.hxx>
 #include <comphelper/processfactory.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/string_view.hxx>
 
 #include "graphhelp.hxx"
 #include <bitmaps.hlst>
@@ -235,27 +236,27 @@ bool GraphicHelper::getThumbnailReplacement_Impl(std::u16string_view rResID, con
 }
 
 // static
-OUString GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl( const OUString& aFactoryShortName )
+OUString GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl( std::u16string_view aFactoryShortName )
 {
     OUString sResult;
 
-    if ( aFactoryShortName == "scalc" )
+    if ( aFactoryShortName == u"scalc" )
     {
         sResult = BMP_128X128_CALC_DOC;
     }
-    else if ( aFactoryShortName == "sdraw" )
+    else if ( aFactoryShortName == u"sdraw" )
     {
         sResult = BMP_128X128_DRAW_DOC;
     }
-    else if ( aFactoryShortName == "simpress" )
+    else if ( aFactoryShortName == u"simpress" )
     {
         sResult = BMP_128X128_IMPRESS_DOC;
     }
-    else if ( aFactoryShortName == "smath" )
+    else if ( aFactoryShortName == u"smath" )
     {
         sResult = BMP_128X128_MATH_DOC;
     }
-    else if ( aFactoryShortName == "swriter" || aFactoryShortName.startsWith("swriter/") )
+    else if ( aFactoryShortName == u"swriter" || o3tl::starts_with(aFactoryShortName, u"swriter/") )
     {
         sResult = BMP_128X128_WRITER_DOC;
     }
diff --git a/sfx2/source/doc/graphhelp.hxx b/sfx2/source/doc/graphhelp.hxx
index bfaf3e223d90..e0129c917b1e 100644
--- a/sfx2/source/doc/graphhelp.hxx
+++ b/sfx2/source/doc/graphhelp.hxx
@@ -57,7 +57,8 @@ public:
             GDIMetaFile const * pMetaFile,
             const css::uno::Reference< css::io::XStream >& xStream );
 
-    static OUString getThumbnailReplacementIDByFactoryName_Impl(const OUString& aFactoryShortName);
+    static OUString getThumbnailReplacementIDByFactoryName_Impl(
+        std::u16string_view aFactoryShortName);
 
     static bool getThumbnailReplacement_Impl(
             std::u16string_view rResID,
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index ef864760381e..629ceeaef560 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -41,6 +41,7 @@
 #include <vcl/weld.hxx>
 #include <svl/fstathelper.hxx>
 
+#include <o3tl/string_view.hxx>
 #include <officecfg/Office/Common.hxx>
 
 using namespace com::sun::star;
@@ -888,11 +889,11 @@ void SfxClassificationHelper::UpdateInfobar(SfxViewFrame& rViewFrame)
     }
 }
 
-SfxClassificationPolicyType SfxClassificationHelper::stringToPolicyType(const OUString& rType)
+SfxClassificationPolicyType SfxClassificationHelper::stringToPolicyType(std::u16string_view rType)
 {
-    if (rType.startsWith(PROP_PREFIX_EXPORTCONTROL()))
+    if (o3tl::starts_with(rType, PROP_PREFIX_EXPORTCONTROL()))
         return SfxClassificationPolicyType::ExportControl;
-    else if (rType.startsWith(PROP_PREFIX_NATIONALSECURITY()))
+    else if (o3tl::starts_with(rType, PROP_PREFIX_NATIONALSECURITY()))
         return SfxClassificationPolicyType::NationalSecurity;
     else
         return SfxClassificationPolicyType::IntellectualProperty;


More information about the Libreoffice-commits mailing list