summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-10-25 16:43:20 +0200
committerNoel Grandin <noel@peralex.com>2013-10-31 08:34:21 +0200
commite2451bd729d0f1d795a5b689deba65bc4e9d92c6 (patch)
tree4f2356107b0e58db7afda0fc324b9eac49ff68c0 /cui
parent460b52838fdad0352188bdd877b69cbb5f17ca63 (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 'cui')
-rw-r--r--cui/source/customize/cfg.cxx18
-rw-r--r--cui/source/customize/cfgutil.cxx10
-rw-r--r--cui/source/customize/macropg.cxx12
-rw-r--r--cui/source/dialogs/hldoctp.cxx2
-rw-r--r--cui/source/dialogs/hlinettp.cxx2
-rw-r--r--cui/source/tabpages/autocdlg.cxx2
6 files changed, 21 insertions, 25 deletions
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index 35da4cccdfa0..8605ade05212 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -804,7 +804,7 @@ SvxConfigDialog::SvxConfigDialog(
{
OUString text = ((const SfxStringItem*)pItem)->GetValue();
- if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
+ if (text.startsWith( ITEM_TOOLBAR_URL ) )
{
SetCurPageId( RID_SVXPAGE_TOOLBARS );
}
@@ -3109,7 +3109,7 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(
if ( pItem )
{
OUString text = ((const SfxStringItem*)pItem)->GetValue();
- if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
+ if (text.startsWith( ITEM_TOOLBAR_URL ))
{
m_aURLToSelect = text.copy( 0 );
}
@@ -3754,7 +3754,7 @@ void ToolbarSaveInData::SetSystemStyle(
const OUString& rResourceURL,
sal_Int32 nStyle )
{
- if ( rResourceURL.indexOf( "private" ) == 0 &&
+ if ( rResourceURL.startsWith( "private" ) &&
m_xPersistentWindowState.is() &&
m_xPersistentWindowState->hasByName( rResourceURL ) )
{
@@ -3793,7 +3793,7 @@ sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
{
sal_Int32 result = 0;
- if ( rResourceURL.indexOf( "private" ) == 0 &&
+ if ( rResourceURL.startsWith( "private" ) &&
m_xPersistentWindowState.is() &&
m_xPersistentWindowState->hasByName( rResourceURL ) )
{
@@ -3827,7 +3827,7 @@ OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
{
OUString result;
- if ( rResourceURL.indexOf( "private" ) == 0 &&
+ if ( rResourceURL.startsWith( "private" ) &&
m_xPersistentWindowState.is() &&
m_xPersistentWindowState->hasByName( rResourceURL ) )
{
@@ -3853,7 +3853,7 @@ OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
}
}
- if ( rResourceURL.indexOf( ".uno" ) == 0 &&
+ if ( rResourceURL.startsWith( ".uno" ) &&
m_xCommandToLabelMap.is() &&
m_xCommandToLabelMap->hasByName( rResourceURL ) )
{
@@ -3956,7 +3956,7 @@ SvxEntries* ToolbarSaveInData::GetEntries()
aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
OUString custom(CUSTOM_TOOLBAR_STR);
- if ( systemname.indexOf( custom ) == 0 )
+ if ( systemname.startsWith( custom ) )
{
pEntry->SetUserDefined( sal_True );
}
@@ -4008,7 +4008,7 @@ SvxEntries* ToolbarSaveInData::GetEntries()
// custom toolbars of the parent are not visible in the document layer
OUString custom(CUSTOM_TOOLBAR_STR);
- if ( systemname.indexOf( custom ) == 0 )
+ if ( systemname.startsWith( custom ) )
continue;
// check if toolbar is already in the document layer
@@ -4039,7 +4039,7 @@ SvxEntries* ToolbarSaveInData::GetEntries()
pEntry->SetMain( sal_True );
pEntry->SetStyle( GetSystemStyle( url ) );
- if ( systemname.indexOf( custom ) == 0 )
+ if ( systemname.startsWith( custom ) )
{
pEntry->SetUserDefined( sal_True );
}
diff --git a/cui/source/customize/cfgutil.cxx b/cui/source/customize/cfgutil.cxx
index 509a3728d7d3..a23418522fd9 100644
--- a/cui/source/customize/cfgutil.cxx
+++ b/cui/source/customize/cfgutil.cxx
@@ -99,7 +99,7 @@ sal_Bool SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl& aStyle)
static sal_Int32 LEN_SPART = CMDURL_SPART_ONLY.getLength();
static sal_Int32 LEN_FPART = CMDURL_FPART_ONLY.getLength();
- if (aStyle.sCommand.indexOf(CMDURL_STYLEPROT_ONLY, 0) != 0)
+ if (!aStyle.sCommand.startsWith(CMDURL_STYLEPROT_ONLY))
return sal_False;
aStyle.sFamily = OUString();
@@ -112,15 +112,15 @@ sal_Bool SfxStylesInfo_Impl::parseStyleCommand(SfxStyleInfo_Impl& aStyle)
return sal_False;
OUString sArg = sCmdArgs.copy(0, i);
- if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
+ if (sArg.startsWith(CMDURL_SPART_ONLY))
aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
- else if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
+ else if (sArg.startsWith(CMDURL_FPART_ONLY))
aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
sArg = sCmdArgs.copy(i+1, sCmdArgs.getLength()-i-1);
- if (sArg.indexOf(CMDURL_SPART_ONLY) == 0)
+ if (sArg.startsWith(CMDURL_SPART_ONLY))
aStyle.sStyle = sArg.copy(LEN_SPART, sArg.getLength()-LEN_SPART);
- else if (sArg.indexOf(CMDURL_FPART_ONLY) == 0)
+ else if (sArg.startsWith(CMDURL_FPART_ONLY))
aStyle.sFamily = sArg.copy(LEN_FPART, sArg.getLength()-LEN_FPART);
if (!(aStyle.sFamily.isEmpty() || aStyle.sStyle.isEmpty()))
diff --git a/cui/source/customize/macropg.cxx b/cui/source/customize/macropg.cxx
index e0ca7ef4c89d..ab01f069a0a0 100644
--- a/cui/source/customize/macropg.cxx
+++ b/cui/source/customize/macropg.cxx
@@ -631,7 +631,7 @@ long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton*
}
bool bDoubleClick = (pBtn == NULL);
- bool bUNOAssigned = (sEventURL.indexOf( aVndSunStarUNO ) == 0);
+ bool bUNOAssigned = sEventURL.startsWith( aVndSunStarUNO );
if( pBtn == pImpl->pDeletePB )
{
// delete pressed
@@ -895,14 +895,10 @@ AssignComponentDialog::AssignComponentDialog( Window * pParent, const OUString&
maOKButton.SetClickHdl(LINK(this, AssignComponentDialog, ButtonHandler));
OUString aMethodName;
- if( !maURL.isEmpty() )
+ if( maURL.startsWith( aVndSunStarUNO ) )
{
- sal_Int32 nIndex = maURL.indexOf( aVndSunStarUNO );
- if( nIndex == 0 )
- {
- sal_Int32 nBegin = aVndSunStarUNO.getLength();
- aMethodName = maURL.copy( nBegin );
- }
+ sal_Int32 nBegin = aVndSunStarUNO.getLength();
+ aMethodName = maURL.copy( nBegin );
}
maMethodEdit.SetText( aMethodName, Selection( 0, SELECTION_MAX ) );
}
diff --git a/cui/source/dialogs/hldoctp.cxx b/cui/source/dialogs/hldoctp.cxx
index 373bfbc98b12..1353038d6095 100644
--- a/cui/source/dialogs/hldoctp.cxx
+++ b/cui/source/dialogs/hldoctp.cxx
@@ -235,7 +235,7 @@ IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickTargetHdl_Impl)
if ( GetPathType ( maStrURL ) == Type_ExistsFile ||
maStrURL.isEmpty() ||
maStrURL.equalsIgnoreAsciiCase( sFileScheme ) ||
- maStrURL.indexOf( sHash ) == 0 )
+ maStrURL.startsWith( sHash ) )
{
mpMarkWnd->SetError( LERR_NOERROR );
diff --git a/cui/source/dialogs/hlinettp.cxx b/cui/source/dialogs/hlinettp.cxx
index bd475341e45a..322ab741519e 100644
--- a/cui/source/dialogs/hlinettp.cxx
+++ b/cui/source/dialogs/hlinettp.cxx
@@ -371,7 +371,7 @@ IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl)
// disable login-editfields if checked
if ( maCbAnonymous.IsChecked() )
{
- if ( maEdLogin.GetText().toAsciiLowerCase().indexOf ( sAnonymous ) == 0 )
+ if ( maEdLogin.GetText().toAsciiLowerCase().startsWith( sAnonymous ) )
{
maStrOldUser = aEmptyStr;
maStrOldPassword = aEmptyStr;
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index fc18ea79d4b3..4f1cca75502c 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -1274,7 +1274,7 @@ IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, Edit*, pEdt)
else
{
aTestStr = pCharClass->lowercase( aTestStr );
- if( aTestStr.indexOf(aWordStr) == 0 && !bTmpSelEntry )
+ if( aTestStr.startsWith(aWordStr) && !bTmpSelEntry )
{
m_pReplaceTLB->MakeVisible( pEntry );
bTmpSelEntry = sal_True;