diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-09-19 08:25:34 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-25 08:55:12 +0200 |
commit | daf44342ca82c5b0e79da88b7f9dbf28f6d43a8b (patch) | |
tree | 54517341b968d644de2e48028d1974f14c70e248 /xmloff/source/draw | |
parent | 49614a9ea971ff7f370f863ce8a2735aab973cee (diff) |
Simplify containers iterations in xmloff/source/[c-d]*
Use range-based loop or replace with STL functions.
Change-Id: I2af2d739d55a0bf480bb6e9d57b49dd16806af30
Reviewed-on: https://gerrit.libreoffice.org/60734
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff/source/draw')
-rw-r--r-- | xmloff/source/draw/XMLShapeStyleContext.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/draw/animexp.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/draw/sdpropls.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/draw/sdxmlexp.cxx | 65 | ||||
-rw-r--r-- | xmloff/source/draw/shapeexport.cxx | 21 | ||||
-rw-r--r-- | xmloff/source/draw/shapeimport.cxx | 9 | ||||
-rw-r--r-- | xmloff/source/draw/ximpcustomshape.cxx | 26 | ||||
-rw-r--r-- | xmloff/source/draw/ximpshap.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.cxx | 28 |
9 files changed, 64 insertions, 129 deletions
diff --git a/xmloff/source/draw/XMLShapeStyleContext.cxx b/xmloff/source/draw/XMLShapeStyleContext.cxx index 31f4beeb2044..10013b18fc3c 100644 --- a/xmloff/source/draw/XMLShapeStyleContext.cxx +++ b/xmloff/source/draw/XMLShapeStyleContext.cxx @@ -135,16 +135,12 @@ void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet ::std::vector< XMLPropertyState > &rProperties = GetProperties(); ::std::vector< XMLPropertyState >::iterator end( rProperties.end() ); - ::std::vector< XMLPropertyState >::iterator property; // first, look for the old format, where we had a text:list-style-name // attribute in the style:properties element - for( property = rProperties.begin(); property != end; ++property ) - { + auto property = std::find_if(rProperties.begin(), end, [&rMapper](XMLPropertyState& rProp) { // find properties with context - if( (property->mnIndex != -1) && (rMapper->GetEntryContextId( property->mnIndex ) == CTF_SD_NUMBERINGRULES_NAME) ) - break; - } + return (rProp.mnIndex != -1) && (rMapper->GetEntryContextId( rProp.mnIndex ) == CTF_SD_NUMBERINGRULES_NAME); }); // if we did not find an old list-style-name in the properties, and we need one // because we got a style:list-style attribute in the style-style element diff --git a/xmloff/source/draw/animexp.cxx b/xmloff/source/draw/animexp.cxx index dc17b1776102..abb2a0266622 100644 --- a/xmloff/source/draw/animexp.cxx +++ b/xmloff/source/draw/animexp.cxx @@ -426,19 +426,14 @@ void XMLAnimationsExporter::exportAnimations( SvXMLExport& rExport ) { mpImpl->maEffects.sort(); - list<XMLEffectHint>::iterator aIter = mpImpl->maEffects.begin(); - const list<XMLEffectHint>::iterator aEnd = mpImpl->maEffects.end(); - OUStringBuffer sTmp; - if( aIter != aEnd ) + if( !mpImpl->maEffects.empty() ) { SvXMLElementExport aElement( rExport, XML_NAMESPACE_PRESENTATION, XML_ANIMATIONS, true, true ); - do + for (const auto& rEffect : mpImpl->maEffects) { - XMLEffectHint& rEffect = *aIter; - SAL_WARN_IF( !rEffect.mxShape.is(), "xmloff", "shape id creation failed for animation effect?" ); rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_SHAPE_ID, rExport.getInterfaceToIdentifierMapper().getIdentifier( rEffect.mxShape ) ); @@ -523,10 +518,7 @@ void XMLAnimationsExporter::exportAnimations( SvXMLExport& rExport ) SvXMLElementExport aElem( rExport, XML_NAMESPACE_PRESENTATION, XML_SOUND, true, true ); } } - - ++aIter; } - while( aIter != aEnd ); } mpImpl->maEffects.clear(); diff --git a/xmloff/source/draw/sdpropls.cxx b/xmloff/source/draw/sdpropls.cxx index b362798246c7..050b2ff3938a 100644 --- a/xmloff/source/draw/sdpropls.cxx +++ b/xmloff/source/draw/sdpropls.cxx @@ -1338,11 +1338,9 @@ void XMLShapeExportPropertyMapper::ContextFilter( XMLPropertyState* pControlWritingMode = nullptr; // filter properties - for( std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); - aIter != rProperties.end(); - ++aIter ) + for( auto& rProp : rProperties ) { - XMLPropertyState *property = &(*aIter); + XMLPropertyState *property = &rProp; if( property->mnIndex == -1 ) continue; @@ -1700,11 +1698,9 @@ void XMLPageExportPropertyMapper::ContextFilter( sal_Int16 nTransitionType = 0; // filter properties - for( std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); - aIter != rProperties.end(); - ++aIter ) + for( auto& rProp : rProperties ) { - XMLPropertyState *property = &(*aIter); + XMLPropertyState *property = &rProp; if( property->mnIndex == -1 ) continue; diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx index ab352d8298d1..0eb2051d9edb 100644 --- a/xmloff/source/draw/sdxmlexp.cxx +++ b/xmloff/source/draw/sdxmlexp.cxx @@ -1362,13 +1362,8 @@ void SdXMLExport::ImpPrepDrawPageInfos() static OUString findOrAppendImpl( std::vector< OUString >& rVector, const OUString& rText, const sal_Char* pPrefix ) { // search rVector if there is already a string that equals rText - std::vector< OUString >::iterator aIter; - sal_Int32 nIndex; - for( nIndex = 1, aIter = rVector.begin(); aIter != rVector.end(); ++aIter, ++nIndex ) - { - if( (*aIter) == rText ) - break; - } + auto aIter = std::find(rVector.begin(), rVector.end(), rText); + sal_Int32 nIndex = std::distance(rVector.begin(), aIter) + 1; // if nothing is found, append the string at the end of rVector if( aIter == rVector.end() ) @@ -1384,16 +1379,13 @@ static OUString findOrAppendImpl( std::vector< OUString >& rVector, const OUStri static OUString findOrAppendImpl( std::vector< DateTimeDeclImpl >& rVector, const OUString& rText, bool bFixed, sal_Int32 nFormat, const sal_Char* pPrefix ) { // search rVector if there is already a DateTimeDeclImpl with rText,bFixed and nFormat - std::vector< DateTimeDeclImpl >::iterator aIter; - sal_Int32 nIndex; - for( nIndex = 1, aIter = rVector.begin(); aIter != rVector.end(); ++aIter, ++nIndex ) - { - const DateTimeDeclImpl& rDecl = (*aIter); - if( (rDecl.mbFixed == bFixed ) && - (!bFixed || rDecl.maStrText == rText) && - (bFixed || (rDecl.mnFormat == nFormat) ) ) - break; - } + auto aIter = std::find_if(rVector.begin(), rVector.end(), + [bFixed, &rText, nFormat](const DateTimeDeclImpl& rDecl) { + return (rDecl.mbFixed == bFixed) && + (!bFixed || (rDecl.maStrText == rText)) && + (bFixed || (rDecl.mnFormat == nFormat)); + }); + sal_Int32 nIndex = std::distance(rVector.begin(), aIter) + 1; // if nothing is found, append a new DateTimeDeclImpl if( aIter == rVector.end() ) @@ -1410,7 +1402,6 @@ static OUString findOrAppendImpl( std::vector< DateTimeDeclImpl >& rVector, cons OUString aStr( OUString::createFromAscii( pPrefix ) ); aStr += OUString::number( nIndex ); return aStr; - } static const sal_Char gpStrHeaderTextPrefix[] = "hdr"; @@ -1477,16 +1468,16 @@ void SdXMLExport::ImpWriteHeaderFooterDecls() { // export header decls const OUString aPrefix( gpStrHeaderTextPrefix ); - std::vector< OUString >::iterator aIter; - sal_Int32 nIndex; - for( nIndex = 1, aIter = maHeaderDeclsVector.begin(); aIter != maHeaderDeclsVector.end(); ++aIter, ++nIndex ) + sal_Int32 nIndex = 1; + for( const auto& rDecl : maHeaderDeclsVector ) { sBuffer.append( aPrefix ); sBuffer.append( nIndex ); AddAttribute(XML_NAMESPACE_PRESENTATION, XML_NAME, sBuffer.makeStringAndClear()); SvXMLElementExport aElem(*this, XML_NAMESPACE_PRESENTATION, XML_HEADER_DECL, true, true); - Characters(*aIter); + Characters(rDecl); + ++nIndex; } } @@ -1494,16 +1485,16 @@ void SdXMLExport::ImpWriteHeaderFooterDecls() { // export footer decls const OUString aPrefix( gpStrFooterTextPrefix ); - std::vector< OUString >::iterator aIter; - sal_Int32 nIndex; - for( nIndex = 1, aIter = maFooterDeclsVector.begin(); aIter != maFooterDeclsVector.end(); ++aIter, ++nIndex ) + sal_Int32 nIndex = 1; + for( const auto& rDecl : maFooterDeclsVector ) { sBuffer.append( aPrefix ); sBuffer.append( nIndex ); AddAttribute(XML_NAMESPACE_PRESENTATION, XML_NAME, sBuffer.makeStringAndClear()); SvXMLElementExport aElem(*this, XML_NAMESPACE_PRESENTATION, XML_FOOTER_DECL, false, false); - Characters(*aIter); + Characters(rDecl); + ++nIndex; } } @@ -1511,12 +1502,9 @@ void SdXMLExport::ImpWriteHeaderFooterDecls() { // export footer decls const OUString aPrefix( gpStrDateTimeTextPrefix ); - std::vector< DateTimeDeclImpl >::iterator aIter; - sal_Int32 nIndex; - for( nIndex = 1, aIter = maDateTimeDeclsVector.begin(); aIter != maDateTimeDeclsVector.end(); ++aIter, ++nIndex ) + sal_Int32 nIndex = 1; + for( const auto& rDecl : maDateTimeDeclsVector ) { - const DateTimeDeclImpl& rDecl = (*aIter); - sBuffer.append( aPrefix ); sBuffer.append( nIndex ); AddAttribute( XML_NAMESPACE_PRESENTATION, XML_NAME, sBuffer.makeStringAndClear()); @@ -1529,6 +1517,8 @@ void SdXMLExport::ImpWriteHeaderFooterDecls() SvXMLElementExport aElem(*this, XML_NAMESPACE_PRESENTATION, XML_DATE_TIME_DECL, false, false); if( rDecl.mbFixed ) Characters(rDecl.maStrText); + + ++nIndex; } } } @@ -2502,16 +2492,11 @@ void SdXMLExport::exportDataStyles() void SdXMLExport::exportAutoDataStyles() { - SdXMLFormatMap::iterator aIter( maUsedDateStyles.begin() ); - SdXMLFormatMap::iterator aEnd( maUsedDateStyles.end() ); - - while( aIter != aEnd ) - SdXMLNumberStylesExporter::exportDateStyle( *this, (*aIter++) ); + for( const auto& rUsedDateStyle : maUsedDateStyles ) + SdXMLNumberStylesExporter::exportDateStyle( *this, rUsedDateStyle ); - aIter = maUsedTimeStyles.begin(); - aEnd = maUsedTimeStyles.end(); - while( aIter != aEnd ) - SdXMLNumberStylesExporter::exportTimeStyle( *this, (*aIter++) ); + for( const auto& rUsedTimeStyle : maUsedTimeStyles ) + SdXMLNumberStylesExporter::exportTimeStyle( *this, rUsedTimeStyle ); if(HasFormExport()) GetFormExport()->exportAutoControlNumberStyles(); diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index 22c421e19a70..b78d6c3b2f89 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -437,14 +437,8 @@ void XMLShapeExport::collectShapeAutoStyles(const uno::Reference< drawing::XShap } } - std::vector< XMLPropertyState >::iterator aIter = aPropStates.begin(); - std::vector< XMLPropertyState >::iterator aEnd = aPropStates.end(); - while( aIter != aEnd ) - { - if( aIter->mnIndex != -1 ) - nCount++; - ++aIter; - } + nCount = std::count_if(aPropStates.cbegin(), aPropStates.cend(), + [](const XMLPropertyState& rProp) { return rProp.mnIndex != -1; }); } if(nCount == 0) @@ -501,15 +495,8 @@ void XMLShapeExport::collectShapeAutoStyles(const uno::Reference< drawing::XShap } } - nCount = 0; - std::vector< XMLPropertyState >::iterator aIter = aPropStates.begin(); - std::vector< XMLPropertyState >::iterator aEnd = aPropStates.end(); - while( aIter != aEnd ) - { - if( aIter->mnIndex != -1 ) - nCount++; - ++aIter; - } + nCount = std::count_if(aPropStates.cbegin(), aPropStates.cend(), + [](const XMLPropertyState& rProp) { return rProp.mnIndex != -1; }); if( nCount ) { diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx index a474cef96aa3..c55cd25411a9 100644 --- a/xmloff/source/draw/shapeimport.cxx +++ b/xmloff/source/draw/shapeimport.cxx @@ -982,13 +982,10 @@ void XMLShapeImportHelper::moveGluePointMapping( const css::uno::Reference< css: ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) ); if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() ) { - GluePointIdMap::iterator aShapeIdIter = (*aShapeIter).second.begin(); - GluePointIdMap::iterator aShapeIdEnd = (*aShapeIter).second.end(); - while ( aShapeIdIter != aShapeIdEnd ) + for ( auto& rShapeId : (*aShapeIter).second ) { - if ( (*aShapeIdIter).second != -1 ) - (*aShapeIdIter).second += n; - ++aShapeIdIter; + if ( rShapeId.second != -1 ) + rShapeId.second += n; } } } diff --git a/xmloff/source/draw/ximpcustomshape.cxx b/xmloff/source/draw/ximpcustomshape.cxx index c30647b5a469..137131b7ce7a 100644 --- a/xmloff/source/draw/ximpcustomshape.cxx +++ b/xmloff/source/draw/ximpcustomshape.cxx @@ -1180,50 +1180,45 @@ void XMLEnhancedCustomShapeContext::EndElement() } // resolve equation - std::vector< OUString >::iterator aEquationIter = maEquations.begin(); - std::vector< OUString >::iterator aEquationEnd = maEquations.end(); - while( aEquationIter != aEquationEnd ) + for( auto& rEquation : maEquations ) { sal_Int32 nIndexOf = 0; do { - nIndexOf = aEquationIter->indexOf( '?', nIndexOf ); + nIndexOf = rEquation.indexOf( '?', nIndexOf ); if ( nIndexOf != -1 ) { OUString aEquationName; - if ( GetEquationName( *aEquationIter, nIndexOf + 1, aEquationName ) ) + if ( GetEquationName( rEquation, nIndexOf + 1, aEquationName ) ) { // copying first characters inclusive '?' - OUString aNew( aEquationIter->copy( 0, nIndexOf + 1 ) ); + OUString aNew( rEquation.copy( 0, nIndexOf + 1 ) ); sal_Int32 nIndex = 0; EquationHashMap::iterator aHashIter( pH->find( aEquationName ) ); if ( aHashIter != pH->end() ) nIndex = (*aHashIter).second; aNew += OUString::number( nIndex ); - aNew += aEquationIter->copy( nIndexOf + aEquationName.getLength() + 1 ); - *aEquationIter = aNew; + aNew += rEquation.copy( nIndexOf + aEquationName.getLength() + 1 ); + rEquation = aNew; } nIndexOf++; } } while( nIndexOf != -1 ); - ++aEquationIter; } // Path sal_Int32 i; - std::vector< beans::PropertyValue >::iterator aPathIter = maPath.begin(); - std::vector< beans::PropertyValue >::iterator aPathEnd = maPath.end(); - while ( aPathIter != aPathEnd ) + for ( beans::PropertyValue& rPathItem : maPath ) { - switch( EASGet( aPathIter->Name ) ) + switch( EASGet( rPathItem.Name ) ) { case EAS_Coordinates : case EAS_GluePoints : { uno::Sequence< css::drawing::EnhancedCustomShapeParameterPair > const & rSeq = *o3tl::doAccess<uno::Sequence< css::drawing::EnhancedCustomShapeParameterPair > >( - aPathIter->Value); + rPathItem.Value); for ( i = 0; i < rSeq.getLength(); i++ ) { CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].First), pH.get() ); @@ -1235,7 +1230,7 @@ void XMLEnhancedCustomShapeContext::EndElement() { uno::Sequence< css::drawing::EnhancedCustomShapeTextFrame > const & rSeq = *o3tl::doAccess<uno::Sequence< css::drawing::EnhancedCustomShapeTextFrame > >( - aPathIter->Value); + rPathItem.Value); for ( i = 0; i < rSeq.getLength(); i++ ) { CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].TopLeft.First), pH.get() ); @@ -1248,7 +1243,6 @@ void XMLEnhancedCustomShapeContext::EndElement() default: break; } - ++aPathIter; } for ( css::beans::PropertyValues const & aHandle : maHandles ) { diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index 21339eb6bbcf..a286811d4e52 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -3762,15 +3762,9 @@ void SdXMLCustomShapeContext::EndElement() //fdo#84043 overwrite the property if it already exists, otherwise append it beans::PropertyValue* pItem; - std::vector< beans::PropertyValue >::iterator aI(maCustomShapeGeometry.begin()); - std::vector< beans::PropertyValue >::iterator aE(maCustomShapeGeometry.end()); - while (aI != aE) - { - if (aI->Name == sName) - break; - ++aI; - } - if (aI != aE) + auto aI = std::find_if(maCustomShapeGeometry.begin(), maCustomShapeGeometry.end(), + [&sName](beans::PropertyValue& rValue) { return rValue.Name == sName; }); + if (aI != maCustomShapeGeometry.end()) { beans::PropertyValue& rItem = *aI; pItem = &rItem; diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index 425c0a3b9942..0bc675d6d3e8 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -192,19 +192,18 @@ void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite ) const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper(); - ::std::vector< XMLPropertyState >::iterator property = rProperties.begin(); - for(; property != rProperties.end(); ++property) + for(auto& property : rProperties) { - if( property->mnIndex == -1 ) + if( property.mnIndex == -1 ) continue; - sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property->mnIndex); + sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property.mnIndex); switch( nContextID ) { case CTF_DATE_TIME_FORMAT: { OUString sStyleName; - (*property).maValue >>= sStyleName; + property.maValue >>= sStyleName; sal_Int32 nStyle = 0; @@ -215,7 +214,7 @@ void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite ) if( pSdNumStyle ) nStyle = pSdNumStyle->GetDrawKey(); - (*property).maValue <<= nStyle; + property.maValue <<= nStyle; } break; } @@ -1187,18 +1186,13 @@ static bool canSkipReset(const OUString &rName, const XMLPropStyleContext* pProp if (nIndexStyle != -1) { const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties(); - ::std::vector< XMLPropertyState >::const_iterator property = rProperties.begin(); - for(; property != rProperties.end(); ++property) + auto property = std::find_if(rProperties.cbegin(), rProperties.cend(), + [nIndexStyle](const XMLPropertyState& rProp) { return rProp.mnIndex == nIndexStyle; }); + if (property != rProperties.cend()) { - sal_Int32 nIdx = property->mnIndex; - if (nIdx == nIndexStyle) - { - bool bNewStyleTextAutoGrowHeight(false); - property->maValue >>= bNewStyleTextAutoGrowHeight; - if (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight) - bCanSkipReset = true; - break; - } + bool bNewStyleTextAutoGrowHeight(false); + property->maValue >>= bNewStyleTextAutoGrowHeight; + bCanSkipReset = (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight); } } } |