diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-07-30 10:42:13 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-07-30 12:47:51 +0100 |
commit | 8f2d9efa736a33d7812118e53eec130101d049b3 (patch) | |
tree | fde8b775e3436b9f321be3ea0f1c870f61af4f50 | |
parent | aec9bb52ab50a26fe635ff1036f7fe6882ca74dd (diff) |
split foul SwSortElement::operator< into a keycompare method
Change-Id: Iefbab73478dd417a45d0a3799d029708b8e892d5
-rw-r--r-- | sw/source/core/doc/docsort.cxx | 80 | ||||
-rw-r--r-- | sw/source/core/inc/docsort.hxx | 2 |
2 files changed, 45 insertions, 37 deletions
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index a76425da66c5..88d791ab53c1 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -133,6 +133,44 @@ double SwSortElement::StrToDouble( const String& rStr ) const return nRet; } +int SwSortElement::keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const +{ + int nCmp = 0; + // The actual comparison + const SwSortElement *pOrig, *pCmp; + + const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ]; + if( pSrtKey->eSortOrder == SRT_ASCENDING ) + pOrig = this, pCmp = &rCmp; + else + pOrig = &rCmp, pCmp = this; + + if( pSrtKey->bIsNumeric ) + { + double n1 = pOrig->GetValue( nKey ); + double n2 = pCmp->GetValue( nKey ); + + nCmp = n1 < n2 ? -1 : n1 == n2 ? 0 : 1; + } + else + { + if( !pLastAlgorithm || *pLastAlgorithm != pSrtKey->sSortType ) + { + if( pLastAlgorithm ) + *pLastAlgorithm = pSrtKey->sSortType; + else + pLastAlgorithm = new String( pSrtKey->sSortType ); + pSortCollator->loadCollatorAlgorithm( *pLastAlgorithm, + *pLocale, + pOptions->bIgnoreCase ? SW_COLLATOR_IGNORES : 0 ); + } + + nCmp = pSortCollator->compareString( + pOrig->GetKey( nKey ), pCmp->GetKey( nKey )); + } + return nCmp; +} + /*-------------------------------------------------------------------- Description: Comparison operators --------------------------------------------------------------------*/ @@ -146,49 +184,17 @@ sal_Bool SwSortElement::operator==(const SwSortElement& ) const --------------------------------------------------------------------*/ sal_Bool SwSortElement::operator<(const SwSortElement& rCmp) const { - // The actual comparison for(sal_uInt16 nKey = 0; nKey < pOptions->aKeys.size(); ++nKey) { - const SwSortElement *pOrig, *pCmp; - - const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ]; - if( pSrtKey->eSortOrder == SRT_ASCENDING ) - pOrig = this, pCmp = &rCmp; - else - pOrig = &rCmp, pCmp = this; + int nCmp = keycompare(rCmp, nKey); - if( pSrtKey->bIsNumeric ) - { - double n1 = pOrig->GetValue( nKey ); - double n2 = pCmp->GetValue( nKey ); - - if( n1 == n2 ) - continue; + if (nCmp == 0) + continue; - return n1 < n2; - } - else - { - if( !pLastAlgorithm || *pLastAlgorithm != pSrtKey->sSortType ) - { - if( pLastAlgorithm ) - *pLastAlgorithm = pSrtKey->sSortType; - else - pLastAlgorithm = new String( pSrtKey->sSortType ); - pSortCollator->loadCollatorAlgorithm( *pLastAlgorithm, - *pLocale, - pOptions->bIgnoreCase ? SW_COLLATOR_IGNORES : 0 ); - } - - sal_Int32 nCmp = pSortCollator->compareString( - pOrig->GetKey( nKey ), pCmp->GetKey( nKey )); - if( 0 == nCmp ) - continue; - - return -1 == nCmp; - } + return nCmp < 0; } + return sal_False; } diff --git a/sw/source/core/inc/docsort.hxx b/sw/source/core/inc/docsort.hxx index 21623284d309..7236e0edb492 100644 --- a/sw/source/core/inc/docsort.hxx +++ b/sw/source/core/inc/docsort.hxx @@ -90,6 +90,8 @@ struct SwSortElement sal_Bool operator<(const SwSortElement& ) const; double StrToDouble(const String& rStr) const; +private: + int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const; }; // sort text |