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 /sc/source | |
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 'sc/source')
-rw-r--r-- | sc/source/core/data/conditio.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaname.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/vba/vbawindow.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaworkbooks.cxx | 6 |
5 files changed, 15 insertions, 16 deletions
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 117f2a096372..c0d6f0d1c0fc 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1072,12 +1072,12 @@ bool ScConditionEntry::IsValid( double nArg, const ScAddress& rPos ) const { OUString aStr = OUString::number(nVal1); OUString aStr2 = OUString::number(nArg); - bValid = aStr2.indexOf(aStr) == 0; + bValid = aStr2.startsWith(aStr); } else { OUString aStr2 = OUString::number(nArg); - bValid = aStr2.indexOf(aStrVal1) == 0; + bValid = aStr2.startsWith(aStrVal1); } break; case SC_COND_ENDS_WITH: @@ -1178,7 +1178,7 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos ) bValid = !bValid; break; case SC_COND_BEGINS_WITH: - bValid = rArg.indexOf(aUpVal1) == 0; + bValid = rArg.startsWith(aUpVal1); break; case SC_COND_ENDS_WITH: bValid = rArg.endsWith(aUpVal1); diff --git a/sc/source/ui/vba/vbaname.cxx b/sc/source/ui/vba/vbaname.cxx index f7ce25376d3f..fc5592b75276 100644 --- a/sc/source/ui/vba/vbaname.cxx +++ b/sc/source/ui/vba/vbaname.cxx @@ -118,7 +118,7 @@ void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGra OUString sContent( rContent ); if ( bRemoveEquals ) { - if (sContent.indexOf('=') == 0) + if (sContent.startsWith("=")) sContent = sContent.copy(1); } ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() ); diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 681a582279aa..b533561d4a42 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -891,7 +891,7 @@ protected: // always compile it in that grammar. Perhaps // css.sheet.FormulaParser should be used in future to directly // pass formula tokens when that API stabilizes. - if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().indexOf('=') == 0 ) ) + if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().startsWith("=") ) ) { uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW ); ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); @@ -4333,9 +4333,8 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, uno::Reference // *searchtext* - contains // <>*searchtext* - doesn't contain // [>|>=|<=|...]searchtext for GREATER_value, GREATER_EQUAL_value etc. - sal_Int32 nPos = 0; bool bIsNumeric = false; - if ( ( nPos = sCriteria1.indexOf( EQUALS ) ) == 0 ) + if ( sCriteria1.startsWith( EQUALS ) ) { if ( sCriteria1.getLength() == EQUALS.getLength() ) rFilterField.Operator = sheet::FilterOperator2::EMPTY; @@ -4350,7 +4349,7 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, uno::Reference } } - else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 ) + else if ( sCriteria1.startsWith( NOTEQUALS ) ) { if ( sCriteria1.getLength() == NOTEQUALS.getLength() ) rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY; @@ -4364,10 +4363,10 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, uno::Reference xDescProps->setPropertyValue( "UseRegularExpressions", uno::Any( sal_True ) ); } } - else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 ) + else if ( sCriteria1.startsWith( GREATERTHAN ) ) { bIsNumeric = true; - if ( ( nPos = sCriteria1.indexOf( GREATERTHANEQUALS ) ) == 0 ) + if ( sCriteria1.startsWith( GREATERTHANEQUALS ) ) { sCriteria1 = sCriteria1.copy( GREATERTHANEQUALS.getLength() ); rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL; @@ -4379,10 +4378,10 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, uno::Reference } } - else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 ) + else if ( sCriteria1.startsWith( LESSTHAN ) ) { bIsNumeric = true; - if ( ( nPos = sCriteria1.indexOf( LESSTHANEQUALS ) ) == 0 ) + if ( sCriteria1.startsWith( LESSTHANEQUALS ) ) { sCriteria1 = sCriteria1.copy( LESSTHANEQUALS.getLength() ); rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL; diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx index 207368e20181..1a0ec714b2c4 100644 --- a/sc/source/ui/vba/vbawindow.cxx +++ b/sc/source/ui/vba/vbawindow.cxx @@ -331,7 +331,7 @@ ScVbaWindow::getCaption() throw (uno::RuntimeException) { static OUString sDot("."); // starts with title - if ( sName.indexOf( sTitle ) == 0 ) + if ( sName.startsWith( sTitle ) ) // extention starts immediately after if ( sName.match( sDot, sTitle.getLength() ) ) sTitle = sName; diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index b6750c7eb3e7..907167adeff3 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -256,9 +256,9 @@ bool ScVbaWorkbooks::isSpreadSheetFile( const OUString& sType ) { // include calc_QPro etc. ? ( not for the moment anyway ) - if ( sType.indexOf( "calc_MS" ) == 0 - || sType.indexOf( "calc8" ) == 0 - || sType.indexOf( "calc_StarOffice" ) == 0 ) + if ( sType.startsWith( "calc_MS" ) + || sType.startsWith( "calc8" ) + || sType.startsWith( "calc_StarOffice" ) ) return true; return false; } |