summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-09-27 09:38:00 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-09-28 08:42:54 +0200
commit949f0fca3cbe3d80c4aaebe6b7d7f4a8beb2fc13 (patch)
treee62c3ee58fad3e2a72f93764db2eccf52f65849b /framework
parentceaff89c973953e283aa881292206c593e5f9c7c (diff)
use more string_view in framework
Change-Id: I9a79eef6d41696f1de7569f40d6eaf1d85ff77bf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140638 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'framework')
-rw-r--r--framework/inc/helper/mischelper.hxx26
-rw-r--r--framework/inc/jobs/jobdata.hxx2
-rw-r--r--framework/source/jobs/jobdata.cxx4
-rw-r--r--framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx32
-rw-r--r--framework/source/uiconfiguration/uiconfigurationmanager.cxx23
5 files changed, 44 insertions, 43 deletions
diff --git a/framework/inc/helper/mischelper.hxx b/framework/inc/helper/mischelper.hxx
index 7e028d18e446..04284e8ff866 100644
--- a/framework/inc/helper/mischelper.hxx
+++ b/framework/inc/helper/mischelper.hxx
@@ -31,6 +31,7 @@
#include <cppuhelper/weakref.hxx>
#include <i18nlangtag/lang.h>
+#include <o3tl/string_view.hxx>
#include <svl/languageoptions.hxx>
#include <rtl/ustring.hxx>
@@ -82,24 +83,25 @@ inline bool IsScriptTypeMatchingToLanguage( SvtScriptType nScriptType, LanguageT
return bool(nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
}
-inline void RetrieveTypeNameFromResourceURL( const OUString& aResourceURL, OUString& aType, OUString& aName )
+inline void RetrieveTypeNameFromResourceURL( std::u16string_view aResourceURL, OUString& aType, OUString& aName )
{
- static const char RESOURCEURL_PREFIX[] = "private:resource/";
- static const sal_Int32 RESOURCEURL_PREFIX_SIZE = strlen(RESOURCEURL_PREFIX);
+ static constexpr std::u16string_view RESOURCEURL_PREFIX = u"private:resource/";
- if (aResourceURL.startsWith( RESOURCEURL_PREFIX ))
+ if (o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ))
{
- sal_Int32 nIdx{ RESOURCEURL_PREFIX_SIZE };
- while (nIdx<aResourceURL.getLength() && aResourceURL[nIdx]=='/') ++nIdx;
- if (nIdx>=aResourceURL.getLength())
+ size_t nIdx = RESOURCEURL_PREFIX.size();
+ while (nIdx < aResourceURL.size() && aResourceURL[nIdx]=='/')
+ ++nIdx;
+ if (nIdx >= aResourceURL.size())
return;
- aType = aResourceURL.getToken(0, '/', nIdx);
- if (nIdx<0)
+ aType = o3tl::getToken(aResourceURL, u'/', nIdx);
+ if (nIdx == std::u16string_view::npos)
return;
- while (nIdx<aResourceURL.getLength() && aResourceURL[nIdx]=='/') ++nIdx;
- if (nIdx>=aResourceURL.getLength())
+ while (nIdx < aResourceURL.size() && aResourceURL[nIdx]=='/')
+ ++nIdx;
+ if (nIdx >= aResourceURL.size())
return;
- aName = aResourceURL.getToken(0, '/', nIdx);
+ aName = o3tl::getToken(aResourceURL, u'/', nIdx);
}
}
diff --git a/framework/inc/jobs/jobdata.hxx b/framework/inc/jobs/jobdata.hxx
index fd23a665e2d8..050bce6a84a9 100644
--- a/framework/inc/jobs/jobdata.hxx
+++ b/framework/inc/jobs/jobdata.hxx
@@ -180,7 +180,7 @@ class JobData final
std::vector< css::beans::NamedValue > getJobConfig () const;
bool hasConfig () const;
- bool hasCorrectContext ( const OUString& rModuleIdent ) const;
+ bool hasCorrectContext ( std::u16string_view rModuleIdent ) const;
void setEnvironment ( EEnvironment eEnvironment );
void setAlias ( const OUString& sAlias );
diff --git a/framework/source/jobs/jobdata.cxx b/framework/source/jobs/jobdata.cxx
index 863bc8c4b4ca..ded3570e8dbf 100644
--- a/framework/source/jobs/jobdata.cxx
+++ b/framework/source/jobs/jobdata.cxx
@@ -448,10 +448,10 @@ void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XC
}
}
-bool JobData::hasCorrectContext(const OUString& rModuleIdent) const
+bool JobData::hasCorrectContext(std::u16string_view rModuleIdent) const
{
sal_Int32 nContextLen = m_sContext.getLength();
- sal_Int32 nModuleIdLen = rModuleIdent.getLength();
+ sal_Int32 nModuleIdLen = rModuleIdent.size();
if ( nContextLen == 0 )
return true;
diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
index ded9d777080c..235190ac9d0d 100644
--- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
+++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
@@ -236,16 +236,15 @@ std::u16string_view UIELEMENTTYPENAMES[] =
u"" UIELEMENTTYPE_TOOLPANEL_NAME
};
-const char RESOURCEURL_PREFIX[] = "private:resource/";
-const sal_Int32 RESOURCEURL_PREFIX_SIZE = strlen(RESOURCEURL_PREFIX);
+constexpr std::u16string_view RESOURCEURL_PREFIX = u"private:resource/";
-sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
+sal_Int16 RetrieveTypeFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- std::u16string_view aTmpStr = aResourceURL.subView( RESOURCEURL_PREFIX_SIZE );
+ std::u16string_view aTmpStr = aResourceURL.substr( RESOURCEURL_PREFIX.size() );
size_t nIndex = aTmpStr.find( '/' );
if (( nIndex > 0 ) && ( aTmpStr.size() > nIndex ))
{
@@ -261,14 +260,15 @@ sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
return ui::UIElementType::UNKNOWN;
}
-OUString RetrieveNameFromResourceURL( const OUString& aResourceURL )
+OUString RetrieveNameFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' );
- if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength()))
- return aResourceURL.copy( nIndex+1 );
+ size_t nIndex = aResourceURL.rfind( '/' );
+
+ if ( nIndex > 0 && nIndex != std::u16string_view::npos && (( nIndex+1 ) < aResourceURL.size()) )
+ return OUString(aResourceURL.substr( nIndex+1 ));
}
return OUString();
@@ -285,8 +285,8 @@ void ModuleUIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIEleme
OUString aCustomUrlPrefix( "custom_" );
for (auto const& userElement : rUserElements)
{
- sal_Int32 nIndex = userElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
- if ( nIndex > RESOURCEURL_PREFIX_SIZE )
+ sal_Int32 nIndex = userElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX.size() );
+ if ( nIndex > static_cast<sal_Int32>(RESOURCEURL_PREFIX.size()) )
{
// Performance: Retrieve user interface name only for custom user interface elements.
// It's only used by them!
@@ -321,8 +321,8 @@ void ModuleUIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIEleme
UIElementInfoHashMap::const_iterator pIterInfo = aUIElementInfoCollection.find( defaultElement.second.aResourceURL );
if ( pIterInfo == aUIElementInfoCollection.end() )
{
- sal_Int32 nIndex = defaultElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
- if ( nIndex > RESOURCEURL_PREFIX_SIZE )
+ sal_Int32 nIndex = defaultElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX.size() );
+ if ( nIndex > static_cast<sal_Int32>(RESOURCEURL_PREFIX.size()) )
{
// Performance: Retrieve user interface name only for custom user interface elements.
// It's only used by them!
diff --git a/framework/source/uiconfiguration/uiconfigurationmanager.cxx b/framework/source/uiconfiguration/uiconfigurationmanager.cxx
index 42f6269bf3ce..eeb1418da1c3 100644
--- a/framework/source/uiconfiguration/uiconfigurationmanager.cxx
+++ b/framework/source/uiconfiguration/uiconfigurationmanager.cxx
@@ -213,16 +213,15 @@ std::u16string_view UIELEMENTTYPENAMES[] =
u"" UIELEMENTTYPE_TOOLPANEL_NAME
};
-const char RESOURCEURL_PREFIX[] = "private:resource/";
-const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17;
+constexpr std::u16string_view RESOURCEURL_PREFIX = u"private:resource/";
-sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
+sal_Int16 RetrieveTypeFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- std::u16string_view aTmpStr = aResourceURL.subView( RESOURCEURL_PREFIX_SIZE );
+ std::u16string_view aTmpStr = aResourceURL.substr( RESOURCEURL_PREFIX.size() );
size_t nIndex = aTmpStr.find( '/' );
if (( nIndex > 0 ) && ( aTmpStr.size() > nIndex ))
{
@@ -238,14 +237,14 @@ sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
return UIElementType::UNKNOWN;
}
-OUString RetrieveNameFromResourceURL( const OUString& aResourceURL )
+OUString RetrieveNameFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' );
- if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength()))
- return aResourceURL.copy( nIndex+1 );
+ size_t nIndex = aResourceURL.rfind( '/' );
+ if ( (nIndex > 0) && (nIndex != std::u16string_view::npos) && (( nIndex+1 ) < aResourceURL.size()) )
+ return OUString(aResourceURL.substr( nIndex+1 ));
}
return OUString();