diff options
author | Eike Rathke <erack@redhat.com> | 2011-11-22 14:29:35 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2011-11-22 14:52:41 +0100 |
commit | 3b5ee26d2c27b9fb8d3836c470832fc81cda721f (patch) | |
tree | fae2e2fce03aaf000a18ae253493d50b68f377de /svl | |
parent | 734bfe16bdfe7c80fa8c0c71d680746353686961 (diff) |
added partitive case month names
* Locale data:
* nominative (nouns) month names always given in <MonthsOfYear>
element
* optional genitive case month names in <GenitiveMonths> element,
following the <MonthsOfYear> element; if not given take nominative
names
* optional partitive case month names in <PartitiveMonths> element,
following the <GenitiveMonths> element, or following the
<MonthsOfYear> element if the <GenitiveMonths> element is not
present; if not given take genitive case names, or nominative if
genitive names aren't defined
* currently known partitive case matters in Finnish locales
* Rules for use of nominative / genitive / partitive case month names in
number formatter:
* no day of month (D or DD) present in format code => MMM or MMMM
display nominative month name (noun)
* day of month (D or DD) after MMM or MMMM => genitive name
* no genitive names defined => nominative names
* day of month (D or DD) before MMM or MMMM => partitive name
* no partitive names defined => genitive names
* no genitive names defined => nominative names
Diffstat (limited to 'svl')
-rw-r--r-- | svl/inc/svl/zformat.hxx | 23 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 28 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.hxx | 2 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 123 |
4 files changed, 128 insertions, 48 deletions
diff --git a/svl/inc/svl/zformat.hxx b/svl/inc/svl/zformat.hxx index 1ad50d704a15..659b9304c7c0 100644 --- a/svl/inc/svl/zformat.hxx +++ b/svl/inc/svl/zformat.hxx @@ -476,14 +476,25 @@ private: SVL_DLLPRIVATE bool ImpIsOtherCalendar( const ImpSvNumFor& rNumFor ) const; - /** Whether to use possessive genitive case month name instead of noun. + /** Whether to use possessive genitive case month name, or partitive case + month name, instead of nominative name (noun). + @param io_nState - 0: execute check, set to 1 if true is returned, set to 2 if false - is returned <br> - 1: don't execute check, return true <br> - 2: don't execute check, return false <br> + 0: execute check <br> + set to 1 if nominative case is returned, <br> + set to 2 if genitive case is returned, <br> + set to 3 if partitive case is returned <br> + 1: don't execute check, return nominative case <br> + 2: don't execute check, return genitive case <br> + 3: don't execute check, return partitive case <br> + + @param eCodeType + a NfKeywordIndex, must designate a month type code + + @returns one of com::sun::star::i18n::CalendarDisplayCode values + according to eCodeType and the check executed (or passed). */ - SVL_DLLPRIVATE bool ImpUseGenitiveMonth( int & io_nState, const ImpSvNumFor& rNumFor ) const; + SVL_DLLPRIVATE sal_Int32 ImpUseMonthCase( int & io_nState, const ImpSvNumFor& rNumFor, NfKeywordIndex eCodeType ) const; #ifdef THE_FUTURE SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar, diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index 3fa6908b1d4f..cfad6e2b7483 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -87,6 +87,8 @@ ImpSvNumberInputScan::ImpSvNumberInputScan( SvNumberFormatter* pFormatterP ) pUpperAbbrevMonthText( NULL ), pUpperGenitiveMonthText( NULL ), pUpperGenitiveAbbrevMonthText( NULL ), + pUpperPartitiveMonthText( NULL ), + pUpperPartitiveAbbrevMonthText( NULL ), pUpperDayText( NULL ), pUpperAbbrevDayText( NULL ), eScannedType( NUMBERFORMAT_UNDEFINED ), @@ -111,6 +113,8 @@ ImpSvNumberInputScan::~ImpSvNumberInputScan() delete [] pUpperAbbrevMonthText; delete [] pUpperGenitiveMonthText; delete [] pUpperGenitiveAbbrevMonthText; + delete [] pUpperPartitiveMonthText; + delete [] pUpperPartitiveAbbrevMonthText; delete [] pUpperDayText; delete [] pUpperAbbrevDayText; } @@ -573,6 +577,18 @@ short ImpSvNumberInputScan::GetMonth( const String& rString, xub_StrLen& nPos ) res = sal::static_int_cast< short >(-(i+1)); // negative break; // for } + else if ( StringContains( pUpperPartitiveMonthText[i], rString, nPos ) ) + { // partitive full names + nPos = nPos + pUpperPartitiveMonthText[i].Len(); + res = i+1; + break; // for + } + else if ( StringContains( pUpperPartitiveAbbrevMonthText[i], rString, nPos ) ) + { // partitive abbreviated + nPos = nPos + pUpperPartitiveAbbrevMonthText[i].Len(); + res = sal::static_int_cast< short >(-(i+1)); // negative + break; // for + } else if ( StringContains( pUpperMonthText[i], rString, nPos ) ) { // noun full names nPos = nPos + pUpperMonthText[i].Len(); @@ -2455,6 +2471,18 @@ void ImpSvNumberInputScan::InitText() pUpperGenitiveAbbrevMonthText[j] = pChrCls->upper( xElems[j].AbbrevName ); } + delete [] pUpperPartitiveMonthText; + delete [] pUpperPartitiveAbbrevMonthText; + xElems = pCal->getPartitiveMonths(); + nElems = xElems.getLength(); + pUpperPartitiveMonthText = new String[nElems]; + pUpperPartitiveAbbrevMonthText = new String[nElems]; + for ( j=0; j<nElems; j++ ) + { + pUpperPartitiveMonthText[j] = pChrCls->upper( xElems[j].FullName ); + pUpperPartitiveAbbrevMonthText[j] = pChrCls->upper( xElems[j].AbbrevName ); + } + delete [] pUpperDayText; delete [] pUpperAbbrevDayText; xElems = pCal->getDays(); diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx index 158a4564a28d..c8a6d29ba5f5 100644 --- a/svl/source/numbers/zforfind.hxx +++ b/svl/source/numbers/zforfind.hxx @@ -75,6 +75,8 @@ private: String* pUpperAbbrevMonthText; // Array of month names, abbreviated, uppercase String* pUpperGenitiveMonthText; // Array of genitive month names, uppercase String* pUpperGenitiveAbbrevMonthText; // Array of genitive month names, abbreviated, uppercase + String* pUpperPartitiveMonthText; // Array of partitive month names, uppercase + String* pUpperPartitiveAbbrevMonthText; // Array of partitive month names, abbreviated, uppercase String* pUpperDayText; // Array of day of week names, uppercase String* pUpperAbbrevDayText; // Array of day of week names, abbreviated, uppercase String aUpperCurrSymbol; // Currency symbol, uppercase diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index c4315d3a007d..e4c347b77660 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -2946,28 +2946,79 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber, /** If a day of month occurs within the format, the month name is in possessive - genitive case. + genitive case if the day follows the month, and partitive case if the day + precedes the month. If there is no day of month the nominative case (noun) + is returned. */ -bool SvNumberformat::ImpUseGenitiveMonth( int & io_nState, const ImpSvNumFor& rNumFor ) const +sal_Int32 SvNumberformat::ImpUseMonthCase( int & io_nState, const ImpSvNumFor& rNumFor, NfKeywordIndex eCodeType ) const { - if (io_nState) - return io_nState == 1; - - const ImpSvNumberformatInfo& rInfo = rNumFor.Info(); - const sal_uInt16 nAnz = rNumFor.GetCount(); - sal_uInt16 i; - for ( i = 0; i < nAnz; i++ ) + using namespace ::com::sun::star::i18n; + if (!io_nState) { - switch ( rInfo.nTypeArray[i] ) + io_nState = 1; + bool bMonthSeen = false; + const ImpSvNumberformatInfo& rInfo = rNumFor.Info(); + const sal_uInt16 nCount = rNumFor.GetCount(); + for ( sal_uInt16 i = 0; i < nCount && io_nState == 1; ++i ) { - case NF_KEY_D : - case NF_KEY_DD : - io_nState = 1; - return true; + switch ( rInfo.nTypeArray[i] ) + { + case NF_KEY_D : + case NF_KEY_DD : + io_nState = (bMonthSeen ? 2 : 3); // and end loop + break; + case NF_KEY_MMM: + case NF_KEY_MMMM: + case NF_KEY_MMMMM: + bMonthSeen = true; + break; + } } } - io_nState = 2; - return false; + switch (io_nState) + { + case 1: + // no day of month + switch (eCodeType) + { + case NF_KEY_MMM: + return CalendarDisplayCode::SHORT_MONTH_NAME; + case NF_KEY_MMMM: + return CalendarDisplayCode::LONG_MONTH_NAME; + case NF_KEY_MMMMM: + return CalendarDisplayCode::NARROW_MONTH_NAME; + default: + ; // nothing + } + case 2: + // day of month follows month (the month's 17th) + switch (eCodeType) + { + case NF_KEY_MMM: + return CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME; + case NF_KEY_MMMM: + return CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME; + case NF_KEY_MMMMM: + return CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME; + default: + ; // nothing + } + case 3: + // day of month precedes month (17 of month) + switch (eCodeType) + { + case NF_KEY_MMM: + return CalendarDisplayCode::SHORT_PARTITIVE_MONTH_NAME; + case NF_KEY_MMMM: + return CalendarDisplayCode::LONG_PARTITIVE_MONTH_NAME; + case NF_KEY_MMMMM: + return CalendarDisplayCode::NARROW_PARTITIVE_MONTH_NAME; + default: + ; // nothing + } + } + OSL_FAIL( "ImpUseMonthCase: should not be reached"); + return CalendarDisplayCode::LONG_MONTH_NAME; } @@ -3130,7 +3181,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, double fDiff = DateTime(*(rScan.GetNullDate())) - rCal.getEpochStart(); fNumber += fDiff; rCal.setLocalDateTime( fNumber ); - int nUseGenitiveMonth = 0; // not decided yet + int nUseMonthCase = 0; // not decided yet String aOrgCalendar; // empty => not changed yet double fOrgDateTime; bool bOtherCalendar = ImpIsOtherCalendar( NumFor[nIx] ); @@ -3183,22 +3234,16 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, CalendarDisplayCode::LONG_MONTH, nNatNum ); break; case NF_KEY_MMM: // MMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME : - CalendarDisplayCode::SHORT_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_MMMM: // MMMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME : - CalendarDisplayCode::LONG_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_MMMMM: // MMMMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME : - CalendarDisplayCode::NARROW_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_Q: // Q OutString += rCal.getDisplayString( @@ -3345,7 +3390,7 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, } rCal.setLocalDateTime( fNumber ); - int nUseGenitiveMonth = 0; // not decided yet + int nUseMonthCase = 0; // not decided yet String aOrgCalendar; // empty => not changed yet double fOrgDateTime; bool bOtherCalendar = ImpIsOtherCalendar( NumFor[nIx] ); @@ -3512,22 +3557,16 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, CalendarDisplayCode::LONG_MONTH, nNatNum ); break; case NF_KEY_MMM: // MMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::SHORT_GENITIVE_MONTH_NAME : - CalendarDisplayCode::SHORT_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_MMMM: // MMMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::LONG_GENITIVE_MONTH_NAME : - CalendarDisplayCode::LONG_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_MMMMM: // MMMMM - OutString += rCal.getDisplayString( - (ImpUseGenitiveMonth( nUseGenitiveMonth, NumFor[nIx]) ? - CalendarDisplayCode::NARROW_GENITIVE_MONTH_NAME : - CalendarDisplayCode::NARROW_MONTH_NAME), nNatNum ); + OutString += rCal.getDisplayString( ImpUseMonthCase( + nUseMonthCase, NumFor[nIx], static_cast<NfKeywordIndex>(rInfo.nTypeArray[i])), nNatNum); break; case NF_KEY_Q: // Q OutString += rCal.getDisplayString( |