ICU 57.1  57.1
dtptngen.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 *
7 * File DTPTNGEN.H
8 *
9 *******************************************************************************
10 */
11 
12 #ifndef __DTPTNGEN_H__
13 #define __DTPTNGEN_H__
14 
15 #include "unicode/datefmt.h"
16 #include "unicode/locid.h"
17 #include "unicode/udat.h"
18 #include "unicode/udatpg.h"
19 
21 
28 class Hashtable;
29 class FormatParser;
30 class DateTimeMatcher;
31 class DistanceInfo;
32 class PatternMap;
33 class PtnSkeleton;
34 class SharedDateTimePatternGenerator;
35 
51 public:
59 
67  static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
68 
69 #ifndef U_HIDE_INTERNAL_API
70 
76  static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
77 
78 #endif /* U_HIDE_INTERNAL_API */
79 
87 
93 
100 
109 
118 
119 #ifndef U_HIDE_DRAFT_API
130  static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
131 #endif /* U_HIDE_DRAFT_API */
132 
145  UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
146  The function is commented out because it is a stable API calling a draft API.
147  After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
148  these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
149  return staticGetSkeleton(pattern, status);
150  }*/
151 
152 #ifndef U_HIDE_DRAFT_API
167 #endif /* U_HIDE_DRAFT_API */
168 
184  UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
185  The function is commented out because it is a stable API calling a draft API.
186  After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
187  these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
188  return staticGetBaseSkeleton(pattern, status);
189  }*/
190 
217  UBool override,
218  UnicodeString& conflictingPattern,
219  UErrorCode& status);
220 
240 
250 
263 
273 
295  void setDateTimeFormat(const UnicodeString& dateTimeFormat);
296 
303 
323 
324 
346  UErrorCode& status);
347 
348 
371  const UnicodeString& skeleton,
372  UErrorCode& status);
373 
397  const UnicodeString& skeleton,
399  UErrorCode& status);
400 
413 
420  const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
421 
432 
433 #ifndef U_HIDE_INTERNAL_API
447 #endif /* U_HIDE_INTERNAL_API */
448 
460  void setDecimal(const UnicodeString& decimal);
461 
467  const UnicodeString& getDecimal() const;
468 
474  virtual UClassID getDynamicClassID() const;
475 
481  static UClassID U_EXPORT2 getStaticClassID(void);
482 
483 private:
489 
494  DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
495 
502 
508  DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
509 
510  Locale pLocale; // pattern locale
511  FormatParser *fp;
512  DateTimeMatcher* dtMatcher;
513  DistanceInfo *distanceInfo;
514  PatternMap *patternMap;
515  UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
516  UnicodeString appendItemNames[UDATPG_FIELD_COUNT];
517  UnicodeString dateTimeFormat;
518  UnicodeString decimal;
519  DateTimeMatcher *skipMatcher;
520  Hashtable *fAvailableFormatKeyHash;
521  UnicodeString hackPattern;
522  UnicodeString emptyString;
523  UChar fDefaultHourFormatChar;
524 
525  int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
526 
527  /* internal flags masks for adjustFieldTypes etc. */
528  enum {
529  kDTPGNoFlags = 0,
530  kDTPGFixFractionalSeconds = 1,
531  kDTPGSkeletonUsesCapJ = 2,
532  kDTPGSkeletonUsesLowB = 3,
533  kDTPGSkeletonUsesCapB = 4
534  };
535 
536  void initData(const Locale &locale, UErrorCode &status);
537  void addCanonicalItems();
538  void addICUPatterns(const Locale& locale, UErrorCode& status);
539  void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
540  void addCLDRData(const Locale& locale, UErrorCode& status);
541  UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
542  void initHashtable(UErrorCode& status);
543  void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
544  void setDecimalSymbols(const Locale& locale, UErrorCode& status);
545  UDateTimePatternField getAppendFormatNumber(const char* field) const;
546  UDateTimePatternField getAppendNameNumber(const char* field) const;
547  void getAppendName(UDateTimePatternField field, UnicodeString& value);
548  int32_t getCanonicalIndex(const UnicodeString& field);
549  const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, const PtnSkeleton** specifiedSkeletonPtr = 0);
550  UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
551  UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
552  int32_t getTopBitNumber(int32_t foundMask);
553  void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
554  UBool isAvailableFormatSet(const UnicodeString &key) const;
555  void copyHashtable(Hashtable *other, UErrorCode &status);
556  UBool isCanonicalItem(const UnicodeString& item) const;
557  static void loadAllowedHourFormatsData(UErrorCode &status);
558  void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
559 } ;// end class DateTimePatternGenerator
560 
562 
563 #endif
This class provides flexible generation of date format patterns, like "yy-MM-dd".
Definition: dtptngen.h:50
const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
static DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
static UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
static UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
static DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
UBool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
const UnicodeString & getDecimal() const
Getter corresponding to setDecimal.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
UBool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
static DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
StringEnumeration * getRedundants(UErrorCode &status)
Return a list of redundant patterns are those which if removed, make no difference in the resulting g...
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.
UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
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.
const UnicodeString & getAppendItemName(UDateTimePatternField field) const
Getter corresponding to setAppendItemNames.
UnicodeString getBestPattern(const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Return the best pattern matching the input skeleton.
void setAppendItemFormat(UDateTimePatternField field, const UnicodeString &value)
An AppendItem format is a pattern used to append a field if there is no good match.
virtual ~DateTimePatternGenerator()
Destructor.
UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
static DateTimePatternGenerator * internalMakeInstance(const Locale &uLocale, UErrorCode &status)
For ICU use only.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
C++ API: Abstract class for converting dates.
C++ API: Locale ID object.
C API: DateFormat.
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:116
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:97
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:99
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:53
@ UDATPG_FIELD_COUNT
Definition: udatpg.h:87
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:312
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129