ICU-9633 Adapt date fmt display context APIs to tentative new UDisplayContext
X-SVN-Rev: 32549
This commit is contained in:
parent
7a826f4b61
commit
b6053b4240
@ -48,6 +48,7 @@
|
||||
#include "unicode/tzfmt.h"
|
||||
#include "unicode/utf16.h"
|
||||
#include "unicode/vtzone.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
#include "olsontz.h"
|
||||
#include "patternprops.h"
|
||||
#include "fphdlimp.h"
|
||||
@ -241,7 +242,7 @@ SimpleDateFormat::SimpleDateFormat(UErrorCode& status)
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
construct(kShort, (EStyle) (kShort + kDateOffset), fLocale, status);
|
||||
initializeDefaultCentury();
|
||||
@ -257,7 +258,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
fDateOverride.setToBogus();
|
||||
fTimeOverride.setToBogus();
|
||||
@ -277,7 +278,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
fDateOverride.setTo(override);
|
||||
fTimeOverride.setToBogus();
|
||||
@ -299,7 +300,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
|
||||
fDateOverride.setToBogus();
|
||||
@ -321,7 +322,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
|
||||
fDateOverride.setTo(override);
|
||||
@ -346,7 +347,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
|
||||
fDateOverride.setToBogus();
|
||||
@ -368,7 +369,7 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
|
||||
fDateOverride.setToBogus();
|
||||
@ -391,7 +392,7 @@ SimpleDateFormat::SimpleDateFormat(EStyle timeStyle,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
construct(timeStyle, dateStyle, fLocale, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
@ -414,7 +415,7 @@ SimpleDateFormat::SimpleDateFormat(const Locale& locale,
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
if (U_FAILURE(status)) return;
|
||||
initializeSymbols(fLocale, initializeCalendar(NULL, fLocale, status),status);
|
||||
@ -449,7 +450,7 @@ SimpleDateFormat::SimpleDateFormat(const SimpleDateFormat& other)
|
||||
fTimeZoneFormat(NULL),
|
||||
fNumberFormatters(NULL),
|
||||
fOverrideList(NULL),
|
||||
fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
|
||||
fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
@ -482,7 +483,7 @@ SimpleDateFormat& SimpleDateFormat::operator=(const SimpleDateFormat& other)
|
||||
fLocale = other.fLocale;
|
||||
}
|
||||
|
||||
fDefaultCapitalizationContext = other.fDefaultCapitalizationContext;
|
||||
fCapitalizationContext = other.fCapitalizationContext;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -509,7 +510,7 @@ SimpleDateFormat::operator==(const Format& other) const
|
||||
*fSymbols == *that->fSymbols &&
|
||||
fHaveDefaultCentury == that->fHaveDefaultCentury &&
|
||||
fDefaultCenturyStart == that->fDefaultCenturyStart &&
|
||||
fDefaultCapitalizationContext == that->fDefaultCapitalizationContext);
|
||||
fCapitalizationContext == that->fCapitalizationContext);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@ -816,22 +817,7 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo, FieldPosition&
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
FieldPositionOnlyHandler handler(pos);
|
||||
return _format(cal, fDefaultCapitalizationContext, appendTo, handler, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
UnicodeString&
|
||||
SimpleDateFormat::format(Calendar& cal, const UDateFormatContextType* types, const UDateFormatContextValue* values,
|
||||
int32_t typesAndValuesCount, UnicodeString& appendTo, FieldPosition& pos) const
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
FieldPositionOnlyHandler handler(pos);
|
||||
UDateFormatContextValue capitalizationContext = fDefaultCapitalizationContext;
|
||||
if (types != NULL && values != NULL && typesAndValuesCount==1 && types[0]==UDAT_CAPITALIZATION) {
|
||||
capitalizationContext = values[0];
|
||||
}
|
||||
return _format(cal, capitalizationContext, appendTo, handler, status);
|
||||
return _format(cal, appendTo, handler, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -841,14 +827,14 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo,
|
||||
FieldPositionIterator* posIter, UErrorCode& status) const
|
||||
{
|
||||
FieldPositionIteratorHandler handler(posIter, status);
|
||||
return _format(cal, fDefaultCapitalizationContext, appendTo, handler, status);
|
||||
return _format(cal, appendTo, handler, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
UnicodeString&
|
||||
SimpleDateFormat::_format(Calendar& cal, UDateFormatContextValue capitalizationContext,
|
||||
UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const
|
||||
SimpleDateFormat::_format(Calendar& cal, UnicodeString& appendTo,
|
||||
FieldPositionHandler& handler, UErrorCode& status) const
|
||||
{
|
||||
if ( U_FAILURE(status) ) {
|
||||
return appendTo;
|
||||
@ -883,7 +869,7 @@ SimpleDateFormat::_format(Calendar& cal, UDateFormatContextValue capitalizationC
|
||||
// Use subFormat() to format a repeated pattern character
|
||||
// when a different pattern or non-pattern character is seen
|
||||
if (ch != prevCh && count > 0) {
|
||||
subFormat(appendTo, prevCh, count, capitalizationContext, fieldNum++, handler, *workCal, status);
|
||||
subFormat(appendTo, prevCh, count, fCapitalizationContext, fieldNum++, handler, *workCal, status);
|
||||
count = 0;
|
||||
}
|
||||
if (ch == QUOTE) {
|
||||
@ -911,7 +897,7 @@ SimpleDateFormat::_format(Calendar& cal, UDateFormatContextValue capitalizationC
|
||||
|
||||
// Format the last item in the pattern, if any
|
||||
if (count > 0) {
|
||||
subFormat(appendTo, prevCh, count, capitalizationContext, fieldNum++, handler, *workCal, status);
|
||||
subFormat(appendTo, prevCh, count, fCapitalizationContext, fieldNum++, handler, *workCal, status);
|
||||
}
|
||||
|
||||
if (calClone != NULL) {
|
||||
@ -1188,7 +1174,7 @@ void
|
||||
SimpleDateFormat::subFormat(UnicodeString &appendTo,
|
||||
UChar ch,
|
||||
int32_t count,
|
||||
UDateFormatContextValue capitalizationContext,
|
||||
UDisplayContext capitalizationContext,
|
||||
int32_t fieldNum,
|
||||
FieldPositionHandler& handler,
|
||||
Calendar& cal,
|
||||
@ -1532,15 +1518,15 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
|
||||
// first field, check to see whether we need to titlecase it
|
||||
UBool titlecase = FALSE;
|
||||
switch (capitalizationContext) {
|
||||
case UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE:
|
||||
case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE:
|
||||
titlecase = TRUE;
|
||||
break;
|
||||
case UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU:
|
||||
titlecase = fSymbols->fCapitalization[capContextUsageType][0];
|
||||
break;
|
||||
case UDAT_CAPITALIZATION_FOR_STANDALONE:
|
||||
titlecase = fSymbols->fCapitalization[capContextUsageType][1];
|
||||
break;
|
||||
case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU:
|
||||
titlecase = fSymbols->fCapitalization[capContextUsageType][0];
|
||||
break;
|
||||
case UDISPCTX_CAPITALIZATION_FOR_STANDALONE:
|
||||
titlecase = fSymbols->fCapitalization[capContextUsageType][1];
|
||||
break;
|
||||
default:
|
||||
// titlecase = FALSE;
|
||||
break;
|
||||
@ -3123,31 +3109,30 @@ void SimpleDateFormat::adoptCalendar(Calendar* calendarToAdopt)
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
void SimpleDateFormat::setDefaultContext(UDateFormatContextType type,
|
||||
UDateFormatContextValue value, UErrorCode& status)
|
||||
void SimpleDateFormat::setContext(UDisplayContext value, UErrorCode& status)
|
||||
{
|
||||
if (U_FAILURE(status))
|
||||
return;
|
||||
if (type != UDAT_CAPITALIZATION) {
|
||||
if ( (UDisplayContextType)(value & ~0xFF) == UDISPCTX_TYPE_CAPITALIZATION ) {
|
||||
fCapitalizationContext = value;
|
||||
} else {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
fDefaultCapitalizationContext = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
int32_t SimpleDateFormat::getDefaultContext(UDateFormatContextType type, UErrorCode& status) const
|
||||
UDisplayContext SimpleDateFormat::getContext(UDisplayContextType type, UErrorCode& status) const
|
||||
{
|
||||
if (U_FAILURE(status))
|
||||
return 0;
|
||||
if (type != UDAT_CAPITALIZATION) {
|
||||
return (UDisplayContext)0;
|
||||
if (type != UDISPCTX_TYPE_CAPITALIZATION) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return 0;
|
||||
return (UDisplayContext)0;
|
||||
}
|
||||
return (int32_t)fDefaultCapitalizationContext;
|
||||
return fCapitalizationContext;
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/dtfmtsym.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
#include "cpputils.h"
|
||||
#include "reldtfmt.h"
|
||||
#include "umutex.h"
|
||||
@ -943,27 +944,23 @@ udat_getLocaleByType(const UDateFormat *fmt,
|
||||
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
udat_setDefaultContext(UDateFormat* fmt,
|
||||
UDateFormatContextType type, UDateFormatContextValue value,
|
||||
UErrorCode* status)
|
||||
udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status)
|
||||
{
|
||||
verifyIsSimpleDateFormat(fmt, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
return;
|
||||
}
|
||||
((SimpleDateFormat*)fmt)->setDefaultContext(type, value, *status);
|
||||
((SimpleDateFormat*)fmt)->setContext(value, *status);
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
udat_getDefaultContext(UDateFormat* fmt,
|
||||
UDateFormatContextType type,
|
||||
UErrorCode* status)
|
||||
U_CAPI UDisplayContext U_EXPORT2
|
||||
udat_getContext(UDateFormat* fmt, UDisplayContextType type, UErrorCode* status)
|
||||
{
|
||||
verifyIsSimpleDateFormat(fmt, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
return 0;
|
||||
return (UDisplayContext)0;
|
||||
}
|
||||
return ((SimpleDateFormat*)fmt)->getDefaultContext(type, *status);
|
||||
return ((SimpleDateFormat*)fmt)->getContext(type, *status);
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/datefmt.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -400,38 +401,6 @@ public:
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
|
||||
/**
|
||||
* Format a date or time, which is the standard millis since 24:00 GMT, Jan
|
||||
* 1, 1970. Overrides DateFormat pure virtual method.
|
||||
* <P>
|
||||
* Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
|
||||
* 1996.07.10 AD at 15:08:56 PDT
|
||||
*
|
||||
* @param cal Calendar set to the date and time to be formatted
|
||||
* into a date/time string.
|
||||
* @param types Array of UDateFormatContextTypes for which the corresponding
|
||||
* value specified in the next parameter should override the
|
||||
* formatter's default value for this call (this does not
|
||||
* change the default value).
|
||||
* @param values Array of UDateFormatContextValues corresponding 1-1 to the
|
||||
* UDateFormatContextTypes in the previous parameter.
|
||||
* @param typesAndValuesCount Number of elements in the types and values
|
||||
* arrays.
|
||||
* @param appendTo Output parameter to receive result.
|
||||
* Result is appended to existing contents.
|
||||
* @param pos The formatting position. On input: an alignment field,
|
||||
* if desired. On output: the offsets of the alignment field.
|
||||
* @return Reference to 'appendTo' parameter.
|
||||
* @draft ICU 49
|
||||
*/
|
||||
virtual UnicodeString& format( Calendar& cal,
|
||||
const UDateFormatContextType* types,
|
||||
const UDateFormatContextValue* values,
|
||||
int32_t typesAndValuesCount,
|
||||
UnicodeString& appendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Format a date or time, which is the standard millis since 24:00 GMT, Jan
|
||||
* 1, 1970. Overrides DateFormat pure virtual method.
|
||||
@ -806,34 +775,32 @@ public:
|
||||
*/
|
||||
virtual void adoptCalendar(Calendar* calendarToAdopt);
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
|
||||
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual */
|
||||
/**
|
||||
* Set the formatter's default value for a particular context type,
|
||||
* such as UDAT_CAPITALIZATION.
|
||||
* @param type The context type for which the default value should be set.
|
||||
* @param value The default value to set for the specified context type.
|
||||
* Set a particular UDisplayContext value in the formatter, such as
|
||||
* UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
|
||||
* @param value The UDisplayContext value to set.
|
||||
* @param status Input/output status. If at entry this indicates a failure
|
||||
* status, the function will do nothing; otherwise this will be
|
||||
* updated with any new status from the function.
|
||||
* @draft ICU 49
|
||||
* @internal ICU 50 technology preview
|
||||
*/
|
||||
virtual void setDefaultContext(UDateFormatContextType type, UDateFormatContextValue value,
|
||||
UErrorCode& status);
|
||||
virtual void setContext(UDisplayContext value, UErrorCode& status);
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
|
||||
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual */
|
||||
/**
|
||||
* Get the formatter's default value for a particular context type,
|
||||
* such as UDAT_CAPITALIZATION.
|
||||
* @param type The context type for which the default value should be obtained.
|
||||
* Get the formatter's UDisplayContext value for the specified UDisplayContextType,
|
||||
* such as UDISPCTX_TYPE_CAPITALIZATION.
|
||||
* @param type The UDisplayContextType whose value to return
|
||||
* @param status Input/output status. If at entry this indicates a failure
|
||||
* status, the function will do nothing; otherwise this will be
|
||||
* updated with any new status from the function.
|
||||
* @return The current default value for the specified context type.
|
||||
* @draft ICU 49
|
||||
* @return The UDisplayContextValue for the specified type.
|
||||
* @internal ICU 50 technology preview
|
||||
*/
|
||||
virtual int32_t getDefaultContext(UDateFormatContextType type, UErrorCode& status) const;
|
||||
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
|
||||
/**
|
||||
* Sets the TimeZoneFormat to be used by this date/time formatter.
|
||||
* The caller should not delete the TimeZoneFormat object after
|
||||
@ -856,7 +823,6 @@ public:
|
||||
* @internal ICU 49 technology preview
|
||||
*/
|
||||
virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
@ -927,8 +893,7 @@ private:
|
||||
/**
|
||||
* Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
|
||||
*/
|
||||
UnicodeString& _format(Calendar& cal, UDateFormatContextValue capitalizationContext,
|
||||
UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
|
||||
UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Called by format() to format a single field.
|
||||
@ -949,7 +914,7 @@ private:
|
||||
void subFormat(UnicodeString &appendTo,
|
||||
UChar ch,
|
||||
int32_t count,
|
||||
UDateFormatContextValue capitalizationContext,
|
||||
UDisplayContext capitalizationContext,
|
||||
int32_t fieldNum,
|
||||
FieldPositionHandler& handler,
|
||||
Calendar& cal,
|
||||
@ -1254,7 +1219,7 @@ private:
|
||||
|
||||
UBool fHaveDefaultCentury;
|
||||
|
||||
UDateFormatContextValue fDefaultCapitalizationContext;
|
||||
UDisplayContext fCapitalizationContext;
|
||||
};
|
||||
|
||||
inline UDate
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/ucal.h"
|
||||
#include "unicode/unum.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: DateFormat
|
||||
@ -179,67 +180,6 @@ typedef enum UDateFormatStyle {
|
||||
UDAT_IGNORE = UDAT_PATTERN
|
||||
} UDateFormatStyle;
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_DRAFT_API for UDateFormatContextType and UDateFormatContextValue
|
||||
* since a SimpleDateFormat virtual method & data member depends on them */
|
||||
/** Date format context types
|
||||
* @draft ICU 49
|
||||
*/
|
||||
typedef enum UDateFormatContextType {
|
||||
/**
|
||||
* Type (key) for specifying the capitalization context for which a date
|
||||
* is to be formatted (possible values are in UDateFormatContextValue).
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CAPITALIZATION = 1
|
||||
} UDateFormatContextType;
|
||||
|
||||
/** Values for date format context types
|
||||
* @draft ICU 49
|
||||
*/
|
||||
typedef enum UDateFormatContextValue {
|
||||
/** Values for any UDateFormatContextType (key) */
|
||||
/**
|
||||
* Value for any UDateFormatContextType (such as UDAT_CAPITALIZATION) if the
|
||||
* relevant context to be used in formatting a date is unknown (this is the
|
||||
* default value for any UDateFormatContextType when no value has been
|
||||
* explicitly specified for that UDateFormatContextType).
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CONTEXT_UNKNOWN = 0,
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
/** Values for type (key) UDAT_CAPITALIZATION */
|
||||
/**
|
||||
* UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
|
||||
* with capitalization appropriate for the middle of a sentence.
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE = 1,
|
||||
/**
|
||||
* UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
|
||||
* with capitalization appropriate for the beginning of a sentence.
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE = 2,
|
||||
/**
|
||||
* UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
|
||||
* with capitalization appropriate for a user-interface list or menu item.
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU = 3,
|
||||
/**
|
||||
* UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
|
||||
* with capitalization appropriate for stand-alone usage such as an
|
||||
* isolated name on a calendar page.
|
||||
* @draft ICU 49
|
||||
*/
|
||||
UDAT_CAPITALIZATION_FOR_STANDALONE = 4,
|
||||
#endif
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
UDAT_CONTEXT_DEFAULT = UDAT_CONTEXT_UNKNOWN
|
||||
} UDateFormatContextValue;
|
||||
|
||||
/**
|
||||
* @{
|
||||
* Below are a set of pre-defined skeletons.
|
||||
@ -1040,35 +980,31 @@ udat_getLocaleByType(const UDateFormat *fmt,
|
||||
ULocDataLocaleType type,
|
||||
UErrorCode* status);
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Set the formatter's default value for a particular context type,
|
||||
* such as UDAT_CAPITALIZATION.
|
||||
* @param fmt The formatter for which to set a context type's default value.
|
||||
* @param type The context type for which the default value should be set.
|
||||
* @param value The default value to set for the specified context type.
|
||||
* Set a particular UDisplayContext value in the formatter, such as
|
||||
* UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
|
||||
* @param fmt The formatter for which to set a UDisplayContext value.
|
||||
* @param value The UDisplayContext value to set.
|
||||
* @param status A pointer to an UErrorCode to receive any errors
|
||||
* @draft ICU 49
|
||||
* @internal ICU 50 technology preview
|
||||
*/
|
||||
U_DRAFT void U_EXPORT2
|
||||
udat_setDefaultContext(UDateFormat* fmt,
|
||||
UDateFormatContextType type, UDateFormatContextValue value,
|
||||
UErrorCode* status);
|
||||
U_INTERNAL void U_EXPORT2
|
||||
udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status);
|
||||
|
||||
/**
|
||||
* Get the formatter's default value for a particular context type,
|
||||
* such as UDAT_CAPITALIZATION.
|
||||
* @param fmt The formatter from which to get a context type's default value.
|
||||
* @param type The context type for which the default value should be obtained.
|
||||
* Get the formatter's UDisplayContext value for the specified UDisplayContextType,
|
||||
* such as UDISPCTX_TYPE_CAPITALIZATION.
|
||||
* @param fmt The formatter to query.
|
||||
* @param type The UDisplayContextType whose value to return
|
||||
* @param status A pointer to an UErrorCode to receive any errors
|
||||
* @return The current default value for the specified context type.
|
||||
* @draft ICU 49
|
||||
* @return The UDisplayContextValue for the specified type.
|
||||
* @internal ICU 50 technology preview
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
udat_getDefaultContext(UDateFormat* fmt,
|
||||
UDateFormatContextType type,
|
||||
UErrorCode* status);
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
U_INTERNAL UDisplayContext U_EXPORT2
|
||||
udat_getContext(UDateFormat* fmt, UDisplayContextType type, UErrorCode* status);
|
||||
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
|
@ -1245,26 +1245,26 @@ static const UChar july2008_csTitle[] = { 0x10C,0x65,0x72,0x76,0x65,0x6E,0x65,0x
|
||||
typedef struct {
|
||||
const char * locale;
|
||||
const UChar * skeleton;
|
||||
UDateFormatContextValue capitalizationContext;
|
||||
UDisplayContext capitalizationContext;
|
||||
const UChar * expectedFormat;
|
||||
} TestContextItem;
|
||||
|
||||
static const TestContextItem textContextItems[] = {
|
||||
{ "fr", skeleton_yMMMM, UDAT_CONTEXT_UNKNOWN, july2008_frDefault },
|
||||
{ "fr", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_NONE, july2008_frDefault },
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
{ "fr", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july2008_frDefault },
|
||||
{ "fr", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, july2008_frTitle },
|
||||
{ "fr", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july2008_frDefault },
|
||||
{ "fr", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_STANDALONE, july2008_frTitle },
|
||||
{ "fr", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july2008_frDefault },
|
||||
{ "fr", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, july2008_frTitle },
|
||||
{ "fr", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july2008_frDefault },
|
||||
{ "fr", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, july2008_frTitle },
|
||||
#endif
|
||||
{ "cs", skeleton_yMMMM, UDAT_CONTEXT_UNKNOWN, july2008_csDefault },
|
||||
{ "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_NONE, july2008_csDefault },
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
{ "cs", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july2008_csDefault },
|
||||
{ "cs", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, july2008_csTitle },
|
||||
{ "cs", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july2008_csTitle },
|
||||
{ "cs", skeleton_yMMMM, UDAT_CAPITALIZATION_FOR_STANDALONE, july2008_csDefault },
|
||||
{ "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, july2008_csDefault },
|
||||
{ "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, july2008_csTitle },
|
||||
{ "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, july2008_csTitle },
|
||||
{ "cs", skeleton_yMMMM, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, july2008_csDefault },
|
||||
#endif
|
||||
{ NULL, NULL, 0, NULL }
|
||||
{ NULL, NULL, (UDisplayContext)0, NULL }
|
||||
};
|
||||
|
||||
static const UDate july022008 = 1215000001979.0;
|
||||
@ -1288,12 +1288,12 @@ static void TestContext(void) {
|
||||
log_err("FAIL: udatpg_getBestPattern for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) );
|
||||
} else {
|
||||
udat_applyPattern(udfmt, FALSE, ubuf, len);
|
||||
udat_setDefaultContext(udfmt, UDAT_CAPITALIZATION, textContextItemPtr->capitalizationContext, &status);
|
||||
udat_setContext(udfmt, textContextItemPtr->capitalizationContext, &status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
log_err("FAIL: udat_setDefaultContext for locale %s, capitalizationContext %d, status %s\n",
|
||||
log_err("FAIL: udat_setContext for locale %s, capitalizationContext %d, status %s\n",
|
||||
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, u_errorName(status) );
|
||||
} else {
|
||||
int32_t getContext;
|
||||
UDisplayContext getContext;
|
||||
len = udat_format(udfmt, july022008, ubuf, kUbufMax, NULL, &status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
log_err("FAIL: udat_format for locale %s, capitalizationContext %d, status %s\n",
|
||||
@ -1306,13 +1306,13 @@ static void TestContext(void) {
|
||||
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext,
|
||||
u_austrncpy(bbuf1,textContextItemPtr->expectedFormat,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) );
|
||||
}
|
||||
getContext = udat_getDefaultContext(udfmt, UDAT_CAPITALIZATION, &status);
|
||||
getContext = udat_getContext(udfmt, UDISPCTX_TYPE_CAPITALIZATION, &status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
log_err("FAIL: udat_getDefaultContext for locale %s, capitalizationContext %d, status %s\n",
|
||||
log_err("FAIL: udat_getContext for locale %s, capitalizationContext %d, status %s\n",
|
||||
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, u_errorName(status) );
|
||||
} else if (getContext != (int)textContextItemPtr->capitalizationContext) {
|
||||
log_err("FAIL: udat_getDefaultContext for locale %s, capitalizationContext %d, got context %d\n",
|
||||
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, getContext );
|
||||
} else if (getContext != textContextItemPtr->capitalizationContext) {
|
||||
log_err("FAIL: udat_getContext for locale %s, capitalizationContext %d, got context %d\n",
|
||||
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, (int)getContext );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3837,7 +3837,7 @@ void DateFormatTest::TestMonthPatterns()
|
||||
typedef struct {
|
||||
const char * locale;
|
||||
UnicodeString pattern;
|
||||
UDateFormatContextValue capitalizationContext;
|
||||
UDisplayContext capitalizationContext;
|
||||
UnicodeString expectedFormat;
|
||||
} TestContextItem;
|
||||
|
||||
@ -3845,23 +3845,23 @@ void DateFormatTest::TestContext()
|
||||
{
|
||||
const UDate july022008 = 1215000001979.0;
|
||||
const TestContextItem items[] = {
|
||||
//locale pattern capitalizationContext expected formatted date
|
||||
{ "fr", UnicodeString("MMMM y"), UDAT_CONTEXT_UNKNOWN, UnicodeString("juillet 2008") },
|
||||
//locale pattern capitalizationContext expected formatted date
|
||||
{ "fr", UnicodeString("MMMM y"), UDISPCTX_CAPITALIZATION_NONE, UnicodeString("juillet 2008") },
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
{ "fr", UnicodeString("MMMM y"), UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UnicodeString("juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UnicodeString("Juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UnicodeString("juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDAT_CAPITALIZATION_FOR_STANDALONE, UnicodeString("Juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UnicodeString("juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UnicodeString("Juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UnicodeString("juillet 2008") },
|
||||
{ "fr", UnicodeString("MMMM y"), UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UnicodeString("Juillet 2008") },
|
||||
#endif
|
||||
{ "cs", UnicodeString("LLLL y"), UDAT_CONTEXT_UNKNOWN, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDISPCTX_CAPITALIZATION_NONE, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
#if !UCONFIG_NO_BREAK_ITERATION
|
||||
{ "cs", UnicodeString("LLLL y"), UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, CharsToUnicodeString("\\u010Cervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU, CharsToUnicodeString("\\u010Cervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDAT_CAPITALIZATION_FOR_STANDALONE, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, CharsToUnicodeString("\\u010Cervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, CharsToUnicodeString("\\u010Cervenec 2008") },
|
||||
{ "cs", UnicodeString("LLLL y"), UDISPCTX_CAPITALIZATION_FOR_STANDALONE, CharsToUnicodeString("\\u010Dervenec 2008") },
|
||||
#endif
|
||||
// terminator
|
||||
{ NULL, UnicodeString(""), (UDateFormatContextValue)0, UnicodeString("") }
|
||||
{ NULL, UnicodeString(""), (UDisplayContext)0, UnicodeString("") }
|
||||
};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Calendar* cal = Calendar::createInstance(status);
|
||||
@ -3877,13 +3877,13 @@ void DateFormatTest::TestContext()
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln(UnicodeString("FAIL: Unable to create SimpleDateFormat for specified pattern with locale ") + UnicodeString(itemPtr->locale));
|
||||
} else {
|
||||
UDateFormatContextType contextType = UDAT_CAPITALIZATION;
|
||||
UDateFormatContextValue contextValue = itemPtr->capitalizationContext;
|
||||
sdmft->setContext(itemPtr->capitalizationContext, status);
|
||||
UnicodeString result;
|
||||
FieldPosition pos(0);
|
||||
sdmft->format(*cal, &contextType, &contextValue, 1, result, pos);
|
||||
sdmft->format(*cal, result, pos);
|
||||
if (result.compare(itemPtr->expectedFormat) != 0) {
|
||||
errln(UnicodeString("FAIL: format for locale ") + UnicodeString(itemPtr->locale) +
|
||||
", status " + (int)status +
|
||||
", capitalizationContext " + (int)itemPtr->capitalizationContext +
|
||||
", expected " + itemPtr->expectedFormat + ", got " + result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user