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>
This commit is contained in:
parent
ceaff89c97
commit
949f0fca3c
5 changed files with 44 additions and 43 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue