summaryrefslogtreecommitdiff
path: root/i18npool/source/calendar
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-09-07 23:10:33 +0300
committerArkadiy Illarionov <qarkai@gmail.com>2019-10-21 19:41:43 +0200
commit00e2f118d7f4f070ebddf16b2cf4e89cf9d551a7 (patch)
tree2f48bf4455360d0f08d8096317ea31012debffbc /i18npool/source/calendar
parentad3e00237f48c52dbd2833f21f5e2f5acfdd4167 (diff)
Simplify Sequence iterations in i18npool
Use range-based loops, STL and comphelper functions. Change-Id: Ibbc1c14e921585819872f26e8def2a60594e6a63 Reviewed-on: https://gerrit.libreoffice.org/78754 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'i18npool/source/calendar')
-rw-r--r--i18npool/source/calendar/calendarImpl.cxx33
-rw-r--r--i18npool/source/calendar/calendar_gregorian.cxx8
2 files changed, 17 insertions, 24 deletions
diff --git a/i18npool/source/calendar/calendarImpl.cxx b/i18npool/source/calendar/calendarImpl.cxx
index d2e9801338dd..2cb659560489 100644
--- a/i18npool/source/calendar/calendarImpl.cxx
+++ b/i18npool/source/calendar/calendarImpl.cxx
@@ -20,6 +20,7 @@
#include <calendarImpl.hxx>
#include <calendar_gregorian.hxx>
#include <localedata.hxx>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
@@ -42,14 +43,11 @@ CalendarImpl::~CalendarImpl()
void SAL_CALL
CalendarImpl::loadDefaultCalendarTZ( const css::lang::Locale& rLocale, const OUString& rTimeZone )
{
- Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
- for (sal_Int32 i = 0; i < xC.getLength(); i++) {
- if (xC[i].Default) {
- loadCalendarTZ(xC[i].Name, rLocale, rTimeZone);
- return;
- }
- }
- throw ERROR;
+ const Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
+ auto pCal = std::find_if(xC.begin(), xC.end(), [](const Calendar2& rCal) { return rCal.Default; });
+ if (pCal == xC.end())
+ throw ERROR;
+ loadCalendarTZ(pCal->Name, rLocale, rTimeZone);
}
void SAL_CALL
@@ -74,13 +72,9 @@ CalendarImpl::loadCalendarTZ( const OUString& uniqueID, const css::lang::Locale&
if ( ! xI.is() ) {
// check if the calendar is defined in localedata, load gregorian calendar service.
- Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
- for (i = 0; i < xC.getLength(); i++) {
- if (uniqueID == xC[i].Name) {
- xI = m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext);
- break;
- }
- }
+ const Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
+ if (std::any_of(xC.begin(), xC.end(), [&uniqueID](const Calendar2& rCal) { return uniqueID == rCal.Name; }))
+ xI = m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext);
}
if ( !xI.is() )
@@ -139,11 +133,10 @@ CalendarImpl::getLoadedCalendar()
Sequence< OUString > SAL_CALL
CalendarImpl::getAllCalendars( const css::lang::Locale& rLocale )
{
- Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
- sal_Int32 nLen = xC.getLength();
- Sequence< OUString > xSeq( nLen );
- for (sal_Int32 i = 0; i < nLen; i++)
- xSeq[i] = xC[i].Name;
+ const Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
+ Sequence< OUString > xSeq( xC.getLength() );
+ std::transform(xC.begin(), xC.end(), xSeq.begin(),
+ [](const Calendar2& rCal) { return rCal.Name; });
return xSeq;
}
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx
index f3b228efc04e..f3dc6ede1f66 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -260,12 +260,12 @@ Calendar_gregorian::loadCalendar( const OUString& uniqueID, const css::lang::Loc
getValue();
aLocale = rLocale;
- Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
- for (sal_Int32 i = 0; i < xC.getLength(); i++)
+ const Sequence< Calendar2 > xC = LocaleDataImpl::get()->getAllCalendars2(rLocale);
+ for (const auto& rCal : xC)
{
- if (uniqueID == xC[i].Name)
+ if (uniqueID == rCal.Name)
{
- aCalendar = xC[i];
+ aCalendar = rCal;
// setup minimalDaysInFirstWeek
setMinimumNumberOfDaysForFirstWeek(
aCalendar.MinimumNumberOfDaysForFirstWeek);