diff --git a/src/recurrence.cpp b/src/recurrence.cpp --- a/src/recurrence.cpp +++ b/src/recurrence.cpp @@ -443,7 +443,8 @@ } dts << rl; } - dts.sortUnique(); + std::sort(dts.begin(), dts.end()); + dts.erase(std::unique(dts.begin(), dts.end()), dts.end()); return dts.isEmpty() ? QDateTime() : dts.last(); } @@ -876,8 +877,10 @@ SortableList mD(monthlyDays); SortableList rbD(rrule->byMonthDays()); - mD.sortUnique(); - rbD.sortUnique(); + std::sort(mD.begin(), mD.end()); + mD.erase(std::unique(mD.begin(), mD.end()), mD.end()); + std::sort(rbD.begin(), rbD.end()); + rbD.erase(std::unique(rbD.begin(), rbD.end()), rbD.end()); if (mD != rbD) { rrule->setByMonthDays(monthlyDays); @@ -914,11 +917,13 @@ return; } - SortableList d(days); - SortableList bYD(rrule->byYearDays()); + QList d(days); + QList bYD(rrule->byYearDays()); - d.sortUnique(); - bYD.sortUnique(); + std::sort(d.begin(), d.end()); + d.erase(std::unique(d.begin(), d.end()), d.end()); + std::sort(bYD.begin(), bYD.end()); + bYD.erase(std::unique(bYD.begin(), bYD.end()), bYD.end()); if (d != bYD) { rrule->setByYearDays(days); @@ -978,11 +983,13 @@ return; } - SortableList m(months); - SortableList bM(rrule->byMonths()); + QList m(months); + QList bM(rrule->byMonths()); - m.sortUnique(); - bM.sortUnique(); + std::sort(m.begin(), m.end()); + m.erase(std::unique(m.begin(), m.end()), m.end()); + std::sort(bM.begin(), bM.end()); + bM.erase(std::unique(bM.begin(), bM.end()), bM.end()); if (m != bM) { rrule->setByMonths(months); @@ -1029,7 +1036,8 @@ for (i = 0, end = d->mRRules.count(); i < end; ++i) { times += d->mRRules[i]->recurTimesOn(date, timeZone); } - times.sortUnique(); + std::sort(times.begin(), times.end()); + times.erase(std::unique(times.begin(), times.end()), times.end()); foundDate = false; TimeList extimes; @@ -1047,7 +1055,8 @@ extimes += d->mExRules[i]->recurTimesOn(date, timeZone); } } - extimes.sortUnique(); + std::sort(extimes.begin(), extimes.end()); + extimes.erase(std::unique(extimes.begin(), extimes.end()), extimes.end()); int st = 0; for (i = 0, end = extimes.count(); i < end; ++i) { @@ -1095,7 +1104,8 @@ times += d->mStartDateTime; } - times.sortUnique(); + std::sort(times.begin(), times.end()); + times.erase(std::unique(times.begin(), times.end()), times.end()); // Remove excluded times int idt = 0; @@ -1114,7 +1124,8 @@ extimes += d->mExRules[i]->timesInInterval(start, end); } extimes += d->mExDateTimes; - extimes.sortUnique(); + std::sort(extimes.begin(), extimes.end()); + extimes.erase(std::unique(extimes.begin(), extimes.end()), extimes.end()); int st = 0; for (i = 0, count = extimes.count(); i < count; ++i) { @@ -1179,7 +1190,8 @@ } // Take the first of these (all others can't be used later on) - dates.sortUnique(); + std::sort(dates.begin(), dates.end()); + dates.erase(std::unique(dates.begin(), dates.end()), dates.end()); if (dates.isEmpty()) { return QDateTime(); } @@ -1250,7 +1262,8 @@ } // Take the last of these (all others can't be used later on) - dates.sortUnique(); + std::sort(dates.begin(), dates.end()); + dates.erase(std::unique(dates.begin(), dates.end()), dates.end()); if (dates.isEmpty()) { return QDateTime(); } @@ -1365,7 +1378,8 @@ } d->mRDateTimes = rdates; - d->mRDateTimes.sortUnique(); + std::sort(d->mRDateTimes.begin(), d->mRDateTimes.end()); + d->mRDateTimes.erase(std::unique(d->mRDateTimes.begin(), d->mRDateTimes.end()), d->mRDateTimes.end()); updated(); } @@ -1391,7 +1405,8 @@ } d->mRDates = rdates; - d->mRDates.sortUnique(); + std::sort(d->mRDates.begin(), d->mRDates.end()); + d->mRDates.erase(std::unique(d->mRDates.begin(), d->mRDates.end()), d->mRDates.end()); updated(); } @@ -1417,7 +1432,8 @@ } d->mExDateTimes = exdates; - d->mExDateTimes.sortUnique(); + std::sort(d->mExDateTimes.begin(), d->mExDateTimes.end()); + d->mExDateTimes.erase(std::unique(d->mExDateTimes.begin(), d->mExDateTimes.end()), d->mExDateTimes.end()); } void Recurrence::addExDateTime(const QDateTime &exdate) @@ -1442,7 +1458,8 @@ } DateList l = exdates; - l.sortUnique(); + std::sort(l.begin(), l.end()); + l.erase(std::unique(l.begin(), l.end()), l.end()); 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()), container.end()); +} + +} + +#endif diff --git a/src/recurrencerule.cpp b/src/recurrencerule.cpp --- a/src/recurrencerule.cpp +++ b/src/recurrencerule.cpp @@ -2003,7 +2003,8 @@ } } // Sort it so we can apply the BySetPos. Also some logic relies on this being sorted - lst.sortUnique(); + std::sort(lst.begin(), lst.end()); + lst.erase(std::unique(lst.begin(), lst.end()), lst.end()); /*if ( lst.isEmpty() ) { qCDebug(KCALCORE_LOG) << " No Dates in Interval"; @@ -2029,7 +2030,8 @@ lst.append(tmplst[pos]); } } - lst.sortUnique(); + std::sort(lst.begin(), lst.end()); + lst.erase(std::unique(lst.begin(), lst.end()), lst.end()); } return lst;