jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 2007-2016, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * File DTPTNGEN.H jpayne@69: * jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: jpayne@69: #ifndef __DTPTNGEN_H__ jpayne@69: #define __DTPTNGEN_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #include "unicode/datefmt.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/udat.h" jpayne@69: #include "unicode/udatpg.h" jpayne@69: #include "unicode/unistr.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Date/Time Pattern Generator jpayne@69: */ jpayne@69: jpayne@69: jpayne@69: class CharString; jpayne@69: class Hashtable; jpayne@69: class FormatParser; jpayne@69: class DateTimeMatcher; jpayne@69: class DistanceInfo; jpayne@69: class PatternMap; jpayne@69: class PtnSkeleton; jpayne@69: class SharedDateTimePatternGenerator; jpayne@69: jpayne@69: /** jpayne@69: * This class provides flexible generation of date format patterns, like "yy-MM-dd". jpayne@69: * The user can build up the generator by adding successive patterns. Once that jpayne@69: * is done, a query can be made using a "skeleton", which is a pattern which just jpayne@69: * includes the desired fields and lengths. The generator will return the "best fit" jpayne@69: * pattern corresponding to that skeleton. jpayne@69: *

The main method people will use is getBestPattern(String skeleton), jpayne@69: * since normally this class is pre-built with data from a particular locale. jpayne@69: * However, generators can be built directly from other data as well. jpayne@69: *

Issue: may be useful to also have a function that returns the list of jpayne@69: * fields in a pattern, in order, since we have that internally. jpayne@69: * That would be useful for getting the UI order of field elements. jpayne@69: * @stable ICU 3.8 jpayne@69: **/ jpayne@69: class U_I18N_API DateTimePatternGenerator : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Construct a flexible generator according to default locale. jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Construct a flexible generator according to data for a given locale. jpayne@69: * @param uLocale jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: jpayne@69: /** jpayne@69: * For ICU use only jpayne@69: * jpayne@69: * @internal jpayne@69: */ jpayne@69: static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status); jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Create an empty generator, to be constructed with addPattern(...) etc. jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~DateTimePatternGenerator(); jpayne@69: jpayne@69: /** jpayne@69: * Clone DateTimePatternGenerator object. Clients are responsible for jpayne@69: * deleting the DateTimePatternGenerator object cloned. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: DateTimePatternGenerator* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically equal to this one. jpayne@69: * jpayne@69: * @param other the DateTimePatternGenerator object to be compared with. jpayne@69: * @return true if other is semantically equal to this. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool operator==(const DateTimePatternGenerator& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically unequal to this one. jpayne@69: * jpayne@69: * @param other the DateTimePatternGenerator object to be compared with. jpayne@69: * @return true if other is semantically unequal to this. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool operator!=(const DateTimePatternGenerator& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Utility to return a unique skeleton from a given pattern. For example, jpayne@69: * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd". jpayne@69: * jpayne@69: * @param pattern Input pattern, such as "dd/MMM" jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return skeleton such as "MMMdd" jpayne@69: * @stable ICU 56 jpayne@69: */ jpayne@69: static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Utility to return a unique skeleton from a given pattern. For example, jpayne@69: * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd". jpayne@69: * getSkeleton() works exactly like staticGetSkeleton(). jpayne@69: * Use staticGetSkeleton() instead of getSkeleton(). jpayne@69: * jpayne@69: * @param pattern Input pattern, such as "dd/MMM" jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return skeleton such as "MMMdd" jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* { jpayne@69: The function is commented out because it is a stable API calling a draft API. jpayne@69: After staticGetSkeleton becomes stable, staticGetSkeleton can be used and jpayne@69: these comments and the definition of getSkeleton in dtptngen.cpp should be removed. jpayne@69: return staticGetSkeleton(pattern, status); jpayne@69: }*/ jpayne@69: jpayne@69: /** jpayne@69: * Utility to return a unique base skeleton from a given pattern. This is jpayne@69: * the same as the skeleton, except that differences in length are minimized jpayne@69: * so as to only preserve the difference between string and numeric form. So jpayne@69: * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd" jpayne@69: * (notice the single d). jpayne@69: * jpayne@69: * @param pattern Input pattern, such as "dd/MMM" jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return base skeleton, such as "MMMd" jpayne@69: * @stable ICU 56 jpayne@69: */ jpayne@69: static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Utility to return a unique base skeleton from a given pattern. This is jpayne@69: * the same as the skeleton, except that differences in length are minimized jpayne@69: * so as to only preserve the difference between string and numeric form. So jpayne@69: * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd" jpayne@69: * (notice the single d). jpayne@69: * getBaseSkeleton() works exactly like staticGetBaseSkeleton(). jpayne@69: * Use staticGetBaseSkeleton() instead of getBaseSkeleton(). jpayne@69: * jpayne@69: * @param pattern Input pattern, such as "dd/MMM" jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return base skeleton, such as "MMMd" jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* { jpayne@69: The function is commented out because it is a stable API calling a draft API. jpayne@69: After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and jpayne@69: these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed. jpayne@69: return staticGetBaseSkeleton(pattern, status); jpayne@69: }*/ jpayne@69: jpayne@69: /** jpayne@69: * Adds a pattern to the generator. If the pattern has the same skeleton as jpayne@69: * an existing pattern, and the override parameter is set, then the previous jpayne@69: * value is overriden. Otherwise, the previous value is retained. In either jpayne@69: * case, the conflicting status is set and previous vale is stored in jpayne@69: * conflicting pattern. jpayne@69: *

jpayne@69: * Note that single-field patterns (like "MMM") are automatically added, and jpayne@69: * don't need to be added explicitly! jpayne@69: * jpayne@69: * @param pattern Input pattern, such as "dd/MMM" jpayne@69: * @param override When existing values are to be overridden use true, jpayne@69: * otherwise use false. jpayne@69: * @param conflictingPattern Previous pattern with the same skeleton. jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return conflicting status. The value could be UDATPG_NO_CONFLICT, jpayne@69: * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT. jpayne@69: * @stable ICU 3.8 jpayne@69: *

jpayne@69: *

Sample code

jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1 jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp addPatternExample jpayne@69: *

jpayne@69: */ jpayne@69: UDateTimePatternConflict addPattern(const UnicodeString& pattern, jpayne@69: UBool override, jpayne@69: UnicodeString& conflictingPattern, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * An AppendItem format is a pattern used to append a field if there is no jpayne@69: * good match. For example, suppose that the input skeleton is "GyyyyMMMd", jpayne@69: * and there is no matching pattern internally, but there is a pattern jpayne@69: * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the jpayne@69: * G. The way these two are conjoined is by using the AppendItemFormat for G jpayne@69: * (era). So if that value is, say "{0}, {1}" then the final resulting jpayne@69: * pattern is "d-MM-yyyy, G". jpayne@69: *

jpayne@69: * There are actually three available variables: {0} is the pattern so far, jpayne@69: * {1} is the element we are adding, and {2} is the name of the element. jpayne@69: *

jpayne@69: * This reflects the way that the CLDR data is organized. jpayne@69: * jpayne@69: * @param field such as UDATPG_ERA_FIELD. jpayne@69: * @param value pattern, such as "{0}, {1}" jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value); jpayne@69: jpayne@69: /** jpayne@69: * Getter corresponding to setAppendItemFormat. Values below 0 or at or jpayne@69: * above UDATPG_FIELD_COUNT are illegal arguments. jpayne@69: * jpayne@69: * @param field such as UDATPG_ERA_FIELD. jpayne@69: * @return append pattern for field jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the names of field, eg "era" in English for ERA. These are only jpayne@69: * used if the corresponding AppendItemFormat is used, and if it contains a jpayne@69: * {2} variable. jpayne@69: *

jpayne@69: * This reflects the way that the CLDR data is organized. jpayne@69: * jpayne@69: * @param field such as UDATPG_ERA_FIELD. jpayne@69: * @param value name of the field jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setAppendItemName(UDateTimePatternField field, const UnicodeString& value); jpayne@69: jpayne@69: /** jpayne@69: * Getter corresponding to setAppendItemNames. Values below 0 or at or above jpayne@69: * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general method jpayne@69: * for getting date/time field display names is getFieldDisplayName. jpayne@69: * jpayne@69: * @param field such as UDATPG_ERA_FIELD. jpayne@69: * @return name for field jpayne@69: * @see getFieldDisplayName jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const UnicodeString& getAppendItemName(UDateTimePatternField field) const; jpayne@69: jpayne@69: /** jpayne@69: * The general interface to get a display name for a particular date/time field, jpayne@69: * in one of several possible display widths. jpayne@69: * jpayne@69: * @param field The desired UDateTimePatternField, such as UDATPG_ERA_FIELD. jpayne@69: * @param width The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED. jpayne@69: * @return The display name for field jpayne@69: * @stable ICU 61 jpayne@69: */ jpayne@69: UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const; jpayne@69: jpayne@69: /** jpayne@69: * The DateTimeFormat is a message format pattern used to compose date and jpayne@69: * time patterns. The default pattern in the root locale is "{1} {0}", where jpayne@69: * {1} will be replaced by the date pattern and {0} will be replaced by the jpayne@69: * time pattern; however, other locales may specify patterns such as jpayne@69: * "{1}, {0}" or "{1} 'at' {0}", etc. jpayne@69: *

jpayne@69: * This is used when the input skeleton contains both date and time fields, jpayne@69: * but there is not a close match among the added patterns. For example, jpayne@69: * suppose that this object was created by adding "dd-MMM" and "hh:mm", and jpayne@69: * its datetimeFormat is the default "{1} {0}". Then if the input skeleton jpayne@69: * is "MMMdhmm", there is not an exact match, so the input skeleton is jpayne@69: * broken up into two components "MMMd" and "hmm". There are close matches jpayne@69: * for those two skeletons, so the result is put together with this pattern, jpayne@69: * resulting in "d-MMM h:mm". jpayne@69: * jpayne@69: * @param dateTimeFormat jpayne@69: * message format pattern, here {1} will be replaced by the date jpayne@69: * pattern and {0} will be replaced by the time pattern. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setDateTimeFormat(const UnicodeString& dateTimeFormat); jpayne@69: jpayne@69: /** jpayne@69: * Getter corresponding to setDateTimeFormat. jpayne@69: * @return DateTimeFormat. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const UnicodeString& getDateTimeFormat() const; jpayne@69: jpayne@69: /** jpayne@69: * Return the best pattern matching the input skeleton. It is guaranteed to jpayne@69: * have all of the fields in the skeleton. jpayne@69: * jpayne@69: * @param skeleton jpayne@69: * The skeleton is a pattern containing only the variable fields. jpayne@69: * For example, "MMMdd" and "mmhh" are skeletons. jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return bestPattern jpayne@69: * The best pattern found from the given skeleton. jpayne@69: * @stable ICU 3.8 jpayne@69: *

jpayne@69: *

Sample code

jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1 jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample jpayne@69: *

jpayne@69: */ jpayne@69: UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Return the best pattern matching the input skeleton. It is guaranteed to jpayne@69: * have all of the fields in the skeleton. jpayne@69: * jpayne@69: * @param skeleton jpayne@69: * The skeleton is a pattern containing only the variable fields. jpayne@69: * For example, "MMMdd" and "mmhh" are skeletons. jpayne@69: * @param options jpayne@69: * Options for forcing the length of specified fields in the jpayne@69: * returned pattern to match those in the skeleton (when this jpayne@69: * would not happen otherwise). For default behavior, use jpayne@69: * UDATPG_MATCH_NO_OPTIONS. jpayne@69: * @param status jpayne@69: * Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return bestPattern jpayne@69: * The best pattern found from the given skeleton. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString getBestPattern(const UnicodeString& skeleton, jpayne@69: UDateTimePatternMatchOptions options, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Adjusts the field types (width and subtype) of a pattern to match what is jpayne@69: * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a jpayne@69: * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be jpayne@69: * "dd-MMMM hh:mm". This is used internally to get the best match for the jpayne@69: * input skeleton, but can also be used externally. jpayne@69: * jpayne@69: * @param pattern Input pattern jpayne@69: * @param skeleton jpayne@69: * The skeleton is a pattern containing only the variable fields. jpayne@69: * For example, "MMMdd" and "mmhh" are skeletons. jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return pattern adjusted to match the skeleton fields widths and subtypes. jpayne@69: * @stable ICU 3.8 jpayne@69: *

jpayne@69: *

Sample code

jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1 jpayne@69: * \snippet samples/dtptngsample/dtptngsample.cpp replaceFieldTypesExample jpayne@69: *

jpayne@69: */ jpayne@69: UnicodeString replaceFieldTypes(const UnicodeString& pattern, jpayne@69: const UnicodeString& skeleton, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Adjusts the field types (width and subtype) of a pattern to match what is jpayne@69: * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a jpayne@69: * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be jpayne@69: * "dd-MMMM hh:mm". This is used internally to get the best match for the jpayne@69: * input skeleton, but can also be used externally. jpayne@69: * jpayne@69: * @param pattern Input pattern jpayne@69: * @param skeleton jpayne@69: * The skeleton is a pattern containing only the variable fields. jpayne@69: * For example, "MMMdd" and "mmhh" are skeletons. jpayne@69: * @param options jpayne@69: * Options controlling whether the length of specified fields in the jpayne@69: * pattern are adjusted to match those in the skeleton (when this jpayne@69: * would not happen otherwise). For default behavior, use jpayne@69: * UDATPG_MATCH_NO_OPTIONS. jpayne@69: * @param status jpayne@69: * Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return pattern adjusted to match the skeleton fields widths and subtypes. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString replaceFieldTypes(const UnicodeString& pattern, jpayne@69: const UnicodeString& skeleton, jpayne@69: UDateTimePatternMatchOptions options, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Return a list of all the skeletons (in canonical form) from this class. jpayne@69: * jpayne@69: * Call getPatternForSkeleton() to get the corresponding pattern. jpayne@69: * jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return StringEnumeration with the skeletons. jpayne@69: * The caller must delete the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: StringEnumeration* getSkeletons(UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Get the pattern corresponding to a given skeleton. jpayne@69: * @param skeleton jpayne@69: * @return pattern corresponding to a given skeleton. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const; jpayne@69: jpayne@69: /** jpayne@69: * Return a list of all the base skeletons (in canonical form) from this class. jpayne@69: * jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return a StringEnumeration with the base skeletons. jpayne@69: * The caller must delete the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: StringEnumeration* getBaseSkeletons(UErrorCode& status) const; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Return a list of redundant patterns are those which if removed, make no jpayne@69: * difference in the resulting getBestPattern values. This method returns a jpayne@69: * list of them, to help check the consistency of the patterns used to build jpayne@69: * this generator. jpayne@69: * jpayne@69: * @param status Output param set to success/failure code on exit, jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * @return a StringEnumeration with the redundant pattern. jpayne@69: * The caller must delete the object. jpayne@69: * @internal ICU 3.8 jpayne@69: */ jpayne@69: StringEnumeration* getRedundants(UErrorCode& status); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * The decimal value is used in formatting fractions of seconds. If the jpayne@69: * skeleton contains fractional seconds, then this is used with the jpayne@69: * fractional seconds. For example, suppose that the input pattern is jpayne@69: * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and jpayne@69: * the decimal string is ",". Then the resulting pattern is modified to be jpayne@69: * "H:mm:ss,SSSS" jpayne@69: * jpayne@69: * @param decimal jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setDecimal(const UnicodeString& decimal); jpayne@69: jpayne@69: /** jpayne@69: * Getter corresponding to setDecimal. jpayne@69: * @return UnicodeString corresponding to the decimal point jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const UnicodeString& getDecimal() const; jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #ifndef U_HIDE_DRAFT_API jpayne@69: /** jpayne@69: * Get the default hour cycle for a locale. Uses the locale that the jpayne@69: * DateTimePatternGenerator was initially created with. jpayne@69: * jpayne@69: * Cannot be used on an empty DateTimePatternGenerator instance. jpayne@69: * jpayne@69: * @param status Output param set to success/failure code on exit, which jpayne@69: * which must not indicate a failure before the function call. jpayne@69: * Set to U_UNSUPPORTED_ERROR if used on an empty instance. jpayne@69: * @return the default hour cycle. jpayne@69: * @draft ICU 67 jpayne@69: */ jpayne@69: UDateFormatHourCycle getDefaultHourCycle(UErrorCode& status) const; jpayne@69: #endif /* U_HIDE_DRAFT_API */ jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * Constructor. jpayne@69: */ jpayne@69: DateTimePatternGenerator(UErrorCode & status); jpayne@69: jpayne@69: /** jpayne@69: * Constructor. jpayne@69: */ jpayne@69: DateTimePatternGenerator(const Locale& locale, UErrorCode & status); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param other DateTimePatternGenerator to copy jpayne@69: */ jpayne@69: DateTimePatternGenerator(const DateTimePatternGenerator& other); jpayne@69: jpayne@69: /** jpayne@69: * Default assignment operator. jpayne@69: * @param other DateTimePatternGenerator to copy jpayne@69: */ jpayne@69: DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other); jpayne@69: jpayne@69: // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode. jpayne@69: // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1; jpayne@69: jpayne@69: Locale pLocale; // pattern locale jpayne@69: FormatParser *fp; jpayne@69: DateTimeMatcher* dtMatcher; jpayne@69: DistanceInfo *distanceInfo; jpayne@69: PatternMap *patternMap; jpayne@69: UnicodeString appendItemFormats[UDATPG_FIELD_COUNT]; jpayne@69: // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT jpayne@69: UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3]; jpayne@69: UnicodeString dateTimeFormat; jpayne@69: UnicodeString decimal; jpayne@69: DateTimeMatcher *skipMatcher; jpayne@69: Hashtable *fAvailableFormatKeyHash; jpayne@69: UnicodeString emptyString; jpayne@69: char16_t fDefaultHourFormatChar; jpayne@69: jpayne@69: int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN. jpayne@69: jpayne@69: // Internal error code used for recording/reporting errors that occur during methods that do not jpayne@69: // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method. jpayne@69: // When this is set to an error the object is in an invalid state. jpayne@69: UErrorCode internalErrorCode; jpayne@69: jpayne@69: /* internal flags masks for adjustFieldTypes etc. */ jpayne@69: enum { jpayne@69: kDTPGNoFlags = 0, jpayne@69: kDTPGFixFractionalSeconds = 1, jpayne@69: kDTPGSkeletonUsesCapJ = 2 jpayne@69: // with #13183, no longer need flags for b, B jpayne@69: }; jpayne@69: jpayne@69: void initData(const Locale &locale, UErrorCode &status); jpayne@69: void addCanonicalItems(UErrorCode &status); jpayne@69: void addICUPatterns(const Locale& locale, UErrorCode& status); jpayne@69: void hackTimes(const UnicodeString& hackPattern, UErrorCode& status); jpayne@69: void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err); jpayne@69: void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status); jpayne@69: void addCLDRData(const Locale& locale, UErrorCode& status); jpayne@69: UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status); jpayne@69: void initHashtable(UErrorCode& status); jpayne@69: void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status); jpayne@69: void setDecimalSymbols(const Locale& locale, UErrorCode& status); jpayne@69: UDateTimePatternField getAppendFormatNumber(const char* field) const; jpayne@69: // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61 jpayne@69: UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const; jpayne@69: void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value); jpayne@69: UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width); jpayne@69: void getAppendName(UDateTimePatternField field, UnicodeString& value); jpayne@69: UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status); jpayne@69: const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0); jpayne@69: UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS); jpayne@69: UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS); jpayne@69: int32_t getTopBitNumber(int32_t foundMask) const; jpayne@69: void setAvailableFormat(const UnicodeString &key, UErrorCode& status); jpayne@69: UBool isAvailableFormatSet(const UnicodeString &key) const; jpayne@69: void copyHashtable(Hashtable *other, UErrorCode &status); jpayne@69: UBool isCanonicalItem(const UnicodeString& item) const; jpayne@69: static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status); jpayne@69: void getAllowedHourFormats(const Locale &locale, UErrorCode &status); jpayne@69: jpayne@69: struct AppendItemFormatsSink; jpayne@69: struct AppendItemNamesSink; jpayne@69: struct AvailableFormatsSink; jpayne@69: } ;// end class DateTimePatternGenerator jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif