From e2451bd729d0f1d795a5b689deba65bc4e9d92c6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 25 Oct 2013 16:43:20 +0200 Subject: 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 --- framework/source/accelerators/storageholder.cxx | 2 +- framework/source/classes/menumanager.cxx | 4 ++-- framework/source/layoutmanager/helpers.cxx | 4 ++-- framework/source/services/autorecovery.cxx | 2 +- framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx | 4 ++-- framework/source/uiconfiguration/uiconfigurationmanager.cxx | 6 +++--- framework/source/uielement/macrosmenucontroller.cxx | 2 +- framework/source/uielement/menubarmanager.cxx | 2 +- framework/source/uielement/newmenucontroller.cxx | 2 +- framework/source/uielement/recentfilesmenucontroller.cxx | 4 ++-- framework/source/uielement/toolbarsmenucontroller.cxx | 6 +++--- framework/source/uielement/uicommanddescription.cxx | 4 ++-- framework/source/uifactory/windowcontentfactorymanager.cxx | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) (limited to 'framework') diff --git a/framework/source/accelerators/storageholder.cxx b/framework/source/accelerators/storageholder.cxx index efc0722d7274..50a302890161 100644 --- a/framework/source/accelerators/storageholder.cxx +++ b/framework/source/accelerators/storageholder.cxx @@ -554,7 +554,7 @@ OUString StorageHolder::impl_st_normPath(const OUString& sPath) OUString sNormedPath = sPath; // "/bla" => "bla" && "/" => "" (!) - if (sNormedPath.indexOf(PATH_SEPARATOR) == 0) + if (sNormedPath.startsWith(PATH_SEPARATOR)) sNormedPath += sNormedPath.copy(1); // "/" => "" || "" => "" ? diff --git a/framework/source/classes/menumanager.cxx b/framework/source/classes/menumanager.cxx index 4ec18d46d36e..85d6798c3ef9 100644 --- a/framework/source/classes/menumanager.cxx +++ b/framework/source/classes/menumanager.cxx @@ -143,8 +143,8 @@ MenuManager::MenuManager( if ( pPopupMenu ) { AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren); - if (! (( aItemCommand.getLength() > nAddonsURLPrefixLength ) && - ( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) ) + if (! ( aItemCommand.getLength() > nAddonsURLPrefixLength && + aItemCommand.startsWith( ADDONSPOPUPMENU_URL_PREFIX ) ) ) { // Create addon popup menu if there exist elements and this is the tools popup menu diff --git a/framework/source/layoutmanager/helpers.cxx b/framework/source/layoutmanager/helpers.cxx index 1ad507d0464c..5cc82710aed0 100644 --- a/framework/source/layoutmanager/helpers.cxx +++ b/framework/source/layoutmanager/helpers.cxx @@ -199,7 +199,7 @@ OUString getElementTypeFromResourceURL( const OUString& aResourceURL ) OUString aType; OUString aUIResourceURL( UIRESOURCE_URL ); - if ( aResourceURL.indexOf( aUIResourceURL ) == 0 ) + if ( aResourceURL.startsWith( aUIResourceURL ) ) { sal_Int32 nIndex = 0; OUString aPathPart = aResourceURL.copy( aUIResourceURL.getLength() ); @@ -214,7 +214,7 @@ OUString getElementTypeFromResourceURL( const OUString& aResourceURL ) void parseResourceURL( const OUString& aResourceURL, OUString& aElementType, OUString& aElementName ) { OUString aUIResourceURL( UIRESOURCE_URL ); - if ( aResourceURL.indexOf( aUIResourceURL ) == 0 ) + if ( aResourceURL.startsWith( aUIResourceURL ) ) { sal_Int32 nIndex = 0; OUString aPathPart = aResourceURL.copy( aUIResourceURL.getLength() ); diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx index 3e40ef9edb63..78b7df626479 100644 --- a/framework/source/services/autorecovery.cxx +++ b/framework/source/services/autorecovery.cxx @@ -1060,7 +1060,7 @@ void AutoRecovery::implts_readConfig() implts_specifyAppModuleAndFactory(aInfo); implts_specifyDefaultFilterAndExtension(aInfo); - if (pItems[i].indexOf(sRECOVERY_ITEM_BASE_IDENTIFIER)==0) + if (pItems[i].startsWith(sRECOVERY_ITEM_BASE_IDENTIFIER)) { OUString sID = pItems[i].copy(sRECOVERY_ITEM_BASE_IDENTIFIER.getLength()); aInfo.ID = sID.toInt32(); diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx index 215f4454d508..7b2d0fa39591 100644 --- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx @@ -90,7 +90,7 @@ static const char RESOURCEURL_CUSTOM_ELEMENT[] = "custom_"; static sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL ) { - if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) && + if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) && ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) { OUString aTmpStr = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ); @@ -111,7 +111,7 @@ static sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL ) static OUString RetrieveNameFromResourceURL( const OUString& aResourceURL ) { - if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) && + if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) && ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) { sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' ); diff --git a/framework/source/uiconfiguration/uiconfigurationmanager.cxx b/framework/source/uiconfiguration/uiconfigurationmanager.cxx index 799a3f3ab207..3b264d9434a2 100644 --- a/framework/source/uiconfiguration/uiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/uiconfigurationmanager.cxx @@ -90,11 +90,11 @@ static const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17; static sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL ) { - if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) && + if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) && ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) { OUString aTmpStr = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ); - sal_Int32 nIndex = aTmpStr.indexOf( '/' ); + sal_Int32 nIndex = aTmpStr.indexOf( '/' ); if (( nIndex > 0 ) && ( aTmpStr.getLength() > nIndex )) { OUString aTypeStr( aTmpStr.copy( 0, nIndex )); @@ -111,7 +111,7 @@ static sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL ) static OUString RetrieveNameFromResourceURL( const OUString& aResourceURL ) { - if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) && + if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) && ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) { sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' ); diff --git a/framework/source/uielement/macrosmenucontroller.cxx b/framework/source/uielement/macrosmenucontroller.cxx index 9db444cf8048..18c5460c3b65 100644 --- a/framework/source/uielement/macrosmenucontroller.cxx +++ b/framework/source/uielement/macrosmenucontroller.cxx @@ -186,7 +186,7 @@ void MacrosMenuController::addScriptItems( PopupMenu* pPopupMenu, sal_uInt16 sta { for ( sal_Int32 index = 0; index < serviceNames.getLength(); index++ ) { - if ( serviceNames[ index ].indexOf( providerKey ) == 0 ) + if ( serviceNames[ index ].startsWith( providerKey ) ) { OUString serviceName = serviceNames[ index ]; OUString aCommand = aCmdBase; diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index 47298594ef75..c65abbbeb7a3 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -1297,7 +1297,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF lcl_CheckForChildren(pMenu, nItemId); } else if (( aItemCommand.getLength() > nAddonsURLPrefixLength ) && - ( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) + ( aItemCommand.startsWith( ADDONSPOPUPMENU_URL_PREFIX ) )) { // A special addon popup menu, must be created with a different ctor MenuBarManager* pSubMenuManager = new MenuBarManager( m_xContext, m_xFrame, m_xURLTransformer,(AddonPopupMenu *)pPopup, bDeleteChildren, bDeleteChildren ); diff --git a/framework/source/uielement/newmenucontroller.cxx b/framework/source/uielement/newmenucontroller.cxx index 8b5837721207..69653823a928 100644 --- a/framework/source/uielement/newmenucontroller.cxx +++ b/framework/source/uielement/newmenucontroller.cxx @@ -133,7 +133,7 @@ void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR ) { aCommand = pPopupMenu->GetItemCommand( nId ); - if ( aCommand.indexOf( m_aEmptyDocURL ) == 0 ) + if ( aCommand.startsWith( m_aEmptyDocURL ) ) { pPopupMenu->SetAccelKey( nId, rKeyCode ); bFound = sal_True; diff --git a/framework/source/uielement/recentfilesmenucontroller.cxx b/framework/source/uielement/recentfilesmenucontroller.cxx index 7b01a110db80..43c0350ded67 100644 --- a/framework/source/uielement/recentfilesmenucontroller.cxx +++ b/framework/source/uielement/recentfilesmenucontroller.cxx @@ -312,7 +312,7 @@ throw( RuntimeException ) throwIfDisposed(); - if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 ) + if ( aURL.Complete.startsWith( m_aBaseURL ) ) return Reference< XDispatch >( static_cast< OWeakObject* >( this ), UNO_QUERY ); else return Reference< XDispatch >(); @@ -328,7 +328,7 @@ throw( RuntimeException ) throwIfDisposed(); - if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 ) + if ( aURL.Complete.startsWith( m_aBaseURL ) ) { // Parse URL to retrieve entry argument and its value sal_Int32 nQueryPart = aURL.Complete.indexOf( '?', m_aBaseURL.getLength() ); diff --git a/framework/source/uielement/toolbarsmenucontroller.cxx b/framework/source/uielement/toolbarsmenucontroller.cxx index 87185d6e79b3..d73f3cec6504 100644 --- a/framework/source/uielement/toolbarsmenucontroller.cxx +++ b/framework/source/uielement/toolbarsmenucontroller.cxx @@ -164,7 +164,7 @@ void ToolbarsMenuController::addCommand( rPopupMenu->insertItem( nItemId, aLabel, 0, nItemId ); rPopupMenu->setCommand( nItemId, rCommandURL ); - bool bInternal = ( rCommandURL.indexOf( STATIC_INTERNAL_CMD_PART ) == 0); + bool bInternal = rCommandURL.startsWith( STATIC_INTERNAL_CMD_PART ); if ( !bInternal ) { if ( !getDispatchFromCommandURL( rCommandURL ).is() ) @@ -616,7 +616,7 @@ void SAL_CALL ToolbarsMenuController::itemSelected( const css::awt::MenuEvent& r PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); OUString aCmd( pVCLPopupMenu->GetItemCommand( rEvent.MenuId )); - if ( aCmd.indexOf( STATIC_INTERNAL_CMD_PART ) == 0 ) + if ( aCmd.startsWith( STATIC_INTERNAL_CMD_PART ) ) { // Command to restore the visibility of all context sensitive toolbars Reference< XNameReplace > xNameReplace( xPersistentWindowState, UNO_QUERY ); @@ -765,7 +765,7 @@ void SAL_CALL ToolbarsMenuController::itemActivated( const css::awt::MenuEvent& const sal_uInt32 nCount = aCmdVector.size(); for ( sal_uInt32 i = 0; i < nCount; i++ ) { - bool bInternal = ( aCmdVector[i].indexOf( STATIC_INTERNAL_CMD_PART ) == 0); + bool bInternal = aCmdVector[i].startsWith( STATIC_INTERNAL_CMD_PART ); if ( !bInternal ) { diff --git a/framework/source/uielement/uicommanddescription.cxx b/framework/source/uielement/uicommanddescription.cxx index 42cd3890e58a..d930bc58cfd6 100644 --- a/framework/source/uielement/uicommanddescription.cxx +++ b/framework/source/uielement/uicommanddescription.cxx @@ -240,7 +240,7 @@ Any SAL_CALL ConfigurationAccess_UICommand::getByNameImpl( const OUString& rComm fillCache(); } - if ( rCommandURL.indexOf( m_aPrivateResourceURL ) == 0 ) + if ( rCommandURL.startsWith( m_aPrivateResourceURL ) ) { // special keys to retrieve information about a set of commands // SAFE @@ -711,7 +711,7 @@ throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::la } } } - else if ( !m_aPrivateResourceURL.isEmpty() && aName.indexOf( m_aPrivateResourceURL ) == 0 ) + else if ( !m_aPrivateResourceURL.isEmpty() && aName.startsWith( m_aPrivateResourceURL ) ) { // special keys to retrieve information about a set of commands return m_xGenericUICommands->getByName( aName ); diff --git a/framework/source/uifactory/windowcontentfactorymanager.cxx b/framework/source/uifactory/windowcontentfactorymanager.cxx index 672041e6b1e7..b66c473b2d2a 100644 --- a/framework/source/uifactory/windowcontentfactorymanager.cxx +++ b/framework/source/uifactory/windowcontentfactorymanager.cxx @@ -84,7 +84,7 @@ void WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( const OUStrin const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17; const char RESOURCEURL_PREFIX[] = "private:resource/"; - if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) && + if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) && ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) { OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE )); -- cgit