ICU 78.1  78.1
dtptngen.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2007-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 *
9 * File DTPTNGEN.H
10 *
11 *******************************************************************************
12 */
13 
14 #ifndef __DTPTNGEN_H__
15 #define __DTPTNGEN_H__
16 
17 #include "unicode/utypes.h"
18 
19 #if U_SHOW_CPLUSPLUS_API
20 
21 #include "unicode/datefmt.h"
22 #include "unicode/locid.h"
23 #include "unicode/udat.h"
24 #include "unicode/udatpg.h"
25 #include "unicode/unistr.h"
26 
27 U_NAMESPACE_BEGIN
28 
35 class CharString;
36 class Hashtable;
37 class FormatParser;
38 class DateTimeMatcher;
39 class DistanceInfo;
40 class PatternMap;
41 class PtnSkeleton;
42 class SharedDateTimePatternGenerator;
43 
59 public:
67 
76 
77 #ifndef U_HIDE_INTERNAL_API
78 
85  UErrorCode& status);
86 
87 #endif /* U_HIDE_INTERNAL_API */
88 
96 
102 
109 
118 
127 
139 
153  The function is commented out because it is a stable API calling a draft API.
154  After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
155  these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
156  return staticGetSkeleton(pattern, status);
157  }*/
158 
173  UErrorCode& status);
174 
191  The function is commented out because it is a stable API calling a draft API.
192  After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
193  these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
194  return staticGetBaseSkeleton(pattern, status);
195  }*/
196 
218  UBool override,
219  UnicodeString& conflictingPattern,
220  UErrorCode& status);
221 
222 #ifndef U_HIDE_INTERNAL_API
229  const UnicodeString& skeletonToUse,
230  UBool override,
231  UnicodeString& conflictingPattern,
232  UErrorCode& status);
233 #endif /* U_HIDE_INTERNAL_API */
234 
254 
264 
277 
289 
300  UDateTimePGDisplayWidth width) const;
301 
328  U_I18N_API void setDateTimeFormat(const UnicodeString& dateTimeFormat);
329 
342 
343 #if !UCONFIG_NO_FORMATTING
367  const UnicodeString& dateTimeFormat,
368  UErrorCode& status);
369 
388 #endif /* #if !UCONFIG_NO_FORMATTING */
389 
404 
426  UErrorCode& status);
427 
445  const UnicodeString& skeleton,
446  UErrorCode& status);
447 
471  const UnicodeString& skeleton,
473  UErrorCode& status);
474 
487 
495 
506 
507 #ifndef U_HIDE_INTERNAL_API
521 #endif /* U_HIDE_INTERNAL_API */
522 
534  U_I18N_API void setDecimal(const UnicodeString& decimal);
535 
542 
543 #if !UCONFIG_NO_FORMATTING
544 
558 
559 #endif /* #if !UCONFIG_NO_FORMATTING */
560 
566  U_I18N_API virtual UClassID getDynamicClassID() const override;
567 
574 
575 private:
580 
584  DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
585 
591 
596  DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
597 
598  static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
599 
600  Locale pLocale; // pattern locale
601  FormatParser *fp;
602  DateTimeMatcher* dtMatcher;
603  DistanceInfo *distanceInfo;
604  PatternMap *patternMap;
605  UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
606  UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][UDATPG_WIDTH_COUNT];
607  UnicodeString dateTimeFormat[4];
608  UnicodeString decimal;
609  DateTimeMatcher *skipMatcher;
610  Hashtable *fAvailableFormatKeyHash;
611  UnicodeString emptyString;
612  char16_t fDefaultHourFormatChar;
613 
614  int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
615 
616  // Internal error code used for recording/reporting errors that occur during methods that do not
617  // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
618  // When this is set to an error the object is in an invalid state.
619  UErrorCode internalErrorCode;
620 
621  /* internal flags masks for adjustFieldTypes etc. */
622  enum {
623  kDTPGNoFlags = 0,
624  kDTPGFixFractionalSeconds = 1,
625  kDTPGSkeletonUsesCapJ = 2
626  // with #13183, no longer need flags for b, B
627  };
628 
629  void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
630  void addCanonicalItems(UErrorCode &status);
631  void addICUPatterns(const Locale& locale, UErrorCode& status);
632  void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
633  void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
634  void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
635  void addCLDRData(const Locale& locale, UErrorCode& status);
636  UDateTimePatternConflict addPatternWithOptionalSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
637  void initHashtable(UErrorCode& status);
638  void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
639  void setDecimalSymbols(const Locale& locale, UErrorCode& status);
640  UDateTimePatternField getAppendFormatNumber(const char* field) const;
641  // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
642  UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
643  void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
644  UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
645  void getAppendName(UDateTimePatternField field, UnicodeString& value);
646  UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
647  const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = nullptr);
648  UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
649  UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
650  int32_t getTopBitNumber(int32_t foundMask) const;
651  void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
652  UBool isAvailableFormatSet(const UnicodeString &key) const;
653  void copyHashtable(Hashtable *other, UErrorCode &status);
654  UBool isCanonicalItem(const UnicodeString& item) const;
655  static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
656  void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
657 
658  struct U_HIDDEN AppendItemFormatsSink;
659  struct U_HIDDEN AppendItemNamesSink;
660  struct U_HIDDEN AvailableFormatsSink;
661 } ;// end class DateTimePatternGenerator
662 
663 U_NAMESPACE_END
664 
665 #endif /* U_SHOW_CPLUSPLUS_API */
666 
667 #endif
This class provides flexible generation of date format patterns, like "yy-MM-dd".
Definition: dtptngen.h:58
static U_I18N_API DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
U_I18N_API UnicodeString replaceFieldTypes(const UnicodeString &pattern, const UnicodeString &skeleton, UErrorCode &status)
Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.
static U_I18N_API DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
static U_I18N_API DateTimePatternGenerator * createInstanceNoStdPat(const Locale &uLocale, UErrorCode &status)
For ICU use only.
static U_I18N_API UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
U_I18N_API void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
U_I18N_API UDateFormatHourCycle getDefaultHourCycle(UErrorCode &status) const
Get the default hour cycle for a locale.
U_I18N_API UnicodeString replaceFieldTypes(const UnicodeString &pattern, const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.
U_I18N_API const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
U_I18N_API UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString &pattern, const UnicodeString &skeletonToUse, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Like addPattern, but associates the pattern with the given skeleton.
U_I18N_API bool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
U_I18N_API const UnicodeString & getDecimal() const
Getter corresponding to setDecimal.
U_I18N_API UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const
The general interface to get a display name for a particular date/time field, in one of several possi...
U_I18N_API const UnicodeString & getDateTimeFormat(UDateFormatStyle style, UErrorCode &status) const
Getter corresponding to setDateTimeFormat.
U_I18N_API bool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
U_I18N_API DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
static U_I18N_API UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
U_I18N_API StringEnumeration * getRedundants(UErrorCode &status)
Return a list of redundant patterns are those which if removed, make no difference in the resulting g...
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
static U_I18N_API DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
U_I18N_API const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
U_I18N_API UnicodeString getBestPattern(const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Return the best pattern matching the input skeleton.
U_I18N_API const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
U_I18N_API UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
virtual U_I18N_API ~DateTimePatternGenerator()
Destructor.
U_I18N_API UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
U_I18N_API void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
U_I18N_API StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
U_I18N_API void setDateTimeFormat(UDateFormatStyle style, const UnicodeString &dateTimeFormat, UErrorCode &status)
dateTimeFormats are message patterns used to compose combinations of date and time patterns.
U_I18N_API void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
U_I18N_API const UnicodeString & getAppendItemName(UDateTimePatternField field) const
Getter corresponding to setAppendItemNames.
U_I18N_API StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
U_I18N_API UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
U_I18N_API UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
U_I18N_API void setAppendItemFormat(UDateTimePatternField field, const UnicodeString &value)
An AppendItem format is a pattern used to append a field if there is no good match.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
C++ API: Abstract class for converting dates.
C++ API: Locale ID object.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:837
#define U_HIDDEN
This is used to mark internal structs declared within external classes, to prevent the internal struc...
Definition: platform.h:814
C API: DateFormat.
UDateFormatStyle
The possible date/time format styles.
Definition: udat.h:162
UDateFormatHourCycle
Hour Cycle.
Definition: udat.h:983
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:108
@ UDATPG_NARROW
Definition: udatpg.h:114
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:143
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:124
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:126
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:59
@ UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:100
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition: utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316