#include "unicode/locid.h"
#include "unicode/udat.h"
#include "unicode/udatpg.h"
+#include "unicode/unistr.h"
#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
* which must not indicate a failure before the function call.
* @stable ICU 3.8
*/
- static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
+ static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status, UBool skipICUData = FALSE);
#ifndef U_HIDE_INTERNAL_API
* @return conflicting status. The value could be UDATPG_NO_CONFLICT,
* UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
* @stable ICU 3.8
- * <p>
- * <h4>Sample code</h4>
- * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
- * \snippet samples/dtptngsample/dtptngsample.cpp addPatternExample
- * <p>
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp addPatternExample
+ * <p>
*/
UDateTimePatternConflict addPattern(const UnicodeString& pattern,
UBool override,
/**
* Getter corresponding to setAppendItemNames. Values below 0 or at or above
- * UDATPG_FIELD_COUNT are illegal arguments.
+ * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general method
+ * for getting date/time field display names is getFieldDisplayName.
*
* @param field such as UDATPG_ERA_FIELD.
* @return name for field
+ * @see getFieldDisplayName
* @stable ICU 3.8
*/
const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
+ /**
+ * The general interface to get a display name for a particular date/time field,
+ * in one of several possible display widths.
+ *
+ * @param field The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
+ * @param width The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
+ * @return. The display name for field
+ * @stable ICU 61
+ */
+ UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
+
/**
* The DateTimeFormat is a message format pattern used to compose date and
* time patterns. The default pattern in the root locale is "{1} {0}", where
* @return bestPattern
* The best pattern found from the given skeleton.
* @stable ICU 3.8
- * <p>
- * <h4>Sample code</h4>
- * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
- * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample
- * <p>
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample
+ * <p>
*/
UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
* which must not indicate a failure before the function call.
* @return pattern adjusted to match the skeleton fields widths and subtypes.
* @stable ICU 3.8
- * <p>
- * <h4>Sample code</h4>
- * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
- * \snippet samples/dtptngsample/dtptngsample.cpp replaceFieldTypesExample
- * <p>
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp replaceFieldTypesExample
+ * <p>
*/
UnicodeString replaceFieldTypes(const UnicodeString& pattern,
const UnicodeString& skeleton,
private:
/**
* Constructor.
- * @stable ICU 3.8
*/
DateTimePatternGenerator(UErrorCode & status);
/**
* Constructor.
- * @stable ICU 3.8
*/
- DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
+ DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipICUData = FALSE);
/**
* Copy constructor.
* @param other DateTimePatternGenerator to copy
- * @stable ICU 3.8
*/
DateTimePatternGenerator(const DateTimePatternGenerator& other);
/**
* Default assignment operator.
* @param other DateTimePatternGenerator to copy
- * @stable ICU 3.8
*/
DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
+ // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
+ // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
+
Locale pLocale; // pattern locale
FormatParser *fp;
DateTimeMatcher* dtMatcher;
DistanceInfo *distanceInfo;
PatternMap *patternMap;
UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
- UnicodeString appendItemNames[UDATPG_FIELD_COUNT];
+ // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
+ UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
UnicodeString dateTimeFormat;
UnicodeString decimal;
DateTimeMatcher *skipMatcher;
int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
+ // Internal error code used for recording/reporting errors that occur during methods that do not
+ // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
+ // When this is set to an error the object is in an invalid state.
+ UErrorCode internalErrorCode;
+
/* internal flags masks for adjustFieldTypes etc. */
enum {
kDTPGNoFlags = 0,
kDTPGFixFractionalSeconds = 1,
- kDTPGSkeletonUsesCapJ = 2,
- kDTPGSkeletonUsesLowB = 3,
- kDTPGSkeletonUsesCapB = 4
+ kDTPGSkeletonUsesCapJ = 2
+ // with #13183, no longer need flags for b, B
};
- void initData(const Locale &locale, UErrorCode &status);
+ void initData(const Locale &locale, UErrorCode &status, UBool skipICUData = FALSE);
void addCanonicalItems(UErrorCode &status);
void addICUPatterns(const Locale& locale, UErrorCode& status);
void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
void setDecimalSymbols(const Locale& locale, UErrorCode& status);
UDateTimePatternField getAppendFormatNumber(const char* field) const;
- UDateTimePatternField getAppendNameNumber(const char* field) const;
- UnicodeString& getMutableAppendItemName(UDateTimePatternField field);
+#ifndef U_HIDE_DRAFT_API
+ // The following three have to be U_HIDE_DRAFT_API (though private) because UDateTimePGDisplayWidth is
+ UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
+ void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
+ UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
+#endif // U_HIDE_DRAFT_API
void getAppendName(UDateTimePatternField field, UnicodeString& value);
+ UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UDateTimePatternMatchOptions options, UErrorCode& status);
int32_t getCanonicalIndex(const UnicodeString& field);
- const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, const PtnSkeleton** specifiedSkeletonPtr = 0);
+ const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
- UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
- int32_t getTopBitNumber(int32_t foundMask);
+ UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
+ int32_t getTopBitNumber(int32_t foundMask) const;
void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
UBool isAvailableFormatSet(const UnicodeString &key) const;
void copyHashtable(Hashtable *other, UErrorCode &status);