diff options
author | Noel Grandin <noel@peralex.com> | 2013-10-25 16:43:20 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-10-31 08:34:21 +0200 |
commit | e2451bd729d0f1d795a5b689deba65bc4e9d92c6 (patch) | |
tree | 4f2356107b0e58db7afda0fc324b9eac49ff68c0 /scripting | |
parent | 460b52838fdad0352188bdd877b69cbb5f17ca63 (diff) |
Convert indexOf->startsWith and lastIndexOf->endsWith
This is both an optimisation and a cleanup.
This converts code like
aStr.indexOf("XX") == 0
to
aStr.startsWith("XX")
and converts code like
aStr.lastIndexOf("XXX") == aStr.getLength() - 3
to
aStr.endsWith("XXX")
Note that in general
aStr.lastIndexOf("X") == aStr.getLength() - 1
converts to
aStr.isEmpty() || aStr.endsWith("X")
so I used the surrounding context to determine if aStr could be empty
when modifying the code.
Change-Id: I22cb8ca7c2a4d0288b001f72adb27fd63af87669
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/source/basprov/basprov.cxx | 2 | ||||
-rw-r--r-- | scripting/source/provider/ActiveMSPList.cxx | 2 | ||||
-rw-r--r-- | scripting/source/provider/MasterScriptProvider.cxx | 4 | ||||
-rw-r--r-- | scripting/source/provider/ProviderCache.cxx | 2 | ||||
-rw-r--r-- | scripting/source/provider/URIHelper.cxx | 2 | ||||
-rw-r--r-- | scripting/source/stringresource/stringresource.cxx | 2 |
6 files changed, 7 insertions, 7 deletions
diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx index cc0f4f9ce230..fc482c45f55e 100644 --- a/scripting/source/basprov/basprov.cxx +++ b/scripting/source/basprov/basprov.cxx @@ -243,7 +243,7 @@ namespace basprov } OUString sDoc = "vnd.sun.star.tdoc"; - if ( m_sScriptingContext.indexOf( sDoc ) == 0 ) + if ( m_sScriptingContext.startsWith( sDoc ) ) { xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext ); // TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF diff --git a/scripting/source/provider/ActiveMSPList.cxx b/scripting/source/provider/ActiveMSPList.cxx index 5b3b71e9bed3..98d18a85500e 100644 --- a/scripting/source/provider/ActiveMSPList.cxx +++ b/scripting/source/provider/ActiveMSPList.cxx @@ -152,7 +152,7 @@ Reference< provider::XScriptProvider > Reference< provider::XScriptProvider > msp; try { - if ( context.indexOf( "vnd.sun.star.tdoc" ) == 0 ) + if ( context.startsWith( "vnd.sun.star.tdoc" ) ) { Reference< frame::XModel > xModel( MiscUtils::tDocUrlToModel( context ) ); diff --git a/scripting/source/provider/MasterScriptProvider.cxx b/scripting/source/provider/MasterScriptProvider.cxx index 19e1134a66af..f93aca5e3387 100644 --- a/scripting/source/provider/MasterScriptProvider.cxx +++ b/scripting/source/provider/MasterScriptProvider.cxx @@ -129,7 +129,7 @@ throw ( Exception, RuntimeException ) if ( args[ 0 ] >>= m_sCtxString ) { invokeArgs[ 0 ] = args[ 0 ]; - if ( m_sCtxString.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.tdoc" ) ) == 0 ) + if ( m_sCtxString.startsWith( "vnd.sun.star.tdoc" ) ) { m_xModel = MiscUtils::tDocUrlToModel( m_sCtxString ); } @@ -411,7 +411,7 @@ MasterScriptProvider::getName() if ( !isPkgProvider() ) { OUString sCtx = getContextString(); - if ( sCtx.indexOf( "vnd.sun.star.tdoc" ) == 0 ) + if ( sCtx.startsWith( "vnd.sun.star.tdoc" ) ) { Reference< frame::XModel > xModel = m_xModel; if ( !xModel.is() ) diff --git a/scripting/source/provider/ProviderCache.cxx b/scripting/source/provider/ProviderCache.cxx index ec5209cda795..71bba4c84e29 100644 --- a/scripting/source/provider/ProviderCache.cxx +++ b/scripting/source/provider/ProviderCache.cxx @@ -159,7 +159,7 @@ ProviderCache::populateCache() throw ( RuntimeException ) for ( sal_Int32 index = 0; index < serviceNames.getLength(); index++ ) { - if ( serviceNames[ index ].indexOf( searchString ) == 0 && !isInBlackList( serviceNames[ index ] ) ) + if ( serviceNames[ index ].startsWith( searchString ) && !isInBlackList( serviceNames[ index ] ) ) { serviceName = serviceNames[ index ]; ProviderDetails details; diff --git a/scripting/source/provider/URIHelper.cxx b/scripting/source/provider/URIHelper.cxx index 6a6d0b7fc48c..0763901957c3 100644 --- a/scripting/source/provider/URIHelper.cxx +++ b/scripting/source/provider/URIHelper.cxx @@ -141,7 +141,7 @@ ScriptingFrameworkURIHelper::initBaseURI() test = OUString("uno_packages"); uri = OUString(SHARE_UNO_PACKAGES_URI); } - else if (m_sLocation.indexOf(TDOC_SCHEME) == 0) + else if (m_sLocation.startsWith(TDOC_SCHEME)) { m_sBaseURI = m_sLocation.concat( SCRIPTS_PART ); m_sLocation = OUString(DOCUMENT ); diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx index 196998a0bcfb..cc0c611e2c2d 100644 --- a/scripting/source/stringresource/stringresource.cxx +++ b/scripting/source/stringresource/stringresource.cxx @@ -1671,7 +1671,7 @@ bool checkNamingSceme( const OUString& aName, const OUString& aNameBase, // Name has to start with NameBase followed // by a '_' and at least one more character - if( aName.indexOf( aNameBase ) == 0 && nNameBaseLen < nNameLen-1 && + if( aName.startsWith( aNameBase ) && nNameBaseLen < nNameLen-1 && aName.getStr()[nNameBaseLen] == '_' ) { bSuccess = true; |