Kaydet (Commit) 51496690 authored tarafından Miklos Vajna's avatar Miklos Vajna

writerfilter: use auto where it improves code readability

for (std::vector< std::pair<Id, RTFValue::Pointer_t> >::const_iterator i = m_pSprms->begin(); i != m_pSprms->end(); ++i)

vs

for (auto& rSprm : *m_pSprms)

and so on.

Change-Id: I2b4d975af096fb59815b074cbcb9934bead9e6f0
Reviewed-on: https://gerrit.libreoffice.org/25350Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst a4e8419c
......@@ -917,8 +917,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
}
m_aStates.top().aDrawingObject.xPropertySet.set(m_aStates.top().aDrawingObject.xShape, uno::UNO_QUERY);
std::vector<beans::PropertyValue>& rPendingProperties = m_aStates.top().aDrawingObject.aPendingProperties;
for (std::vector<beans::PropertyValue>::iterator i = rPendingProperties.begin(); i != rPendingProperties.end(); ++i)
m_aStates.top().aDrawingObject.xPropertySet->setPropertyValue(i->Name, i->Value);
for (auto& rPendingProperty : rPendingProperties)
m_aStates.top().aDrawingObject.xPropertySet->setPropertyValue(rPendingProperty.Name, rPendingProperty.Value);
m_pSdrImport->resolveDhgt(m_aStates.top().aDrawingObject.xPropertySet, m_aStates.top().aDrawingObject.nDhgt, /*bOldStyle=*/true);
}
break;
......
......@@ -419,27 +419,27 @@ void RTFDocumentImpl::setNeedSect(bool bNeedSect)
/// Copy rProps to rStyleAttributes and rStyleSprms, but in case of nested sprms, copy their children as toplevel sprms/attributes.
static void lcl_copyFlatten(RTFReferenceProperties& rProps, RTFSprms& rStyleAttributes, RTFSprms& rStyleSprms)
{
for (RTFSprms::Iterator_t it = rProps.getSprms().begin(); it != rProps.getSprms().end(); ++it)
for (auto& rSprm : rProps.getSprms())
{
// createStyleProperties() puts properties to rPr, but here we need a flat list.
if (it->first == NS_ooxml::LN_CT_Style_rPr)
if (rSprm.first == NS_ooxml::LN_CT_Style_rPr)
{
// rPr can have both attributes and SPRMs, copy over both types.
RTFSprms& rRPrSprms = it->second->getSprms();
for (RTFSprms::Iterator_t itRPrSprm = rRPrSprms.begin(); itRPrSprm != rRPrSprms.end(); ++itRPrSprm)
rStyleSprms.set(itRPrSprm->first, itRPrSprm->second);
RTFSprms& rRPrSprms = rSprm.second->getSprms();
for (auto& rRPrSprm : rRPrSprms)
rStyleSprms.set(rRPrSprm.first, rRPrSprm.second);
RTFSprms& rRPrAttributes = it->second->getAttributes();
for (RTFSprms::Iterator_t itRPrAttribute = rRPrAttributes.begin(); itRPrAttribute != rRPrAttributes.end(); ++itRPrAttribute)
rStyleAttributes.set(itRPrAttribute->first, itRPrAttribute->second);
RTFSprms& rRPrAttributes = rSprm.second->getAttributes();
for (auto& rRPrAttribute : rRPrAttributes)
rStyleAttributes.set(rRPrAttribute.first, rRPrAttribute.second);
}
else
rStyleSprms.set(it->first, it->second);
rStyleSprms.set(rSprm.first, rSprm.second);
}
RTFSprms& rAttributes = rProps.getAttributes();
for (RTFSprms::Iterator_t itAttr = rAttributes.begin(); itAttr != rAttributes.end(); ++itAttr)
rStyleAttributes.set(itAttr->first, itAttr->second);
for (auto& rAttribute : rAttributes)
rStyleAttributes.set(rAttribute.first, rAttribute.second);
}
writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms)
......@@ -447,14 +447,14 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT
int nStyle = 0;
if (!m_aStates.empty())
nStyle = m_aStates.top().nCurrentStyleIndex;
RTFReferenceTable::Entries_t::iterator it = m_aStyleTableEntries.find(nStyle);
auto it = m_aStyleTableEntries.find(nStyle);
if (it != m_aStyleTableEntries.end())
{
RTFReferenceProperties& rProps = *static_cast<RTFReferenceProperties*>(it->second.get());
// cloneAndDeduplicate() wants to know about only a single "style", so
// let's merge paragraph and character style properties here.
RTFReferenceTable::Entries_t::iterator itChar = m_aStyleTableEntries.end();
auto itChar = m_aStyleTableEntries.end();
if (!m_aStates.empty())
{
int nCharStyle = m_aStates.top().nCurrentCharacterStyleIndex;
......@@ -654,7 +654,7 @@ rtl_TextEncoding RTFDocumentImpl::getEncoding(int nFontIndex)
{
if (!m_pSuperstream)
{
std::map<int, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(nFontIndex);
auto it = m_aFontEncodings.find(nFontIndex);
if (it != m_aFontEncodings.end())
// We have a font encoding associated to this font.
return it->second;
......@@ -949,9 +949,9 @@ void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing::XS
auto pExtentValue = std::make_shared<RTFValue>(aExtentAttributes);
// docpr sprm
RTFSprms aDocprAttributes;
for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterAttributes.begin(); i != m_aStates.top().aCharacterAttributes.end(); ++i)
if (i->first == NS_ooxml::LN_CT_NonVisualDrawingProps_name || i->first == NS_ooxml::LN_CT_NonVisualDrawingProps_descr)
aDocprAttributes.set(i->first, i->second);
for (auto& rCharacterAttribute : m_aStates.top().aCharacterAttributes)
if (rCharacterAttribute.first == NS_ooxml::LN_CT_NonVisualDrawingProps_name || rCharacterAttribute.first == NS_ooxml::LN_CT_NonVisualDrawingProps_descr)
aDocprAttributes.set(rCharacterAttribute.first, rCharacterAttribute.second);
auto pDocprValue = std::make_shared<RTFValue>(aDocprAttributes);
if (bInline)
{
......@@ -974,23 +974,23 @@ void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing::XS
RTFSprms aAnchorWrapAttributes;
m_aStates.top().aShape.aAnchorAttributes.set(NS_ooxml::LN_CT_Anchor_behindDoc, std::make_shared<RTFValue>((m_aStates.top().aShape.bInBackground) ? 1 : 0));
RTFSprms aAnchorSprms;
for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterAttributes.begin(); i != m_aStates.top().aCharacterAttributes.end(); ++i)
for (auto& rCharacterAttribute : m_aStates.top().aCharacterAttributes)
{
if (i->first == NS_ooxml::LN_CT_WrapSquare_wrapText)
aAnchorWrapAttributes.set(i->first, i->second);
if (rCharacterAttribute.first == NS_ooxml::LN_CT_WrapSquare_wrapText)
aAnchorWrapAttributes.set(rCharacterAttribute.first, rCharacterAttribute.second);
}
sal_Int32 nWrap = -1;
for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterSprms.begin(); i != m_aStates.top().aCharacterSprms.end(); ++i)
for (auto& rCharacterSprm : m_aStates.top().aCharacterSprms)
{
if (i->first == NS_ooxml::LN_EG_WrapType_wrapNone || i->first == NS_ooxml::LN_EG_WrapType_wrapTight)
if (rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapNone || rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapTight)
{
nWrap = i->first;
nWrap = rCharacterSprm.first;
// If there is a wrap polygon prepared by RTFSdrImport, pick it up here.
if (i->first == NS_ooxml::LN_EG_WrapType_wrapTight && !m_aStates.top().aShape.aWrapPolygonSprms.empty())
i->second->getSprms().set(NS_ooxml::LN_CT_WrapTight_wrapPolygon, std::make_shared<RTFValue>(RTFSprms(), m_aStates.top().aShape.aWrapPolygonSprms));
if (rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapTight && !m_aStates.top().aShape.aWrapPolygonSprms.empty())
rCharacterSprm.second->getSprms().set(NS_ooxml::LN_CT_WrapTight_wrapPolygon, std::make_shared<RTFValue>(RTFSprms(), m_aStates.top().aShape.aWrapPolygonSprms));
aAnchorSprms.set(i->first, i->second);
aAnchorSprms.set(rCharacterSprm.first, rCharacterSprm.second);
}
}
auto pAnchorWrapValue = std::make_shared<RTFValue>(aAnchorWrapAttributes);
......@@ -1237,7 +1237,7 @@ void RTFDocumentImpl::text(OUString& rString)
//See fdo#47347 initial invalid font entry properties are inserted first,
//so when we attempt to insert the correct ones, there's already an
//entry in the map for them, so the new ones aren't inserted.
RTFReferenceTable::Entries_t::iterator lb = m_aFontTableEntries.lower_bound(m_nCurrentFontIndex);
auto lb = m_aFontTableEntries.lower_bound(m_nCurrentFontIndex);
if (lb != m_aFontTableEntries.end() && !(m_aFontTableEntries.key_comp()(m_nCurrentFontIndex, lb->first)))
lb->second = pProp;
else
......@@ -1539,9 +1539,9 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer,
bool findPropertyName(const std::vector<beans::PropertyValue>& rProperties, const OUString& rName)
{
for (std::vector<beans::PropertyValue>::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it)
for (auto& rProperty : rProperties)
{
if (it->Name == rName)
if (rProperty.Name == rName)
return true;
}
return false;
......@@ -1918,8 +1918,8 @@ RTFError RTFDocumentImpl::popState()
}
break;
case Destination::LISTENTRY:
for (RTFSprms::Iterator_t i = aState.aListLevelEntries.begin(); i != aState.aListLevelEntries.end(); ++i)
aState.aTableSprms.set(i->first, i->second, RTFOverwrite::NO_APPEND);
for (auto& rListLevelEntry : aState.aListLevelEntries)
aState.aTableSprms.set(rListLevelEntry.first, rListLevelEntry.second, RTFOverwrite::NO_APPEND);
break;
case Destination::FIELDINSTRUCTION:
{
......@@ -2071,8 +2071,8 @@ RTFError RTFDocumentImpl::popState()
else if (aState.bInShapeGroup && !aState.bInShape)
{
// End of a groupshape, as we're in shapegroup, but not in a real shape.
for (std::vector< std::pair<OUString, OUString> >::iterator i = aState.aShape.aGroupProperties.begin(); i != aState.aShape.aGroupProperties.end(); ++i)
m_pSdrImport->appendGroupProperty(i->first, i->second);
for (auto& rGroupProperty : aState.aShape.aGroupProperties)
m_pSdrImport->appendGroupProperty(rGroupProperty.first, rGroupProperty.second);
aState.aShape.aGroupProperties.clear();
}
break;
......
......@@ -30,11 +30,11 @@ RTFReferenceProperties::~RTFReferenceProperties() = default;
void RTFReferenceProperties::resolve(Properties& rHandler)
{
for (RTFSprms::Iterator_t i = m_aAttributes.begin(); i != m_aAttributes.end(); ++i)
rHandler.attribute(i->first, *i->second.get());
for (RTFSprms::Iterator_t i = m_aSprms.begin(); i != m_aSprms.end(); ++i)
for (auto& rAttribute : m_aAttributes)
rHandler.attribute(rAttribute.first, *rAttribute.second.get());
for (auto& rSprm : m_aSprms)
{
RTFSprm aSprm(i->first, i->second);
RTFSprm aSprm(rSprm.first, rSprm.second);
rHandler.sprm(aSprm);
}
}
......
......@@ -23,8 +23,8 @@ RTFReferenceTable::~RTFReferenceTable() = default;
void RTFReferenceTable::resolve(Table& rHandler)
{
for (Entries_t::const_iterator i = m_aEntries.begin(); i != m_aEntries.end(); ++i)
rHandler.entry(i->first, i->second);
for (auto& rEntry : m_aEntries)
rHandler.entry(rEntry.first, rEntry.second);
}
} // namespace rtftok
......
......@@ -74,13 +74,13 @@ RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst, bool bForWrite)
if (bForWrite)
ensureCopyBeforeWrite();
for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
if (i->first == nKeyword)
for (auto& rSprm : *m_pSprms)
if (rSprm.first == nKeyword)
{
if (bFirst)
return i->second;
return rSprm.second;
else
pValue = i->second;
pValue = rSprm.second;
}
return pValue;
}
......@@ -91,12 +91,12 @@ void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwr
bool bFound = false;
if (eOverwrite == RTFOverwrite::YES || eOverwrite == RTFOverwrite::NO_IGNORE)
{
for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
if (i->first == nKeyword)
for (auto& rSprm : *m_pSprms)
if (rSprm.first == nKeyword)
{
if (eOverwrite == RTFOverwrite::YES)
{
i->second = pValue;
rSprm.second = pValue;
return;
}
else
......@@ -113,7 +113,7 @@ void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwr
bool RTFSprms::erase(Id nKeyword)
{
ensureCopyBeforeWrite();
for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
for (auto i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
{
if (i->first == nKeyword)
{
......@@ -127,7 +127,7 @@ bool RTFSprms::erase(Id nKeyword)
void RTFSprms::eraseLast(Id nKeyword)
{
ensureCopyBeforeWrite();
for (RTFSprms::ReverseIterator_t i = m_pSprms->rbegin(); i != m_pSprms->rend(); ++i)
for (auto i = m_pSprms->rbegin(); i != m_pSprms->rend(); ++i)
{
if (i->first == nKeyword)
{
......@@ -158,42 +158,37 @@ RTFSprms RTFSprms::cloneAndDeduplicate(RTFSprms& rReference) const
// Note: apparently some attributes are set with OVERWRITE_NO_APPEND;
// it is probably a bad idea to mess with those in any way here?
for (RTFSprms::Iterator_t i = rReference.begin(); i != rReference.end(); ++i)
for (auto& rSprm : rReference)
{
RTFValue::Pointer_t const pValue(ret.find(i->first));
RTFValue::Pointer_t const pValue(ret.find(rSprm.first));
if (pValue)
{
if (i->second->equals(*pValue))
if (rSprm.second->equals(*pValue))
{
ret.erase(i->first); // duplicate to style
ret.erase(rSprm.first); // duplicate to style
}
else if (!i->second->getSprms().empty() || !i->second->getAttributes().empty())
else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty())
{
RTFSprms const sprms(
pValue->getSprms().cloneAndDeduplicate(i->second->getSprms()));
RTFSprms const attributes(
pValue->getAttributes().cloneAndDeduplicate(i->second->getAttributes()));
ret.set(i->first, RTFValue::Pointer_t(
pValue->CloneWithSprms(attributes, sprms)));
RTFSprms const sprms(pValue->getSprms().cloneAndDeduplicate(rSprm.second->getSprms()));
RTFSprms const attributes(pValue->getAttributes().cloneAndDeduplicate(rSprm.second->getAttributes()));
ret.set(rSprm.first, RTFValue::Pointer_t(pValue->CloneWithSprms(attributes, sprms)));
}
}
else
{
// not found - try to override style with default
RTFValue::Pointer_t const pDefault(getDefaultSPRM(i->first));
RTFValue::Pointer_t const pDefault(getDefaultSPRM(rSprm.first));
if (pDefault)
{
ret.set(i->first, pDefault);
ret.set(rSprm.first, pDefault);
}
else if (!i->second->getSprms().empty() || !i->second->getAttributes().empty())
else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty())
{
RTFSprms const sprms(
RTFSprms().cloneAndDeduplicate(i->second->getSprms()));
RTFSprms const attributes(
RTFSprms().cloneAndDeduplicate(i->second->getAttributes()));
RTFSprms const sprms(RTFSprms().cloneAndDeduplicate(rSprm.second->getSprms()));
RTFSprms const attributes(RTFSprms().cloneAndDeduplicate(rSprm.second->getAttributes()));
if (!sprms.empty() || !attributes.empty())
{
ret.set(i->first, std::make_shared<RTFValue>(attributes, sprms));
ret.set(rSprm.first, std::make_shared<RTFValue>(attributes, sprms));
}
}
}
......@@ -203,9 +198,8 @@ RTFSprms RTFSprms::cloneAndDeduplicate(RTFSprms& rReference) const
bool RTFSprms::equals(RTFValue& rOther)
{
RTFSprms::Iterator_t i = m_pSprms->begin();
while (i != m_pSprms->end())
if (!i->second->equals(rOther))
for (auto& rSprm : *m_pSprms)
if (!rSprm.second->equals(rOther))
return false;
return true;
}
......@@ -215,8 +209,8 @@ void RTFSprms::ensureCopyBeforeWrite()
if (m_pSprms->m_nRefCount > 1)
{
boost::intrusive_ptr<RTFSprmsImpl> pClone(new RTFSprmsImpl());
for (std::vector< std::pair<Id, RTFValue::Pointer_t> >::const_iterator i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
pClone->push_back(std::make_pair(i->first, RTFValue::Pointer_t(i->second->Clone())));
for (auto& rSprm : *m_pSprms)
pClone->push_back(std::make_pair(rSprm.first, RTFValue::Pointer_t(rSprm.second->Clone())));
m_pSprms = pClone;
}
}
......
......@@ -268,7 +268,7 @@ RTFError RTFTokenizer::resolveKeyword()
bool RTFTokenizer::lookupMathKeyword(RTFMathSymbol& rSymbol)
{
std::vector<RTFMathSymbol>::iterator low = std::lower_bound(s_aRTFMathControlWords.begin(), s_aRTFMathControlWords.end(), rSymbol);
auto low = std::lower_bound(s_aRTFMathControlWords.begin(), s_aRTFMathControlWords.end(), rSymbol);
int i = low - s_aRTFMathControlWords.begin();
if (low == s_aRTFMathControlWords.end() || rSymbol < *low)
return false;
......@@ -290,7 +290,7 @@ RTFError RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nPara
"' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'");
RTFSymbol aSymbol;
aSymbol.sKeyword = rKeyword.getStr();
std::vector<RTFSymbol>::iterator low = std::lower_bound(s_aRTFControlWords.begin(), s_aRTFControlWords.end(), aSymbol);
auto low = std::lower_bound(s_aRTFControlWords.begin(), s_aRTFControlWords.end(), aSymbol);
int i = low - s_aRTFControlWords.begin();
if (low == s_aRTFControlWords.end() || aSymbol < *low)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment