#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"
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
construct(kShort, (EStyle) (kShort + kDateOffset), fLocale, status);
initializeDefaultCentury();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setToBogus();
fTimeOverride.setToBogus();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setTo(override);
fTimeOverride.setToBogus();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setToBogus();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setTo(override);
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setToBogus();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
fDateOverride.setToBogus();
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
construct(timeStyle, dateStyle, fLocale, status);
if(U_SUCCESS(status)) {
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);
fTimeZoneFormat(NULL),
fNumberFormatters(NULL),
fOverrideList(NULL),
- fDefaultCapitalizationContext(UDAT_CONTEXT_UNKNOWN)
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
*this = other;
}
fLocale = other.fLocale;
}
- fDefaultCapitalizationContext = other.fDefaultCapitalizationContext;
+ fCapitalizationContext = other.fCapitalizationContext;
return *this;
}
*fSymbols == *that->fSymbols &&
fHaveDefaultCentury == that->fHaveDefaultCentury &&
fDefaultCenturyStart == that->fDefaultCenturyStart &&
- fDefaultCapitalizationContext == that->fDefaultCapitalizationContext);
+ fCapitalizationContext == that->fCapitalizationContext);
}
return FALSE;
}
{
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);
}
//----------------------------------------------------------------------
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;
// 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) {
// 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) {
SimpleDateFormat::subFormat(UnicodeString &appendTo,
UChar ch,
int32_t count,
- UDateFormatContextValue capitalizationContext,
+ UDisplayContext capitalizationContext,
int32_t fieldNum,
FieldPositionHandler& handler,
Calendar& cal,
// 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;
//----------------------------------------------------------------------
-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;
}
#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"
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);
}
#if !UCONFIG_NO_FORMATTING
#include "unicode/datefmt.h"
+#include "unicode/udisplaycontext.h"
U_NAMESPACE_BEGIN
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.
*/
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
* @internal ICU 49 technology preview
*/
virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
-#endif /* U_HIDE_INTERNAL_API */
#ifndef U_HIDE_INTERNAL_API
/**
/**
* 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.
void subFormat(UnicodeString &appendTo,
UChar ch,
int32_t count,
- UDateFormatContextValue capitalizationContext,
+ UDisplayContext capitalizationContext,
int32_t fieldNum,
FieldPositionHandler& handler,
Calendar& cal,
UBool fHaveDefaultCentury;
- UDateFormatContextValue fDefaultCapitalizationContext;
+ UDisplayContext fCapitalizationContext;
};
inline UDate
#include "unicode/localpointer.h"
#include "unicode/ucal.h"
#include "unicode/unum.h"
+#include "unicode/udisplaycontext.h"
/**
* \file
* \brief C API: DateFormat
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.
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
/**
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;
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",
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 );
}
}
}
typedef struct {
const char * locale;
UnicodeString pattern;
- UDateFormatContextValue capitalizationContext;
+ UDisplayContext capitalizationContext;
UnicodeString expectedFormat;
} TestContextItem;
{
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);
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);
}