diff options
Diffstat (limited to 'i18npool/source/calendar/calendarImpl.cxx')
-rw-r--r-- | i18npool/source/calendar/calendarImpl.cxx | 33 |
1 files changed, 13 insertions, 20 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; } |