Kaydet (Commit) b8ca608a authored tarafından Matteo Casalin's avatar Matteo Casalin

Use more proper integer types and range-for loops

Change-Id: Ie32cef06ecb742e8545e4081d7f99181f5289397
üst 721024be
...@@ -45,17 +45,16 @@ ...@@ -45,17 +45,16 @@
sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const
{ {
const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size();
if(nResId == USHRT_MAX) if(nResId == USHRT_MAX)
{ {
if(!bUsed) if(!bUsed)
return nSize; return static_cast<sal_uInt16>(pFldTypes->size());
sal_uInt16 nUsed = 0; sal_uInt16 nUsed = 0;
for ( sal_uInt16 i = 0; i < nSize; i++ ) for ( const auto pFldType : *pFldTypes )
{ {
if(IsUsed(*(*pFldTypes)[i])) if(IsUsed(*pFldType))
nUsed++; nUsed++;
} }
return nUsed; return nUsed;
...@@ -63,10 +62,10 @@ sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const ...@@ -63,10 +62,10 @@ sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const
// all types with the same ResId // all types with the same ResId
sal_uInt16 nIdx = 0; sal_uInt16 nIdx = 0;
for(sal_uInt16 i = 0; i < nSize; ++i) for(const auto pFldType : *pFldTypes)
{ // same ResId -> increment index {
SwFieldType& rFldType = *((*pFldTypes)[i]); // same ResId -> increment index
if(rFldType.Which() == nResId) if(pFldType->Which() == nResId)
nIdx++; nIdx++;
} }
return nIdx; return nIdx;
...@@ -76,30 +75,29 @@ sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const ...@@ -76,30 +75,29 @@ sal_uInt16 SwEditShell::GetFldTypeCount(sal_uInt16 nResId, bool bUsed ) const
SwFieldType* SwEditShell::GetFldType(sal_uInt16 nFld, sal_uInt16 nResId, bool bUsed ) const SwFieldType* SwEditShell::GetFldType(sal_uInt16 nFld, sal_uInt16 nResId, bool bUsed ) const
{ {
const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size();
if(nResId == USHRT_MAX && nFld < nSize) if(nResId == USHRT_MAX && nFld < pFldTypes->size())
{ {
if(!bUsed) if(!bUsed)
return (*pFldTypes)[nFld]; return (*pFldTypes)[nFld];
sal_uInt16 i, nUsed = 0; SwFldTypes::size_type nUsed = 0;
for ( i = 0; i < nSize; i++ ) for ( const auto pFldType : *pFldTypes )
{ {
if(IsUsed(*(*pFldTypes)[i])) if(IsUsed(*pFldType))
{ {
if(nUsed == nFld) if(nUsed == nFld)
break; return pFldType;
nUsed++; nUsed++;
} }
} }
return i < nSize ? (*pFldTypes)[i] : 0; return nullptr;
} }
sal_uInt16 nIdx = 0; sal_uInt16 nIdx = 0;
for(sal_uInt16 i = 0; i < nSize; ++i) for(const auto pFldType : *pFldTypes)
{ // same ResId -> increment index {
SwFieldType* pFldType = (*pFldTypes)[i]; // same ResId -> increment index
if(pFldType->Which() == nResId) if(pFldType->Which() == nResId)
{ {
if (!bUsed || IsUsed(*pFldType)) if (!bUsed || IsUsed(*pFldType))
...@@ -129,12 +127,11 @@ void SwEditShell::RemoveFldType(sal_uInt16 nFld, sal_uInt16 nResId) ...@@ -129,12 +127,11 @@ void SwEditShell::RemoveFldType(sal_uInt16 nFld, sal_uInt16 nResId)
} }
const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size();
sal_uInt16 nIdx = 0; sal_uInt16 nIdx = 0;
for( sal_uInt16 i = 0; i < nSize; ++i ) const SwFldTypes::size_type nSize = pFldTypes->size();
for( SwFldTypes::size_type i; i < nSize; ++i )
// Gleiche ResId -> Index erhoehen // Gleiche ResId -> Index erhoehen
if( (*pFldTypes)[i]->Which() == nResId && if( (*pFldTypes)[i]->Which() == nResId && nIdx++ == nFld )
nIdx++ == nFld )
{ {
GetDoc()->getIDocumentFieldsAccess().RemoveFldType( i ); GetDoc()->getIDocumentFieldsAccess().RemoveFldType( i );
return; return;
...@@ -145,12 +142,12 @@ void SwEditShell::RemoveFldType(sal_uInt16 nFld, sal_uInt16 nResId) ...@@ -145,12 +142,12 @@ void SwEditShell::RemoveFldType(sal_uInt16 nFld, sal_uInt16 nResId)
void SwEditShell::RemoveFldType(sal_uInt16 nResId, const OUString& rStr) void SwEditShell::RemoveFldType(sal_uInt16 nResId, const OUString& rStr)
{ {
const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes* pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size(); const SwFldTypes::size_type nSize = pFldTypes->size();
const CharClass& rCC = GetAppCharClass(); const CharClass& rCC = GetAppCharClass();
OUString aTmp( rCC.lowercase( rStr )); OUString aTmp( rCC.lowercase( rStr ));
for(sal_uInt16 i = 0; i < nSize; ++i) for(SwFldTypes::size_type i = 0; i < nSize; ++i)
{ {
// same ResId -> increment index // same ResId -> increment index
SwFieldType* pFldType = (*pFldTypes)[i]; SwFieldType* pFldType = (*pFldTypes)[i];
...@@ -434,21 +431,18 @@ void SwEditShell::ChangeAuthorityData(const SwAuthEntry* pNewData) ...@@ -434,21 +431,18 @@ void SwEditShell::ChangeAuthorityData(const SwAuthEntry* pNewData)
bool SwEditShell::IsAnyDatabaseFieldInDoc()const bool SwEditShell::IsAnyDatabaseFieldInDoc()const
{ {
const SwFldTypes * pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes * pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size(); for(const auto pFldType : *pFldTypes)
for(sal_uInt16 i = 0; i < nSize; ++i)
{ {
SwFieldType& rFldType = *((*pFldTypes)[i]); if(IsUsed(*pFldType))
sal_uInt16 nWhich = rFldType.Which();
if(IsUsed(rFldType))
{ {
switch(nWhich) switch(pFldType->Which())
{ {
case RES_DBFLD: case RES_DBFLD:
case RES_DBNEXTSETFLD: case RES_DBNEXTSETFLD:
case RES_DBNUMSETFLD: case RES_DBNUMSETFLD:
case RES_DBSETNUMBERFLD: case RES_DBSETNUMBERFLD:
{ {
SwIterator<SwFmtFld,SwFieldType> aIter( rFldType ); SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
SwFmtFld* pFld = aIter.First(); SwFmtFld* pFld = aIter.First();
while(pFld) while(pFld)
{ {
......
...@@ -38,20 +38,17 @@ using namespace com::sun::star; ...@@ -38,20 +38,17 @@ using namespace com::sun::star;
bool SwEditShell::IsFieldDataSourceAvailable(OUString& rUsedDataSource) const bool SwEditShell::IsFieldDataSourceAvailable(OUString& rUsedDataSource) const
{ {
const SwFldTypes * pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes(); const SwFldTypes * pFldTypes = GetDoc()->getIDocumentFieldsAccess().GetFldTypes();
const sal_uInt16 nSize = pFldTypes->size();
uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() ); uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext); uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
for(sal_uInt16 i = 0; i < nSize; ++i) for(const auto pFldType : *pFldTypes)
{ {
SwFieldType& rFldType = *((*pFldTypes)[i]); if(IsUsed(*pFldType))
sal_uInt16 nWhich = rFldType.Which();
if(IsUsed(rFldType))
{ {
switch(nWhich) switch(pFldType->Which())
{ {
case RES_DBFLD: case RES_DBFLD:
{ {
SwIterator<SwFmtFld,SwFieldType> aIter( rFldType ); SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
SwFmtFld* pFmtFld = aIter.First(); SwFmtFld* pFmtFld = aIter.First();
while(pFmtFld) while(pFmtFld)
{ {
......
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