summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2012-02-08 15:37:49 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2012-02-08 18:33:19 -0500
commit814c4e1c1c8350652b55a21597996d4755f911d4 (patch)
tree590a4c270eb1520fc6c4824ee07962a138baf621
parent1d5400285e1fe4e8754cb9ec32d031a08d1dcd1c (diff)
std::unique must be followed by erase() to really remove duplicates.
It's even mentioned in Effective STL.
-rw-r--r--sc/source/core/data/documen3.cxx70
1 files changed, 27 insertions, 43 deletions
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 3b8be7ae6948..ba618a0474fe 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -88,6 +88,28 @@
using namespace com::sun::star;
+namespace {
+
+void sortAndRemoveDuplicates(std::vector<TypedStrData>& rStrings, bool bCaseSens)
+{
+ if (bCaseSens)
+ {
+ std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseSensitive());
+ std::vector<TypedStrData>::iterator it =
+ std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseSensitive());
+ rStrings.erase(it, rStrings.end());
+ }
+ else
+ {
+ std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseInsensitive());
+ std::vector<TypedStrData>::iterator it =
+ std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseInsensitive());
+ rStrings.erase(it, rStrings.end());
+ }
+}
+
+}
+
void ScDocument::GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rNames) const
{
ScRangeName::TabNameCopyMap aNames;
@@ -1470,17 +1492,7 @@ bool ScDocument::GetFilterEntries(
maTabs[nTab]->GetFilterEntries( nCol, nStartRow, nEndRow, rStrings, rHasDates );
}
- if (aParam.bCaseSens)
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseSensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseSensitive());
- }
- else
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseInsensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseInsensitive());
- }
-
+ sortAndRemoveDuplicates(rStrings, aParam.bCaseSens);
return true;
}
}
@@ -1499,16 +1511,7 @@ bool ScDocument::GetFilterEntriesArea(
if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
{
maTabs[nTab]->GetFilterEntries( nCol, nStartRow, nEndRow, rStrings, rHasDates );
- if (bCaseSens)
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseSensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseSensitive());
- }
- else
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseInsensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseInsensitive());
- }
+ sortAndRemoveDuplicates(rStrings, bCaseSens);
return true;
}
@@ -1535,18 +1538,8 @@ bool ScDocument::GetDataEntries(
if( pData && pData->FillSelectionList( rStrings, ScAddress( nCol, nRow, nTab ) ) )
{
if (pData->GetListType() == ValidListType::SORTEDASCENDING)
- {
- if (bCaseSens)
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseSensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseSensitive());
- }
- else
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseInsensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseInsensitive());
- }
- }
+ sortAndRemoveDuplicates(rStrings, bCaseSens);
+
return true;
}
}
@@ -1561,16 +1554,7 @@ bool ScDocument::GetDataEntries(
std::set<TypedStrData> aStrings;
bool bRet = maTabs[nTab]->GetDataEntries(nCol, nRow, aStrings, bLimit);
rStrings.insert(rStrings.end(), aStrings.begin(), aStrings.end());
- if (bCaseSens)
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseSensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseSensitive());
- }
- else
- {
- std::sort(rStrings.begin(), rStrings.end(), TypedStrData::LessCaseInsensitive());
- std::unique(rStrings.begin(), rStrings.end(), TypedStrData::EqualCaseInsensitive());
- }
+ sortAndRemoveDuplicates(rStrings, bCaseSens);
return bRet;
}