summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2011-11-18 21:26:39 +0100
committerEike Rathke <erack@redhat.com>2011-11-19 16:15:20 +0100
commitf8a352c746d1ca2ced555e9e1711b8de7646832d (patch)
tree52510e15bb801c3b93e46fd85114b19cc6a9334c /i18npool
parent74ec768623eb0f30f9573cde0ea6471b7e1d59a0 (diff)
squeeze some duplicated code
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/localedata.hxx11
-rw-r--r--i18npool/source/localedata/localedata.cxx89
2 files changed, 49 insertions, 51 deletions
diff --git a/i18npool/inc/localedata.hxx b/i18npool/inc/localedata.hxx
index 4cc240d3ebf9..55d9a0374a41 100644
--- a/i18npool/inc/localedata.hxx
+++ b/i18npool/inc/localedata.hxx
@@ -133,6 +133,17 @@ private :
const com::sun::star::lang::Locale& rLocale,
const com::sun::star::uno::Sequence< com::sun::star::i18n::Calendar >& calendarsSeq,
sal_Int16 item) throw( com::sun::star::uno::RuntimeException );
+
+ /// Helper to obtain a sequence of days, months, gmonths or eras.
+ com::sun::star::uno::Sequence< com::sun::star::i18n::CalendarItem > getCalendarItems(
+ sal_Unicode const * const * const allCalendars,
+ sal_Int16 & rnOffset,
+ const sal_Int16 nWhichItem,
+ const sal_Int16 nCalendar,
+ const com::sun::star::lang::Locale & rLocale,
+ const com::sun::star::uno::Sequence< com::sun::star::i18n::Calendar > & calendarsSeq )
+ throw( com::sun::star::uno::RuntimeException );
+
};
} } } }
diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx
index 8b5b58de146f..af580e1f739e 100644
--- a/i18npool/source/localedata/localedata.cxx
+++ b/i18npool/source/localedata/localedata.cxx
@@ -504,11 +504,39 @@ Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name
}
+Sequence< CalendarItem > LocaleData::getCalendarItems(
+ sal_Unicode const * const * const allCalendars, sal_Int16 & rnOffset,
+ const sal_Int16 nWhichItem, const sal_Int16 nCalendar,
+ const Locale & rLocale, const Sequence< Calendar > & calendarsSeq )
+ throw(RuntimeException)
+{
+ Sequence< CalendarItem > aItems;
+ if (OUString( allCalendars[rnOffset]).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ref")))
+ {
+ aItems = getCalendarItemByName( OUString( allCalendars[rnOffset+1]), rLocale, calendarsSeq, nWhichItem);
+ rnOffset += 2;
+ }
+ else
+ {
+ sal_Int32 nSize = allCalendars[nWhichItem][nCalendar];
+ aItems.realloc( nSize);
+ CalendarItem* pItem = aItems.getArray();
+ for (sal_Int16 j = 0; j < nSize; ++j, ++pItem)
+ {
+ CalendarItem day( allCalendars[rnOffset], allCalendars[rnOffset+1], allCalendars[rnOffset+2]);
+ *pItem = day;
+ rnOffset += 3;
+ }
+ }
+ return aItems;
+}
+
+
Sequence< Calendar > SAL_CALL
LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
{
- sal_Unicode **allCalendars = NULL;
+ sal_Unicode const * const * allCalendars = NULL;
MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCalendars" );
@@ -518,60 +546,19 @@ LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
Sequence< Calendar > calendarsSeq(calendarsCount);
sal_Int16 offset = REF_OFFSET_COUNT;
- sal_Int16 i, j;
- for(i = 0; i < calendarsCount; i++) {
- Sequence< CalendarItem > days(allCalendars[REF_DAYS][i]);
- Sequence< CalendarItem > months(allCalendars[REF_MONTHS][i]);
-//prep Sequence< CalendarItem > gmonths(allCalendars[REF_GMONTHS][i]);
- Sequence< CalendarItem > eras(allCalendars[REF_ERAS][i]);
+ for(sal_Int16 i = 0; i < calendarsCount; i++) {
OUString calendarID(allCalendars[offset]);
offset++;
sal_Bool defaultCalendar = sal::static_int_cast<sal_Bool>( allCalendars[offset][0] );
offset++;
- if (OUString(allCalendars[offset]).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ref"))) {
- days = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, REF_DAYS);
- offset += 2;
- } else {
- for(j = 0; j < allCalendars[REF_DAYS][i]; j++) {
- CalendarItem day(allCalendars[offset],
- allCalendars[offset+1], allCalendars[offset+2]);
- days[j] = day;
- offset += 3;
- }
- }
- if (OUString(allCalendars[offset]).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ref"))) {
- months = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, REF_MONTHS);
- offset += 2;
- } else {
- for(j = 0; j < allCalendars[REF_MONTHS][i]; j++) {
- CalendarItem month(allCalendars[offset],
- allCalendars[offset+1], allCalendars[offset+2]);
- months[j] = month;
- offset += 3;
- }
- }
- if (OUString(allCalendars[offset]).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ref"))) {
-//prep gmonths = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, REF_GMONTHS);
- offset += 2;
- } else {
- for(j = 0; j < allCalendars[REF_GMONTHS][i]; j++) {
-//prep CalendarItem gmonth(allCalendars[offset],
-//prep allCalendars[offset+1], allCalendars[offset+2]);
-//prep gmonths[j] = gmonth;
- offset += 3;
- }
- }
- if (OUString(allCalendars[offset]).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ref"))) {
- eras = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, REF_ERAS);
- offset += 2;
- } else {
- for(j = 0; j < allCalendars[REF_ERAS][i]; j++) {
- CalendarItem era(allCalendars[offset],
- allCalendars[offset+1], allCalendars[offset+2]);
- eras[j] = era;
- offset += 3;
- }
- }
+ Sequence< CalendarItem > days = getCalendarItems( allCalendars, offset, REF_DAYS, i,
+ rLocale, calendarsSeq);
+ Sequence< CalendarItem > months = getCalendarItems( allCalendars, offset, REF_MONTHS, i,
+ rLocale, calendarsSeq);
+ Sequence< CalendarItem > gmonths = getCalendarItems( allCalendars, offset, REF_GMONTHS, i,
+ rLocale, calendarsSeq);
+ Sequence< CalendarItem > eras = getCalendarItems( allCalendars, offset, REF_ERAS, i,
+ rLocale, calendarsSeq);
OUString startOfWeekDay(allCalendars[offset]);
offset++;
sal_Int16 minimalDaysInFirstWeek = allCalendars[offset][0];