diff --git a/src/recurrence.cpp b/src/recurrence.cpp --- a/src/recurrence.cpp +++ b/src/recurrence.cpp @@ -24,6 +24,7 @@ #include "recurrence.h" #include "sortablelist.h" #include "utils.h" +#include "recurrencehelper_p.h" #include "kcalcore_debug.h" @@ -443,7 +444,7 @@ } dts << rl; } - dts.sortUnique(); + sortAndRemoveDuplicates(dts); return dts.isEmpty() ? QDateTime() : dts.last(); } @@ -873,11 +874,11 @@ return; } - SortableList mD(monthlyDays); - SortableList rbD(rrule->byMonthDays()); + QList mD(monthlyDays); + QList rbD(rrule->byMonthDays()); - mD.sortUnique(); - rbD.sortUnique(); + sortAndRemoveDuplicates(mD); + sortAndRemoveDuplicates(rbD); if (mD != rbD) { rrule->setByMonthDays(monthlyDays); @@ -914,11 +915,11 @@ return; } - SortableList d(days); - SortableList bYD(rrule->byYearDays()); + QList d(days); + QList bYD(rrule->byYearDays()); - d.sortUnique(); - bYD.sortUnique(); + sortAndRemoveDuplicates(d); + sortAndRemoveDuplicates(bYD); if (d != bYD) { rrule->setByYearDays(days); @@ -978,11 +979,11 @@ return; } - SortableList m(months); - SortableList bM(rrule->byMonths()); + QList m(months); + QList bM(rrule->byMonths()); - m.sortUnique(); - bM.sortUnique(); + sortAndRemoveDuplicates(m); + sortAndRemoveDuplicates(bM); if (m != bM) { rrule->setByMonths(months); @@ -1029,7 +1030,7 @@ for (i = 0, end = d->mRRules.count(); i < end; ++i) { times += d->mRRules[i]->recurTimesOn(date, timeZone); } - times.sortUnique(); + sortAndRemoveDuplicates(times); foundDate = false; TimeList extimes; @@ -1047,7 +1048,7 @@ extimes += d->mExRules[i]->recurTimesOn(date, timeZone); } } - extimes.sortUnique(); + sortAndRemoveDuplicates(extimes); int st = 0; for (i = 0, end = extimes.count(); i < end; ++i) { @@ -1095,7 +1096,7 @@ times += d->mStartDateTime; } - times.sortUnique(); + sortAndRemoveDuplicates(times); // Remove excluded times int idt = 0; @@ -1114,7 +1115,7 @@ extimes += d->mExRules[i]->timesInInterval(start, end); } extimes += d->mExDateTimes; - extimes.sortUnique(); + sortAndRemoveDuplicates(extimes); int st = 0; for (i = 0, count = extimes.count(); i < count; ++i) { @@ -1179,7 +1180,7 @@ } // Take the first of these (all others can't be used later on) - dates.sortUnique(); + sortAndRemoveDuplicates(dates); if (dates.isEmpty()) { return QDateTime(); } @@ -1250,7 +1251,7 @@ } // Take the last of these (all others can't be used later on) - dates.sortUnique(); + sortAndRemoveDuplicates(dates); if (dates.isEmpty()) { return QDateTime(); } @@ -1365,7 +1366,7 @@ } d->mRDateTimes = rdates; - d->mRDateTimes.sortUnique(); + sortAndRemoveDuplicates(d->mRDateTimes); updated(); } @@ -1391,7 +1392,7 @@ } d->mRDates = rdates; - d->mRDates.sortUnique(); + sortAndRemoveDuplicates(d->mRDates); updated(); } @@ -1417,7 +1418,7 @@ } d->mExDateTimes = exdates; - d->mExDateTimes.sortUnique(); + sortAndRemoveDuplicates(d->mExDateTimes); } void Recurrence::addExDateTime(const QDateTime &exdate) @@ -1442,7 +1443,7 @@ } DateList l = exdates; - l.sortUnique(); + sortAndRemoveDuplicates(l); if (d->mExDates != l) { d->mExDates = l; diff --git a/src/recurrencehelper_p.h b/src/recurrencehelper_p.h new file mode 100644 --- /dev/null +++ b/src/recurrencehelper_p.h @@ -0,0 +1,38 @@ +/* + This file is part of the kcalcore library. + + Copyright (c) 2019 Volker Krause + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCALCORE_RECURRENCEHELPER_H +#define KCALCORE_RECURRENCEHELPER_H + +#include + +namespace KCalCore { + +template +inline void sortAndRemoveDuplicates(T &container) +{ + std::sort(container.begin(), container.end()); + container.erase(std::unique(container.begin(), container.end())); +} + +} + +#endif diff --git a/src/recurrencerule.cpp b/src/recurrencerule.cpp --- a/src/recurrencerule.cpp +++ b/src/recurrencerule.cpp @@ -22,6 +22,7 @@ #include "recurrencerule.h" #include "utils.h" #include "kcalcore_debug.h" +#include "recurrencehelper_p.h" #include #include @@ -2003,7 +2004,7 @@ } } // Sort it so we can apply the BySetPos. Also some logic relies on this being sorted - lst.sortUnique(); + sortAndRemoveDuplicates(lst); /*if ( lst.isEmpty() ) { qCDebug(KCALCORE_LOG) << " No Dates in Interval"; @@ -2029,7 +2030,7 @@ lst.append(tmplst[pos]); } } - lst.sortUnique(); + sortAndRemoveDuplicates(lst); } return lst;