mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-5241 Add getQuarters / setQuarters, and tests.
X-SVN-Rev: 19831
This commit is contained in:
parent
b4504a450f
commit
58de79fd9f
6 changed files with 218 additions and 3 deletions
icu4c/source
|
@ -621,6 +621,54 @@ DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthTyp
|
|||
return returnValue;
|
||||
}
|
||||
|
||||
const UnicodeString*
|
||||
DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const
|
||||
{
|
||||
UnicodeString *returnValue = NULL;
|
||||
|
||||
switch (context) {
|
||||
case FORMAT :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
count = fQuartersCount;
|
||||
returnValue = fQuarters;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
count = fShortQuartersCount;
|
||||
returnValue = fShortQuarters;
|
||||
break;
|
||||
case NARROW :
|
||||
count = 0;
|
||||
returnValue = NULL;
|
||||
break;
|
||||
case DT_WIDTH_COUNT :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STANDALONE :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
count = fStandaloneQuartersCount;
|
||||
returnValue = fStandaloneQuarters;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
count = fStandaloneShortQuartersCount;
|
||||
returnValue = fStandaloneShortQuarters;
|
||||
break;
|
||||
case NARROW :
|
||||
count = 0;
|
||||
returnValue = NULL;
|
||||
break;
|
||||
case DT_WIDTH_COUNT :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DT_CONTEXT_COUNT :
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
const UnicodeString*
|
||||
DateFormatSymbols::getAmPmStrings(int32_t &count) const
|
||||
{
|
||||
|
@ -847,6 +895,77 @@ DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width)
|
||||
{
|
||||
// delete the old list if we own it
|
||||
// we always own the new list, which we create here (we duplicate rather
|
||||
// than adopting the list passed in)
|
||||
|
||||
switch (context) {
|
||||
case FORMAT :
|
||||
switch (width) {
|
||||
case WIDE :
|
||||
if (fQuarters)
|
||||
delete[] fQuarters;
|
||||
fQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fQuarters,count);
|
||||
fQuartersCount = count;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
if (fShortQuarters)
|
||||
delete[] fShortQuarters;
|
||||
fShortQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fShortQuarters,count);
|
||||
fShortQuartersCount = count;
|
||||
break;
|
||||
case NARROW :
|
||||
/*
|
||||
if (fNarrowQuarters)
|
||||
delete[] fNarrowQuarters;
|
||||
fNarrowQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fNarrowQuarters,count);
|
||||
fNarrowQuartersCount = count;
|
||||
*/
|
||||
break;
|
||||
case DT_WIDTH_COUNT :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STANDALONE :
|
||||
switch (width) {
|
||||
case WIDE :
|
||||
if (fStandaloneQuarters)
|
||||
delete[] fStandaloneQuarters;
|
||||
fStandaloneQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fStandaloneQuarters,count);
|
||||
fStandaloneQuartersCount = count;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
if (fStandaloneShortQuarters)
|
||||
delete[] fStandaloneShortQuarters;
|
||||
fStandaloneShortQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count);
|
||||
fStandaloneShortQuartersCount = count;
|
||||
break;
|
||||
case NARROW :
|
||||
/*
|
||||
if (fStandaloneNarrowQuarters)
|
||||
delete[] fStandaloneNarrowQuarters;
|
||||
fStandaloneNarrowQuarters = newUnicodeStringArray(count);
|
||||
uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count);
|
||||
fStandaloneNarrowQuartersCount = count;
|
||||
*/
|
||||
break;
|
||||
case DT_WIDTH_COUNT :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DT_CONTEXT_COUNT :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2005, International Business Machines
|
||||
* Copyright (C) 1996-2006, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -390,6 +390,22 @@ udat_getSymbols(const UDateFormat *fmt,
|
|||
res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
||||
break;
|
||||
|
||||
case UDAT_QUARTERS:
|
||||
res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
||||
break;
|
||||
|
||||
case UDAT_SHORT_QUARTERS:
|
||||
res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
||||
break;
|
||||
|
||||
case UDAT_STANDALONE_QUARTERS:
|
||||
res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
||||
break;
|
||||
|
||||
case UDAT_STANDALONE_SHORT_QUARTERS:
|
||||
res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(index < count) {
|
||||
|
@ -471,6 +487,22 @@ udat_countSymbols( const UDateFormat *fmt,
|
|||
syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
||||
break;
|
||||
|
||||
case UDAT_QUARTERS:
|
||||
syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
||||
break;
|
||||
|
||||
case UDAT_SHORT_QUARTERS:
|
||||
syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
||||
break;
|
||||
|
||||
case UDAT_STANDALONE_QUARTERS:
|
||||
syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
||||
break;
|
||||
|
||||
case UDAT_STANDALONE_SHORT_QUARTERS:
|
||||
syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
|
|
|
@ -339,6 +339,29 @@ public:
|
|||
*/
|
||||
void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
|
||||
|
||||
/**
|
||||
* Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE or ABBREVIATED. There
|
||||
* are no NARROW quarters.
|
||||
* @return the quarter strings. (DateFormatSymbols retains ownership.)
|
||||
* @draft ICU 3.6
|
||||
*/
|
||||
const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
|
||||
|
||||
/**
|
||||
* Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
|
||||
*
|
||||
* @param quarters The new quarter strings. (not adopted; caller retains ownership)
|
||||
* @param count Filled in with length of the array.
|
||||
* @param context The formatting context, either FORMAT or STANDALONE
|
||||
* @param width The width of returned strings, either WIDE or ABBREVIATED. There
|
||||
* are no NARROW quarters.
|
||||
* @draft ICU 3.6
|
||||
*/
|
||||
void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
|
||||
|
||||
/**
|
||||
* Gets AM/PM strings. For example: "AM" and "PM".
|
||||
* @param count Filled in with length of the array.
|
||||
|
|
|
@ -710,7 +710,15 @@ typedef enum UDateFormatSymbolType {
|
|||
/** Standalone context versions of weekdays */
|
||||
UDAT_STANDALONE_WEEKDAYS,
|
||||
UDAT_STANDALONE_SHORT_WEEKDAYS,
|
||||
UDAT_STANDALONE_NARROW_WEEKDAYS
|
||||
UDAT_STANDALONE_NARROW_WEEKDAYS,
|
||||
/** The quarters, for example 1st Quarter */
|
||||
UDAT_QUARTERS,
|
||||
/** The short quarter names, for example Q1 */
|
||||
UDAT_SHORT_QUARTERS,
|
||||
/** Standalone context versions of quarters */
|
||||
UDAT_STANDALONE_QUARTERS,
|
||||
UDAT_STANDALONE_SHORT_QUARTERS
|
||||
|
||||
} UDateFormatSymbolType;
|
||||
|
||||
struct UDateFormatSymbols;
|
||||
|
|
|
@ -395,6 +395,7 @@ static void TestSymbols()
|
|||
if(udat_countSymbols(def, UDAT_ERAS)!=2 || udat_countSymbols(def, UDAT_MONTHS)!=12 ||
|
||||
udat_countSymbols(def, UDAT_SHORT_MONTHS)!=12 || udat_countSymbols(def, UDAT_WEEKDAYS)!=8 ||
|
||||
udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def, UDAT_AM_PMS)!=2 ||
|
||||
udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDAT_SHORT_QUARTERS) != 4 ||
|
||||
udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1)
|
||||
{
|
||||
log_err("FAIL: error in udat_countSymbols\n");
|
||||
|
@ -445,6 +446,10 @@ static void TestSymbols()
|
|||
VerifygetSymbols(def, UDAT_AM_PMS, 1, "PM");
|
||||
VerifygetSymbols(fr, UDAT_SHORT_MONTHS, 0, "janv.");
|
||||
VerifygetSymbols(def, UDAT_SHORT_MONTHS, 11, "Dec");
|
||||
VerifygetSymbols(fr, UDAT_QUARTERS, 0, "1er trimestre");
|
||||
VerifygetSymbols(def, UDAT_QUARTERS, 3, "4th quarter");
|
||||
VerifygetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "T2");
|
||||
VerifygetSymbols(def, UDAT_SHORT_QUARTERS, 2, "Q3");
|
||||
VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcL");
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2005, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2006, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
|
@ -272,6 +272,34 @@ void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
|
|||
errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
|
||||
}
|
||||
|
||||
const UnicodeString *wideQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
||||
fr2.setQuarters(wideQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
||||
if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE) !=
|
||||
*fr2.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE )) {
|
||||
errln("ERROR: setQuarters(FORMAT, WIDE) failed");
|
||||
}
|
||||
|
||||
const UnicodeString *abbrQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
||||
fr2.setQuarters(abbrQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
||||
if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED) !=
|
||||
*fr2.getQuarters(count,DateFormatSymbols::FORMAT ,DateFormatSymbols::ABBREVIATED )) {
|
||||
errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
|
||||
}
|
||||
|
||||
const UnicodeString *standaloneWideQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
||||
fr.setQuarters(standaloneWideQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
||||
if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE) !=
|
||||
*fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE )) {
|
||||
errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
|
||||
}
|
||||
|
||||
const UnicodeString *standaloneShortQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
||||
fr.setQuarters(standaloneShortQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
||||
if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED) !=
|
||||
*fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED )) {
|
||||
errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
|
||||
}
|
||||
|
||||
const UnicodeString *ampms = en.getAmPmStrings(count);
|
||||
fr.setAmPmStrings(ampms, count);
|
||||
if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue