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 /reportdesign | |
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 'reportdesign')
4 files changed, 8 insertions, 8 deletions
diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx index 680172fec877..fe362340f98c 100644 --- a/reportdesign/source/core/api/ReportDefinition.cxx +++ b/reportdesign/source/core/api/ReportDefinition.cxx @@ -2197,7 +2197,7 @@ uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstanceWith ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed); uno::Reference< uno::XInterface > xRet; - if ( aServiceSpecifier.indexOf( "com.sun.star.document.ImportEmbeddedObjectResolver") == 0 ) + if ( aServiceSpecifier.startsWith( "com.sun.star.document.ImportEmbeddedObjectResolver") ) { uno::Reference< embed::XStorage > xStorage; const uno::Any* pIter = _aArgs.getConstArray(); @@ -2220,7 +2220,7 @@ uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstance( co ::osl::MutexGuard aGuard(m_aMutex); ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed); uno::Reference< drawing::XShape > xShape; - if ( aServiceSpecifier.indexOf( "com.sun.star.report." ) == 0 ) + if ( aServiceSpecifier.startsWith( "com.sun.star.report." ) ) { if ( aServiceSpecifier == SERVICE_SHAPE ) xShape.set(SvxUnoDrawMSFactory::createInstance("com.sun.star.drawing.CustomShape"),uno::UNO_QUERY_THROW); @@ -2232,7 +2232,7 @@ uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstance( co else xShape.set(SvxUnoDrawMSFactory::createInstance("com.sun.star.drawing.OLE2Shape"),uno::UNO_QUERY_THROW); } - else if ( aServiceSpecifier.indexOf( "com.sun.star.form.component." ) == 0 ) + else if ( aServiceSpecifier.startsWith( "com.sun.star.form.component." ) ) { xShape.set(m_aProps->m_xContext->getServiceManager()->createInstanceWithContext(aServiceSpecifier,m_aProps->m_xContext),uno::UNO_QUERY); } diff --git a/reportdesign/source/core/misc/reportformula.cxx b/reportdesign/source/core/misc/reportformula.cxx index 94158d8d00eb..689c5d9581cd 100644 --- a/reportdesign/source/core/misc/reportformula.cxx +++ b/reportdesign/source/core/misc/reportformula.cxx @@ -67,7 +67,7 @@ namespace rptui { case Expression: { - if ( _rFieldOrExpression.indexOf( lcl_getExpressionPrefix() ) == 0 ) + if ( _rFieldOrExpression.startsWith( lcl_getExpressionPrefix() ) ) m_sCompleteFormula = _rFieldOrExpression; else m_sCompleteFormula = lcl_getExpressionPrefix() + _rFieldOrExpression; @@ -102,7 +102,7 @@ namespace rptui sal_Int32 nPrefixLen( -1 ); // is it an ordinary expression? - if ( m_sCompleteFormula.indexOf( lcl_getExpressionPrefix( &nPrefixLen ) ) == 0 ) + if ( m_sCompleteFormula.startsWith( lcl_getExpressionPrefix( &nPrefixLen ) ) ) { m_eType = Expression; m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen ); @@ -110,7 +110,7 @@ namespace rptui } /// does it refer to a field? - if ( m_sCompleteFormula.indexOf( lcl_getFieldPrefix( &nPrefixLen ) ) == 0 ) + if ( m_sCompleteFormula.startsWith( lcl_getFieldPrefix( &nPrefixLen ) ) ) { if ( ( m_sCompleteFormula.getLength() >= nPrefixLen + 2 ) && ( m_sCompleteFormula[ nPrefixLen ] == '[' ) diff --git a/reportdesign/source/filter/xml/xmlExport.cxx b/reportdesign/source/filter/xml/xmlExport.cxx index c76a4e34e200..8ab0b4303ec1 100644 --- a/reportdesign/source/filter/xml/xmlExport.cxx +++ b/reportdesign/source/filter/xml/xmlExport.cxx @@ -1458,7 +1458,7 @@ void ORptExport::exportParagraph(const Reference< XReportControlModel >& _xRepor else { - if ( sToken.indexOf('"') == 0 && sToken.lastIndexOf('"') == sToken.getLength()-1 ) + if ( sToken.startsWith("\"") && sToken.endsWith("\"") ) sToken = sToken.copy(1,sToken.getLength()-2); bool bPrevCharIsSpace = false; diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx index be3ab4919291..ef35d1ca1b6c 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -2719,7 +2719,7 @@ uno::Any SAL_CALL OReportController::getViewData(void) throw( uno::RuntimeExcept const FeatureState aFeatureState = GetState( nCommandIDs[i] ); OUString sCommandURL( getURLForId( nCommandIDs[i] ).Main ); - OSL_ENSURE( sCommandURL.indexOfAsciiL( ".uno:", 5 ) == 0, "OReportController::getViewData: illegal command URL!" ); + OSL_ENSURE( sCommandURL.startsWith( ".uno:" ), "OReportController::getViewData: illegal command URL!" ); sCommandURL = sCommandURL.copy( 5 ); Any aCommandState; |