makes RTFSprms::set clearer
Change-Id: Ic1aab40c8a4abdd73c616b2faaf95ef183fa2e38 Signed-off-by: Adrien Ollier <adr.ollier@hotmail.fr> Reviewed-on: https://gerrit.libreoffice.org/77556 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
committed by
Mike Kaganski
parent
5ce360777a
commit
a56f2d0168
@@ -103,32 +103,38 @@ void RTFSprms::set(Id nKeyword, const RTFValue::Pointer_t& pValue, RTFOverwrite
|
||||
{
|
||||
ensureCopyBeforeWrite();
|
||||
|
||||
if (eOverwrite == RTFOverwrite::YES_PREPEND)
|
||||
switch (eOverwrite)
|
||||
{
|
||||
auto it = std::remove_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword });
|
||||
m_pSprms->erase(it, m_pSprms->end());
|
||||
m_pSprms->insert(m_pSprms->begin(), std::make_pair(nKeyword, pValue));
|
||||
return;
|
||||
case RTFOverwrite::YES_PREPEND:
|
||||
{
|
||||
m_pSprms->erase(
|
||||
std::remove_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword }),
|
||||
m_pSprms->end());
|
||||
m_pSprms->emplace(m_pSprms->cbegin(), nKeyword, pValue);
|
||||
break;
|
||||
}
|
||||
case RTFOverwrite::YES:
|
||||
{
|
||||
auto it
|
||||
= std::find_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword });
|
||||
if (it != m_pSprms->end())
|
||||
it->second = pValue;
|
||||
else
|
||||
m_pSprms->emplace_back(nKeyword, pValue);
|
||||
break;
|
||||
}
|
||||
case RTFOverwrite::NO_IGNORE:
|
||||
{
|
||||
if (std::none_of(m_pSprms->cbegin(), m_pSprms->cend(), RTFSprms_compare{ nKeyword }))
|
||||
m_pSprms->emplace_back(nKeyword, pValue);
|
||||
break;
|
||||
}
|
||||
case RTFOverwrite::NO_APPEND:
|
||||
{
|
||||
m_pSprms->emplace_back(nKeyword, pValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool bFound = false;
|
||||
if (eOverwrite == RTFOverwrite::YES || eOverwrite == RTFOverwrite::NO_IGNORE)
|
||||
{
|
||||
for (auto& rSprm : *m_pSprms)
|
||||
if (rSprm.first == nKeyword)
|
||||
{
|
||||
if (eOverwrite == RTFOverwrite::YES)
|
||||
{
|
||||
rSprm.second = pValue;
|
||||
return;
|
||||
}
|
||||
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (eOverwrite == RTFOverwrite::NO_APPEND || !bFound)
|
||||
m_pSprms->push_back(std::make_pair(nKeyword, pValue));
|
||||
}
|
||||
|
||||
bool RTFSprms::erase(Id nKeyword)
|
||||
|
Reference in New Issue
Block a user