diff options
author | Eike Rathke <erack@redhat.com> | 2011-11-18 21:26:39 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2011-11-19 16:15:21 +0100 |
commit | a7dbdbf820cdc86f5e4f2d9f49ff3aa320890f78 (patch) | |
tree | 6a5c8998ecdae2655f0339c3d25be13e03259198 /i18npool/source | |
parent | 19f607d7839c53f0395db64246de3454ebdbcf37 (diff) |
implement possessive genitive case month names locale data API
Diffstat (limited to 'i18npool/source')
-rw-r--r-- | i18npool/source/calendar/calendarImpl.cxx | 33 | ||||
-rw-r--r-- | i18npool/source/calendar/calendar_gregorian.cxx | 33 | ||||
-rw-r--r-- | i18npool/source/localedata/localedata.cxx | 53 |
3 files changed, 97 insertions, 22 deletions
diff --git a/i18npool/source/calendar/calendarImpl.cxx b/i18npool/source/calendar/calendarImpl.cxx index 787f0ae150cc..52eea4ff0a44 100644 --- a/i18npool/source/calendar/calendarImpl.cxx +++ b/i18npool/source/calendar/calendarImpl.cxx @@ -57,7 +57,7 @@ CalendarImpl::~CalendarImpl() void SAL_CALL CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeException) { - Sequence< Calendar> xC = LocaleData().getAllCalendars(rLocale); + Sequence< Calendar2 > xC = LocaleData().getAllCalendars2(rLocale); for (sal_Int32 i = 0; i < xC.getLength(); i++) { if (xC[i].Default) { loadCalendar(xC[i].Name, rLocale); @@ -70,7 +70,7 @@ CalendarImpl::loadDefaultCalendar( const Locale& rLocale ) throw(RuntimeExceptio void SAL_CALL CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw (RuntimeException) { - Reference < XExtendedCalendar > xOldCalendar( xCalendar ); // backup + Reference < XCalendar3 > xOldCalendar( xCalendar ); // backup sal_Int32 i; for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) { @@ -87,7 +87,7 @@ CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) thr if ( ! xI.is() ) { // check if the calendar is defined in localedata, load gregorian calendar service. - Sequence< Calendar> xC = LocaleData().getAllCalendars(rLocale); + Sequence< Calendar2 > xC = LocaleData().getAllCalendars2(rLocale); for (i = 0; i < xC.getLength(); i++) { if (uniqueID == xC[i].Name) { xI = xMSF->createInstance( @@ -98,7 +98,7 @@ CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) thr } if ( xI.is() ) - xI->queryInterface(::getCppuType((const Reference< XExtendedCalendar>*)0)) >>= xCalendar; + xI->queryInterface(::getCppuType((const Reference< XCalendar3>*)0)) >>= xCalendar; else throw ERROR; @@ -122,6 +122,15 @@ CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) thr } } +Calendar2 SAL_CALL +CalendarImpl::getLoadedCalendar2() throw(RuntimeException) +{ + if (xCalendar.is()) + return xCalendar->getLoadedCalendar2(); + else + throw ERROR ; +} + Calendar SAL_CALL CalendarImpl::getLoadedCalendar() throw(RuntimeException) { @@ -134,7 +143,7 @@ CalendarImpl::getLoadedCalendar() throw(RuntimeException) Sequence< OUString > SAL_CALL CalendarImpl::getAllCalendars( const Locale& rLocale ) throw(RuntimeException) { - Sequence< Calendar> xC = LocaleData().getAllCalendars(rLocale); + Sequence< Calendar2 > xC = LocaleData().getAllCalendars2(rLocale); sal_Int32 nLen = xC.getLength(); Sequence< OUString > xSeq( nLen ); for (sal_Int32 i = 0; i < nLen; i++) @@ -264,6 +273,16 @@ CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException) Sequence< CalendarItem > SAL_CALL +CalendarImpl::getDays() throw(RuntimeException) +{ + if (xCalendar.is()) + return xCalendar->getDays(); + else + throw ERROR ; +} + + +Sequence< CalendarItem > SAL_CALL CalendarImpl::getMonths() throw(RuntimeException) { if (xCalendar.is()) @@ -274,10 +293,10 @@ CalendarImpl::getMonths() throw(RuntimeException) Sequence< CalendarItem > SAL_CALL -CalendarImpl::getDays() throw(RuntimeException) +CalendarImpl::getGenitiveMonths() throw(RuntimeException) { if (xCalendar.is()) - return xCalendar->getDays(); + return xCalendar->getGenitiveMonths(); else throw ERROR ; } diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx index 7c1e15cc995c..21a6b12bad95 100644 --- a/i18npool/source/calendar/calendar_gregorian.cxx +++ b/i18npool/source/calendar/calendar_gregorian.cxx @@ -246,7 +246,7 @@ Calendar_gregorian::loadCalendar( const OUString& uniqueID, const com::sun::star getValue(); aLocale = rLocale; - Sequence< Calendar> xC = LocaleData().getAllCalendars(rLocale); + Sequence< Calendar2 > xC = LocaleData().getAllCalendars2(rLocale); for (sal_Int32 i = 0; i < xC.getLength(); i++) { if (uniqueID == xC[i].Name) @@ -272,9 +272,16 @@ Calendar_gregorian::loadCalendar( const OUString& uniqueID, const com::sun::star } +com::sun::star::i18n::Calendar2 SAL_CALL +Calendar_gregorian::getLoadedCalendar2() throw(RuntimeException) +{ + return aCalendar; +} + com::sun::star::i18n::Calendar SAL_CALL Calendar_gregorian::getLoadedCalendar() throw(RuntimeException) { + // gets "down-copy-constructed" return aCalendar; } @@ -838,6 +845,8 @@ static sal_Int32 SAL_CALL DisplayCode2FieldIndex(sal_Int32 nCalendarDisplayCode) case CalendarDisplayCode::LONG_MONTH: case CalendarDisplayCode::SHORT_MONTH_NAME: case CalendarDisplayCode::LONG_MONTH_NAME: + case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME: + case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME: return CalendarFieldIndex::MONTH; case CalendarDisplayCode::SHORT_YEAR: case CalendarDisplayCode::LONG_YEAR: @@ -899,6 +908,13 @@ Calendar_gregorian::getNumberOfDaysInWeek() throw(RuntimeException) Sequence< CalendarItem > SAL_CALL +Calendar_gregorian::getDays() throw(RuntimeException) +{ + return aCalendar.Days; +} + + +Sequence< CalendarItem > SAL_CALL Calendar_gregorian::getMonths() throw(RuntimeException) { return aCalendar.Months; @@ -906,11 +922,12 @@ Calendar_gregorian::getMonths() throw(RuntimeException) Sequence< CalendarItem > SAL_CALL -Calendar_gregorian::getDays() throw(RuntimeException) +Calendar_gregorian::getGenitiveMonths() throw(RuntimeException) { - return aCalendar.Days; + return aCalendar.GenitiveMonths; } + OUString SAL_CALL Calendar_gregorian::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_Int16 nameType ) throw(RuntimeException) { @@ -934,6 +951,12 @@ Calendar_gregorian::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_I else if (nameType == 1) aStr = aCalendar.Months[idx].FullName; else throw ERROR; break; + case CalendarDisplayIndex::GENITIVE_MONTH: + if( idx >= aCalendar.GenitiveMonths.getLength() ) throw ERROR; + if (nameType == 0) aStr = aCalendar.GenitiveMonths[idx].AbbrevName; + else if (nameType == 1) aStr = aCalendar.GenitiveMonths[idx].FullName; + else throw ERROR; + break; case CalendarDisplayIndex::ERA: if( idx >= aCalendar.Eras.getLength() ) throw ERROR; if (nameType == 0) aStr = aCalendar.Eras[idx].AbbrevName; @@ -1016,6 +1039,10 @@ Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 return getDisplayName(CalendarDisplayIndex::MONTH, value, 0); case CalendarDisplayCode::LONG_MONTH_NAME: return getDisplayName(CalendarDisplayIndex::MONTH, value, 1); + case CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME: + return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH, value, 0); + case CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME: + return getDisplayName(CalendarDisplayIndex::GENITIVE_MONTH, value, 1); case CalendarDisplayCode::SHORT_ERA: return getDisplayName(CalendarDisplayIndex::ERA, value, 0); case CalendarDisplayCode::LONG_ERA: diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 49ded2295a65..c859da5c3cb7 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -468,7 +468,7 @@ oslGenericFunction SAL_CALL lcl_LookupTableHelper::getFunctionSymbolByName( #define REF_OFFSET_COUNT 4 Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name, - const Locale& rLocale, const Sequence< Calendar >& calendarsSeq, sal_Int16 item) + const Locale& rLocale, const Sequence< Calendar2 >& calendarsSeq, sal_Int16 item) throw(RuntimeException) { if (!ref_name.equals(name)) { @@ -476,11 +476,11 @@ Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name OUString language = name.getToken(0, under, index); OUString country = name.getToken(0, under, index); Locale loc(language, country, OUString()); - Sequence < Calendar > cals; + Sequence < Calendar2 > cals; if (loc == rLocale) { cals = calendarsSeq; } else { - cals = getAllCalendars(loc); + cals = getAllCalendars2(loc); } const OUString& id = name.getToken(0, under, index); for (index = 0; index < cals.getLength(); index++) { @@ -491,7 +491,7 @@ Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name } // Referred locale not found, return name for en_US locale. if (index == cals.getLength()) { - cals = getAllCalendars( + cals = getAllCalendars2( Locale(OUString(RTL_CONSTASCII_USTRINGPARAM("en")), OUString(RTL_CONSTASCII_USTRINGPARAM("US")), OUString())); if (cals.getLength() > 0) ref_cal = cals[0]; @@ -500,14 +500,27 @@ Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name } ref_name = name; } - return item == REF_DAYS ? ref_cal.Days : item == REF_MONTHS ? ref_cal.Months : ref_cal.Eras; + switch (item) + { + case REF_DAYS: + return ref_cal.Days; + case REF_MONTHS: + return ref_cal.Months; + case REF_GMONTHS: + return ref_cal.GenitiveMonths; + default: + OSL_FAIL( "LocaleData::getCalendarItemByName: unhandled REF_* case"); + // fallthru + case REF_ERAS: + return ref_cal.Eras; + } } 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 ) + const Locale & rLocale, const Sequence< Calendar2 > & calendarsSeq ) throw(RuntimeException) { Sequence< CalendarItem > aItems; @@ -532,8 +545,8 @@ Sequence< CalendarItem > LocaleData::getCalendarItems( } -Sequence< Calendar > SAL_CALL -LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException) +Sequence< Calendar2 > SAL_CALL +LocaleData::getAllCalendars2( const Locale& rLocale ) throw(RuntimeException) { sal_Unicode const * const * allCalendars = NULL; @@ -544,7 +557,7 @@ LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException) sal_Int16 calendarsCount = 0; allCalendars = func(calendarsCount); - Sequence< Calendar > calendarsSeq(calendarsCount); + Sequence< Calendar2 > calendarsSeq(calendarsCount); sal_Int16 offset = REF_OFFSET_COUNT; for(sal_Int16 i = 0; i < calendarsCount; i++) { OUString calendarID(allCalendars[offset]); @@ -563,19 +576,35 @@ LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException) offset++; sal_Int16 minimalDaysInFirstWeek = allCalendars[offset][0]; offset++; - Calendar aCalendar(days, months, eras, startOfWeekDay, - minimalDaysInFirstWeek, defaultCalendar, calendarID); + Calendar2 aCalendar(days, months, eras, startOfWeekDay, + minimalDaysInFirstWeek, defaultCalendar, calendarID, gmonths); calendarsSeq[i] = aCalendar; } return calendarsSeq; } else { - Sequence< Calendar > seq1(0); + Sequence< Calendar2 > seq1(0); return seq1; } } +Sequence< Calendar > SAL_CALL +LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException) +{ + Sequence< Calendar2 > aCal2( getAllCalendars2( rLocale)); + sal_Int32 nLen = aCal2.getLength(); + Sequence< Calendar > aCal1( nLen); + const Calendar2* p2 = aCal2.getArray(); + Calendar* p1 = aCal1.getArray(); + for (sal_Int32 i=0; i < nLen; ++i, ++p1, ++p2) + { + *p1 = *p2; + } + return aCal1; +} + + Sequence< Currency2 > SAL_CALL LocaleData::getAllCurrencies2( const Locale& rLocale ) throw(RuntimeException) { |