From 54afdbd1b442d93313a01e58dba8fe3b84f596d1 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Wed, 12 Jun 2019 11:21:20 +0300 Subject: Simplify Sequence iterations in writerfilter, writerperfect, xmlhelp Use range-based loops or replace with comphelper or STL functions Change-Id: I9113e04d15ad84d0abac087afc627969e8ebc354 Reviewed-on: https://gerrit.libreoffice.org/73867 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../source/dmapper/DomainMapperTableHandler.cxx | 40 ++++---- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 109 +++++++++------------ writerfilter/source/dmapper/GraphicImport.cxx | 16 ++- writerfilter/source/dmapper/NumberingManager.cxx | 25 ++--- writerfilter/source/dmapper/PropertyMap.cxx | 24 ++--- writerfilter/source/dmapper/StyleSheetTable.cxx | 19 ++-- writerfilter/source/dmapper/ThemeTable.cxx | 8 +- writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 15 +-- writerfilter/source/ooxml/OOXMLStreamImpl.cxx | 15 +-- 9 files changed, 112 insertions(+), 159 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 0844050c37a7..27a710f5a0b6 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -889,7 +889,7 @@ static bool lcl_emptyRow(std::vector& rTableRanges, sal_Int32 nRo } RowSequence_t rRowSeq = rTableRanges[nRow]; - if (rRowSeq.getLength() == 0) + if (!rRowSeq.hasElements()) { SAL_WARN("writerfilter.dmapper", "m_aCellProperties not in sync with rTableRanges?"); return false; @@ -906,12 +906,14 @@ static bool lcl_emptyRow(std::vector& rTableRanges, sal_Int32 nRo uno::Reference xTextRangeCompare(rRowSeq[0][0]->getText(), uno::UNO_QUERY); try { - for (sal_Int32 nCell = 0; nCell < rRowSeq.getLength(); ++nCell) - // See SwXText::Impl::ConvertCell(), we need to compare the start of - // the start and the end of the end. However for our text ranges, only - // the starts are set, so compareRegionStarts() does what we need. - if (xTextRangeCompare->compareRegionStarts(rRowSeq[nCell][0], rRowSeq[nCell][1]) != 0) - return false; + // See SwXText::Impl::ConvertCell(), we need to compare the start of + // the start and the end of the end. However for our text ranges, only + // the starts are set, so compareRegionStarts() does what we need. + bool bRangesAreNotEqual = std::any_of(rRowSeq.begin(), rRowSeq.end(), + [&xTextRangeCompare](const CellSequence_t& rCellSeq) { + return xTextRangeCompare->compareRegionStarts(rCellSeq[0], rCellSeq[1]) != 0; }); + if (bRangesAreNotEqual) + return false; } catch (const lang::IllegalArgumentException& e) { @@ -1083,21 +1085,19 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab } // OOXML table style may container paragraph properties, apply these now. - for (int i = 0; i < aTableInfo.aTableProperties.getLength(); ++i) + auto pTableProp = std::find_if(aTableInfo.aTableProperties.begin(), aTableInfo.aTableProperties.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "ParaBottomMargin"; }); + if (pTableProp != aTableInfo.aTableProperties.end()) { - if (aTableInfo.aTableProperties[i].Name == "ParaBottomMargin") + uno::Reference xCellRange(xTable, uno::UNO_QUERY); + uno::Any aBottomMargin = pTableProp->Value; + sal_Int32 nRows = aCellProperties.getLength(); + for (sal_Int32 nRow = 0; nRow < nRows; ++nRow) { - uno::Reference xCellRange(xTable, uno::UNO_QUERY); - uno::Any aBottomMargin = aTableInfo.aTableProperties[i].Value; - sal_Int32 nRows = aCellProperties.getLength(); - for (sal_Int32 nRow = 0; nRow < nRows; ++nRow) - { - const uno::Sequence< beans::PropertyValues > aCurrentRow = aCellProperties[nRow]; - sal_Int32 nCells = aCurrentRow.getLength(); - for (sal_Int32 nCell = 0; nCell < nCells; ++nCell) - lcl_ApplyCellParaProps(xCellRange->getCellByPosition(nCell, nRow), aBottomMargin); - } - break; + const uno::Sequence< beans::PropertyValues > aCurrentRow = aCellProperties[nRow]; + sal_Int32 nCells = aCurrentRow.getLength(); + for (sal_Int32 nCell = 0; nCell < nCells; ++nCell) + lcl_ApplyCellParaProps(xCellRange->getCellByPosition(nCell, nRow), aBottomMargin); } } } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index f03ee6f8271b..d70ebb443691 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -633,9 +633,9 @@ FieldContextPtr const & DomainMapper_Impl::GetTopFieldContext() void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops ) { OSL_ENSURE(m_aCurrentTabStops.empty(), "tab stops already initialized"); - for( sal_Int32 nTab = 0; nTab < rInitTabStops.getLength(); ++nTab) + for( const auto& rTabStop : rInitTabStops) { - m_aCurrentTabStops.emplace_back(rInitTabStops[nTab] ); + m_aCurrentTabStops.emplace_back(rTabStop); } } @@ -1626,13 +1626,12 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, const Proper { // If we are in comments, then disable CharGrabBag, comment text doesn't support that. uno::Sequence< beans::PropertyValue > aValues = pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments); - sal_Int32 len = aValues.getLength(); if (m_bStartTOC || m_bStartIndex || m_bStartBibliography) - for( int i =0; i < len; ++i ) + for( auto& rValue : aValues ) { - if (aValues[i].Name == "CharHidden") - aValues[i].Value <<= false; + if (rValue.Name == "CharHidden") + rValue.Value <<= false; } uno::Reference< text::XTextRange > xTextRange; @@ -2339,18 +2338,18 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape xShapePropertySet->getPropertyValue("FrameInteropGrabBag") >>= aGrabBag; bool checkBtLrStatus = false; - for (int i = 0; i < aGrabBag.getLength(); ++i) + for (const auto& rProp : aGrabBag) { - if (aGrabBag[i].Name == "mso-layout-flow-alt") + if (rProp.Name == "mso-layout-flow-alt") { - m_bFrameBtLr = aGrabBag[i].Value.get() == "bottom-to-top"; + m_bFrameBtLr = rProp.Value.get() == "bottom-to-top"; checkBtLrStatus = true; } - if (aGrabBag[i].Name == "VML-Z-ORDER") + if (rProp.Name == "VML-Z-ORDER") { GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper(); sal_Int32 zOrder(0); - aGrabBag[i].Value >>= zOrder; + rProp.Value >>= zOrder; xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder))); pZOrderHelper->addItem(xShapePropertySet, zOrder); xShapePropertySet->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny( zOrder >= 0 ) ); @@ -2359,7 +2358,7 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape if(checkBtLrStatus && checkZOrderStatus) break; - if ( aGrabBag[i].Name == "TxbxHasLink" ) + if ( rProp.Name == "TxbxHasLink" ) { //Chaining of textboxes will happen in ~DomainMapper_Impl //i.e when all the textboxes are read and all its attributes @@ -2391,19 +2390,19 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape uno::Reference xShapePropertySet(xShape, uno::UNO_QUERY); uno::Sequence aGrabBag; xShapePropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag; - for (int i = 0; i < aGrabBag.getLength(); ++i) + for (const auto& rProp : aGrabBag) { - if (aGrabBag[i].Name == "VML-Z-ORDER") + if (rProp.Name == "VML-Z-ORDER") { GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper(); sal_Int32 zOrder(0); - aGrabBag[i].Value >>= zOrder; + rProp.Value >>= zOrder; xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder))); pZOrderHelper->addItem(xShapePropertySet, zOrder); xShapePropertySet->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny( zOrder >= 0 ) ); checkZOrderStatus = true; } - else if ( aGrabBag[i].Name == "TxbxHasLink" ) + else if ( rProp.Name == "TxbxHasLink" ) { //Chaining of textboxes will happen in ~DomainMapper_Impl //i.e when all the textboxes are read and all its attributes @@ -2527,17 +2526,17 @@ bool DomainMapper_Impl::IsSdtEndBefore() if(pContext) { uno::Sequence< beans::PropertyValue > currentCharProps = pContext->GetPropertyValues(); - for (int i =0; i< currentCharProps.getLength(); i++) + for (const auto& rCurrentCharProp : currentCharProps) { - if (currentCharProps[i].Name == "CharInteropGrabBag") + if (rCurrentCharProp.Name == "CharInteropGrabBag") { uno::Sequence aCharGrabBag; - currentCharProps[i].Value >>= aCharGrabBag; - for (int j=0; j < aCharGrabBag.getLength();j++) + rCurrentCharProp.Value >>= aCharGrabBag; + for (const auto& rProp : aCharGrabBag) { - if(aCharGrabBag[j].Name == "SdtEndBefore") + if(rProp.Name == "SdtEndBefore") { - aCharGrabBag[j].Value >>= bIsSdtEndBefore; + rProp.Value >>= bIsSdtEndBefore; } } } @@ -2935,11 +2934,10 @@ void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand, static uno::Any lcl_getGrabBagValue( const uno::Sequence& grabBag, OUString const & name ) { - for (int i = 0; i < grabBag.getLength(); ++i) - { - if (grabBag[i].Name == name ) - return grabBag[i].Value ; - } + auto pProp = std::find_if(grabBag.begin(), grabBag.end(), + [&name](const beans::PropertyValue& rProp) { return rProp.Name == name; }); + if (pProp != grabBag.end()) + return pProp->Value; return uno::Any(); } @@ -3728,10 +3726,7 @@ static uno::Sequence< beans::PropertyValues > lcl_createTOXLevelHyperlinks( bool pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator; } //copy the 'old' entries except the last (page no) - for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken) - { - pNewLevel[nToken + 1] = aLevel[nToken]; - } + std::copy(aLevel.begin(), std::prev(aLevel.end()), std::next(aNewLevel.begin())); //copy page no entry (last or last but one depending on bHyperlinks sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3); pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1]; @@ -5966,21 +5961,17 @@ uno::Reference DomainMapper_Impl::GetCurrentNumberingCharSt } uno::Sequence aProps; xLevels->getByIndex(nListLevel) >>= aProps; - for (int i = 0; i < aProps.getLength(); ++i) + auto pProp = std::find_if(aProps.begin(), aProps.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "CharStyleName"; }); + if (pProp != aProps.end()) { - const beans::PropertyValue& rProp = aProps[i]; - - if (rProp.Name == "CharStyleName") - { - OUString aCharStyle; - rProp.Value >>= aCharStyle; - uno::Reference xCharacterStyles; - uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY); - uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); - xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles; - xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW); - break; - } + OUString aCharStyle; + pProp->Value >>= aCharStyle; + uno::Reference xCharacterStyles; + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles; + xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW); } } catch( const uno::Exception& ) @@ -6039,16 +6030,10 @@ sal_Int32 DomainMapper_Impl::getNumberingProperty(const sal_Int32 nListId, sal_I { uno::Sequence aProps; xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; - for (int i = 0; i < aProps.getLength(); ++i) - { - const beans::PropertyValue& rProp = aProps[i]; - - if (rProp.Name == aProp) - { - rProp.Value >>= nRet; - break; - } - } + auto pProp = std::find_if(aProps.begin(), aProps.end(), + [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); + if (pProp != aProps.end()) + pProp->Value >>= nRet; } } catch( const uno::Exception& ) @@ -6076,16 +6061,10 @@ sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp) { uno::Sequence aProps; xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; - for (int i = 0; i < aProps.getLength(); ++i) - { - const beans::PropertyValue& rProp = aProps[i]; - - if (rProp.Name == aProp) - { - rProp.Value >>= nRet; - break; - } - } + auto pPropVal = std::find_if(aProps.begin(), aProps.end(), + [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); + if (pPropVal != aProps.end()) + pPropVal->Value >>= nRet; } return nRet; diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index d9458ba468c2..d5d09a90dcbb 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -656,16 +656,14 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) xShapeProps->getPropertyValue("RotateAngle") >>= nRotation; css::beans::PropertyValues aGrabBag; - bool bContainsEffects = false; xShapeProps->getPropertyValue("InteropGrabBag") >>= aGrabBag; - for( sal_Int32 i = 0; i < aGrabBag.getLength(); ++i ) - { - // if the shape contains effects in the grab bag, we should not transform it - // in a XTextContent so those effects can be preserved - if( aGrabBag[i].Name == "EffectProperties" || aGrabBag[i].Name == "3DEffectProperties" || - aGrabBag[i].Name == "ArtisticEffectProperties" ) - bContainsEffects = true; - } + // if the shape contains effects in the grab bag, we should not transform it + // in a XTextContent so those effects can be preserved + bool bContainsEffects = std::any_of(aGrabBag.begin(), aGrabBag.end(), [](const auto& rProp) { + return rProp.Name == "EffectProperties" + || rProp.Name == "3DEffectProperties" + || rProp.Name == "ArtisticEffectProperties"; + }); xShapeProps->getPropertyValue("Shadow") >>= m_pImpl->bShadow; if (m_pImpl->bShadow) diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index 4afa77f94f05..666ee674cddc 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -74,20 +74,20 @@ static sal_Int32 lcl_findProperty( const uno::Sequence< beans::PropertyValue >& static void lcl_mergeProperties( uno::Sequence< beans::PropertyValue >& aSrc, uno::Sequence< beans::PropertyValue >& aDst ) { - for ( sal_Int32 i = 0, nSrcLen = aSrc.getLength( ); i < nSrcLen; i++ ) + for ( const auto& rProp : aSrc ) { // Look for the same property in aDst - sal_Int32 nPos = lcl_findProperty( aDst, aSrc[i].Name ); + sal_Int32 nPos = lcl_findProperty( aDst, rProp.Name ); if ( nPos >= 0 ) { // Replace the property value by the one in aSrc - aDst[nPos] = aSrc[i]; + aDst[nPos] = rProp; } else { // Simply add the new value aDst.realloc( aDst.getLength( ) + 1 ); - aDst[ aDst.getLength( ) - 1 ] = aSrc[i]; + aDst[ aDst.getLength( ) - 1 ] = rProp; } } } @@ -338,19 +338,18 @@ void ListLevel::AddParaProperties( uno::Sequence< beans::PropertyValue >* props OUString sParaLeftMargin = getPropertyName( PROP_PARA_LEFT_MARGIN ); - sal_Int32 nLen = aParaProps.getLength( ); - for ( sal_Int32 i = 0; i < nLen; i++ ) + for ( const auto& rParaProp : aParaProps ) { - if ( !hasFirstLineIndent && aParaProps[i].Name == sParaIndent ) + if ( !hasFirstLineIndent && rParaProp.Name == sParaIndent ) { aProps.realloc( aProps.getLength() + 1 ); - aProps[aProps.getLength( ) - 1] = aParaProps[i]; + aProps[aProps.getLength( ) - 1] = rParaProp; aProps[aProps.getLength( ) - 1].Name = sFirstLineIndent; } - else if ( !hasIndentAt && aParaProps[i].Name == sParaLeftMargin ) + else if ( !hasIndentAt && rParaProp.Name == sParaLeftMargin ) { aProps.realloc( aProps.getLength() + 1 ); - aProps[aProps.getLength( ) - 1] = aParaProps[i]; + aProps[aProps.getLength( ) - 1] = rParaProp; aProps[aProps.getLength( ) - 1].Name = sIndentAt; } @@ -547,11 +546,7 @@ void ListDef::CreateNumberingRules( DomainMapper& rDMapper, if( aAbsCharStyleProps.hasElements() ) { // Change the sequence into a vector - PropertyValueVector_t aStyleProps; - for ( sal_Int32 i = 0, nLen = aAbsCharStyleProps.getLength() ; i < nLen; i++ ) - { - aStyleProps.push_back( aAbsCharStyleProps[i] ); - } + auto aStyleProps = comphelper::sequenceToContainer(aAbsCharStyleProps); //create (or find) a character style containing the character // attributes of the symbol and apply it to the numbering level diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index cf5f3b4d3381..68f1f7119564 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -160,11 +160,8 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues( bool bChar { uno::Sequence< beans::PropertyValue > aSeq; rPropPair.second.getValue() >>= aSeq; - for ( sal_Int32 i = 0; i < aSeq.getLength(); ++i ) - { - pCellGrabBagValues[nCellGrabBagValue] = aSeq[i]; - ++nCellGrabBagValue; - } + std::copy(aSeq.begin(), aSeq.end(), pCellGrabBagValues + nCellGrabBagValue); + nCellGrabBagValue += aSeq.getLength(); } else { @@ -452,12 +449,11 @@ static OUString lcl_FindUnusedPageStyleName( const uno::Sequence< OUString >& rP // find the highest number x in each style with the name "DEFAULT_STYLE+x" and // return an incremented name - const OUString* pStyleNames = rPageStyleNames.getConstArray(); - for ( sal_Int32 nStyle = 0; nStyle < rPageStyleNames.getLength(); ++nStyle ) + for ( const auto& rStyleName : rPageStyleNames ) { - if ( pStyleNames[nStyle].startsWith( DEFAULT_STYLE ) ) + if ( rStyleName.startsWith( DEFAULT_STYLE ) ) { - sal_Int32 nIndex = pStyleNames[nStyle].copy( strlen( DEFAULT_STYLE ) ).toInt32(); + sal_Int32 nIndex = rStyleName.copy( strlen( DEFAULT_STYLE ) ).toInt32(); if ( nIndex > nMaxIndex ) nMaxIndex = nIndex; } @@ -1604,14 +1600,14 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) // Ignore write-only properties. static const std::set aBlacklist = { "FooterBackGraphicURL", "BackGraphicURL", "HeaderBackGraphicURL" }; - for ( int i = 0; i < propertyList.getLength(); ++i ) + for ( const auto& rProperty : propertyList ) { - if ( (propertyList[i].Attributes & beans::PropertyAttribute::READONLY) == 0 ) + if ( (rProperty.Attributes & beans::PropertyAttribute::READONLY) == 0 ) { - if (aBlacklist.find(propertyList[i].Name) == aBlacklist.end()) + if (aBlacklist.find(rProperty.Name) == aBlacklist.end()) evenOddStyle->setPropertyValue( - propertyList[i].Name, - pageProperties->getPropertyValue(propertyList[i].Name)); + rProperty.Name, + pageProperties->getPropertyValue(rProperty.Name)); } } evenOddStyle->setPropertyValue( "FollowStyle", uno::makeAny( *pageStyle ) ); diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx index eef56e7db718..3e41aa93404e 100644 --- a/writerfilter/source/dmapper/StyleSheetTable.cxx +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -360,10 +360,8 @@ void StyleSheetTable_Impl::SetPropertiesToDefault(const uno::Reference aProperties = xPropertySetInfo->getProperties(); std::vector aPropertyNames; aPropertyNames.reserve(aProperties.getLength()); - for (sal_Int32 i = 0; i < aProperties.getLength(); ++i) - { - aPropertyNames.push_back(aProperties[i].Name); - } + std::transform(aProperties.begin(), aProperties.end(), std::back_inserter(aPropertyNames), + [](const beans::Property& rProp) { return rProp.Name; }); uno::Reference xPropertyState(xStyle, uno::UNO_QUERY); uno::Sequence aStates = xPropertyState->getPropertyStates(comphelper::containerToSequence(aPropertyNames)); @@ -1479,11 +1477,11 @@ void StyleSheetTable::applyDefaults(bool bParaProperties) xParagraphStyles->getByName("Paragraph style") >>= xDefault; uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues(); - for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i ) + for( const auto& rPropValue : aPropValues ) { try { - xDefault->setPropertyValue(aPropValues[i].Name, aPropValues[i].Value); + xDefault->setPropertyValue(rPropValue.Name, rPropValue.Value); } catch( const uno::Exception& ) { @@ -1494,11 +1492,11 @@ void StyleSheetTable::applyDefaults(bool bParaProperties) if( !bParaProperties && m_pImpl->m_pDefaultCharProps.get()) { uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues(); - for( sal_Int32 i = 0; i < aPropValues.getLength(); ++i ) + for( const auto& rPropValue : aPropValues ) { try { - m_pImpl->m_xTextDefaults->setPropertyValue( aPropValues[i].Name, aPropValues[i].Value ); + m_pImpl->m_xTextDefaults->setPropertyValue( rPropValue.Name, rPropValue.Value ); } catch( const uno::Exception& ) { @@ -1528,11 +1526,10 @@ OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProp //search for all character styles with the name sListLabel + sal_Int32 nStyleFound = 0; uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames(); - const OUString* pStyleNames = aStyleNames.getConstArray(); - for( sal_Int32 nStyle = 0; nStyle < aStyleNames.getLength(); ++nStyle ) + for( const auto& rStyleName : aStyleNames ) { OUString sSuffix; - if( pStyleNames[nStyle].startsWith( cListLabel, &sSuffix ) ) + if( rStyleName.startsWith( cListLabel, &sSuffix ) ) { sal_Int32 nSuffix = sSuffix.toInt32(); if( nSuffix > 0 && nSuffix > nStyleFound ) diff --git a/writerfilter/source/dmapper/ThemeTable.cxx b/writerfilter/source/dmapper/ThemeTable.cxx index 2eac8d818112..754a278ea082 100644 --- a/writerfilter/source/dmapper/ThemeTable.cxx +++ b/writerfilter/source/dmapper/ThemeTable.cxx @@ -243,13 +243,13 @@ const OUString ThemeTable::getFontNameForTheme(const Id id) const void ThemeTable::setThemeFontLangProperties(const uno::Sequence& aPropSeq) { - for (sal_Int32 i = 0 ; i < aPropSeq.getLength() ; i ++) + for (const auto& rProp : aPropSeq) { OUString sLocaleName; - aPropSeq.getConstArray()[i].Value >>= sLocaleName; - if (aPropSeq.getConstArray()[i].Name == "eastAsia") + rProp.Value >>= sLocaleName; + if (rProp.Name == "eastAsia") m_pImpl->m_themeFontLangEastAsia = fromLocaleToScriptTag(sLocaleName); - if (aPropSeq.getConstArray()[i].Name == "bidi") + if (rProp.Name == "bidi") m_pImpl->m_themeFontLangBidi = fromLocaleToScriptTag(sLocaleName); } diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 0d00b0eff303..9601a5311923 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -560,12 +560,10 @@ void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) uno::Sequence> aSeqs = xRelationshipAccess->getAllRelationships(); std::vector> aCustomXmlDomList; std::vector> aCustomXmlDomPropsList; - for (sal_Int32 j = 0; j < aSeqs.getLength(); j++) + for (const uno::Sequence& aSeq : aSeqs) { - const uno::Sequence& aSeq = aSeqs[j]; - for (sal_Int32 i = 0; i < aSeq.getLength(); i++) + for (const beans::StringPair& aPair : aSeq) { - const beans::StringPair& aPair = aSeq[i]; // Need to resolve only customxml files from document relationships. // Skipping other files. if (aPair.Second == sCustomType || @@ -629,10 +627,9 @@ void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); std::vector< uno::Sequence > aGlossaryDomList; - for (sal_Int32 j = 0; j < aSeqs.getLength(); j++) + for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) { OOXMLStream::Pointer_t gStream; - uno::Sequence< beans::StringPair > aSeq = aSeqs[j]; //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target if (aSeq.getLength() < 3) { @@ -728,12 +725,10 @@ void OOXMLDocumentImpl::resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pS bool bHeaderFooterFound = false; OOXMLStream::StreamType_t streamType = OOXMLStream::UNKNOWN; uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); - for (sal_Int32 j = 0; j < aSeqs.getLength(); j++) + for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) { - uno::Sequence< beans::StringPair > aSeq = aSeqs[j]; - for (sal_Int32 i = 0; i < aSeq.getLength(); i++) + for (const beans::StringPair& aPair : aSeq) { - beans::StringPair aPair = aSeq[i]; if (aPair.Second == sChartType || aPair.Second == sChartTypeStrict) { diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx index e4e53acc8f1f..cd9426fe1a41 100644 --- a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx @@ -96,15 +96,13 @@ bool OOXMLStreamImpl::lcl_getTarget(const uno::Reference >aSeqs = xRelationshipAccess->getAllRelationships(); - for (sal_Int32 i = 0; i < aSeqs.getLength(); ++i) + for (const uno::Sequence& rSeq : aSeqs) { - const uno::Sequence& rSeq = aSeqs[i]; OUString aId; OUString aTarget; bool bExternal = false; - for (sal_Int32 j = 0; j < rSeq.getLength(); ++j) + for (const beans::StringPair& rPair : rSeq) { - const beans::StringPair& rPair = rSeq[j]; if (rPair.First == sId) aId = rPair.Second; else if (rPair.First == sTarget) @@ -262,16 +260,12 @@ bool OOXMLStreamImpl::lcl_getTarget(const uno::Reference >aSeqs = xRelationshipAccess->getAllRelationships(); - for (sal_Int32 j = 0; j < aSeqs.getLength(); j++) + for (const uno::Sequence< beans::StringPair > &rSeq : aSeqs) { - const uno::Sequence< beans::StringPair > &rSeq = aSeqs[j]; - bool bExternalTarget = false; OUString sMyTarget; - for (sal_Int32 i = 0; i < rSeq.getLength(); i++) + for (const beans::StringPair &rPair : rSeq) { - const beans::StringPair &rPair = rSeq[i]; - if (rPair.First == sType && ( rPair.Second == sStreamType || rPair.Second == sStreamTypeStrict )) @@ -301,7 +295,6 @@ bool OOXMLStreamImpl::lcl_getTarget(const uno::Reference