ICU 59.1  59.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/datefmt.h"
18 #include "unicode/locid.h"
19 #include "unicode/udat.h"
20 #include "unicode/udatpg.h"
21 
23 
30 class CharString;
31 class Hashtable;
32 class FormatParser;
33 class DateTimeMatcher;
34 class DistanceInfo;
35 class PatternMap;
36 class PtnSkeleton;
37 class SharedDateTimePatternGenerator;
38 
54 public:
61  static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
62 
70  static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
71 
72 #ifndef U_HIDE_INTERNAL_API
73 
79  static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
80 
81 #endif /* U_HIDE_INTERNAL_API */
82 
89  static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
90 
95  virtual ~DateTimePatternGenerator();
96 
102  DateTimePatternGenerator* clone() const;
103 
111  UBool operator==(const DateTimePatternGenerator& other) const;
112 
120  UBool operator!=(const DateTimePatternGenerator& other) const;
121 
132  static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
133 
146  UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
147  The function is commented out because it is a stable API calling a draft API.
148  After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
149  these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
150  return staticGetSkeleton(pattern, status);
151  }*/
152 
166  static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
167 
183  UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
184  The function is commented out because it is a stable API calling a draft API.
185  After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
186  these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
187  return staticGetBaseSkeleton(pattern, status);
188  }*/
189 
215  UDateTimePatternConflict addPattern(const UnicodeString& pattern,
216  UBool override,
217  UnicodeString& conflictingPattern,
218  UErrorCode& status);
219 
238  void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
239 
248  const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
249 
261  void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
262 
271  const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
272 
294  void setDateTimeFormat(const UnicodeString& dateTimeFormat);
295 
301  const UnicodeString& getDateTimeFormat() const;
302 
321  UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
322 
323 
343  UnicodeString getBestPattern(const UnicodeString& skeleton,
345  UErrorCode& status);
346 
347 
369  UnicodeString replaceFieldTypes(const UnicodeString& pattern,
370  const UnicodeString& skeleton,
371  UErrorCode& status);
372 
395  UnicodeString replaceFieldTypes(const UnicodeString& pattern,
396  const UnicodeString& skeleton,
398  UErrorCode& status);
399 
411  StringEnumeration* getSkeletons(UErrorCode& status) const;
412 
419  const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
420 
430  StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
431 
432 #ifndef U_HIDE_INTERNAL_API
433 
445  StringEnumeration* getRedundants(UErrorCode& status);
446 #endif /* U_HIDE_INTERNAL_API */
447 
459  void setDecimal(const UnicodeString& decimal);
460 
466  const UnicodeString& getDecimal() const;
467 
473  virtual UClassID getDynamicClassID() const;
474 
480  static UClassID U_EXPORT2 getStaticClassID(void);
481 
482 private:
488 
493  DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
494 
501 
507  DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
508 
509  Locale pLocale; // pattern locale
510  FormatParser *fp;
511  DateTimeMatcher* dtMatcher;
512  DistanceInfo *distanceInfo;
513  PatternMap *patternMap;
514  UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
515  UnicodeString appendItemNames[UDATPG_FIELD_COUNT];
516  UnicodeString dateTimeFormat;
517  UnicodeString decimal;
518  DateTimeMatcher *skipMatcher;
519  Hashtable *fAvailableFormatKeyHash;
520  UnicodeString emptyString;
521  char16_t fDefaultHourFormatChar;
522 
523  int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
524 
525  /* internal flags masks for adjustFieldTypes etc. */
526  enum {
527  kDTPGNoFlags = 0,
528  kDTPGFixFractionalSeconds = 1,
529  kDTPGSkeletonUsesCapJ = 2,
530  kDTPGSkeletonUsesLowB = 3,
531  kDTPGSkeletonUsesCapB = 4
532  };
533 
534  void initData(const Locale &locale, UErrorCode &status);
535  void addCanonicalItems(UErrorCode &status);
536  void addICUPatterns(const Locale& locale, UErrorCode& status);
537  void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
538  void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
539  void consumeShortTimePattern(const UnicodeString& shortTimePattern, 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  UnicodeString& getMutableAppendItemName(UDateTimePatternField field);
548  void getAppendName(UDateTimePatternField field, UnicodeString& value);
549  int32_t getCanonicalIndex(const UnicodeString& field);
550  const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, const PtnSkeleton** specifiedSkeletonPtr = 0);
551  UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
552  UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
553  int32_t getTopBitNumber(int32_t foundMask);
554  void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
555  UBool isAvailableFormatSet(const UnicodeString &key) const;
556  void copyHashtable(Hashtable *other, UErrorCode &status);
557  UBool isCanonicalItem(const UnicodeString& item) const;
558  static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
559  void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
560 
561  struct AppendItemFormatsSink;
562  struct AppendItemNamesSink;
563  struct AvailableFormatsSink;
564 } ;// end class DateTimePatternGenerator
565 
567 
568 #endif
This class provides flexible generation of date format patterns, like "yy-MM-dd". ...
Definition: dtptngen.h:53
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:871
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:57
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
C API: DateFormat.
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:124
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:95
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:55
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
C++ API: Abstract class for converting dates.
C++ API: Locale ID object.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:105
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188