ICU 65.1  65.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:
66  static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
67 
75  static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
76 
77 #ifndef U_HIDE_INTERNAL_API
78 
84  static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
85 
86 #endif /* U_HIDE_INTERNAL_API */
87 
94  static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
95 
100  virtual ~DateTimePatternGenerator();
101 
107  DateTimePatternGenerator* clone() const;
108 
116  UBool operator==(const DateTimePatternGenerator& other) const;
117 
125  UBool operator!=(const DateTimePatternGenerator& other) const;
126 
137  static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
138 
151  UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
152  The function is commented out because it is a stable API calling a draft API.
153  After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
154  these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
155  return staticGetSkeleton(pattern, status);
156  }*/
157 
171  static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
172 
188  UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
189  The function is commented out because it is a stable API calling a draft API.
190  After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
191  these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
192  return staticGetBaseSkeleton(pattern, status);
193  }*/
194 
220  UDateTimePatternConflict addPattern(const UnicodeString& pattern,
221  UBool override,
222  UnicodeString& conflictingPattern,
223  UErrorCode& status);
224 
243  void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
244 
253  const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
254 
266  void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
267 
278  const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
279 
289  UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
290 
312  void setDateTimeFormat(const UnicodeString& dateTimeFormat);
313 
319  const UnicodeString& getDateTimeFormat() const;
320 
339  UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
340 
341 
361  UnicodeString getBestPattern(const UnicodeString& skeleton,
363  UErrorCode& status);
364 
365 
387  UnicodeString replaceFieldTypes(const UnicodeString& pattern,
388  const UnicodeString& skeleton,
389  UErrorCode& status);
390 
413  UnicodeString replaceFieldTypes(const UnicodeString& pattern,
414  const UnicodeString& skeleton,
416  UErrorCode& status);
417 
429  StringEnumeration* getSkeletons(UErrorCode& status) const;
430 
437  const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
438 
448  StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
449 
450 #ifndef U_HIDE_INTERNAL_API
451 
463  StringEnumeration* getRedundants(UErrorCode& status);
464 #endif /* U_HIDE_INTERNAL_API */
465 
477  void setDecimal(const UnicodeString& decimal);
478 
484  const UnicodeString& getDecimal() const;
485 
491  virtual UClassID getDynamicClassID() const;
492 
498  static UClassID U_EXPORT2 getStaticClassID(void);
499 
500 private:
505 
509  DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
510 
516 
521  DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
522 
523  // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
524  // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
525 
526  Locale pLocale; // pattern locale
527  FormatParser *fp;
528  DateTimeMatcher* dtMatcher;
529  DistanceInfo *distanceInfo;
530  PatternMap *patternMap;
531  UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
532  // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
533  UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
534  UnicodeString dateTimeFormat;
535  UnicodeString decimal;
536  DateTimeMatcher *skipMatcher;
537  Hashtable *fAvailableFormatKeyHash;
538  UnicodeString emptyString;
539  char16_t fDefaultHourFormatChar;
540 
541  int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
542 
543  // Internal error code used for recording/reporting errors that occur during methods that do not
544  // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
545  // When this is set to an error the object is in an invalid state.
546  UErrorCode internalErrorCode;
547 
548  /* internal flags masks for adjustFieldTypes etc. */
549  enum {
550  kDTPGNoFlags = 0,
551  kDTPGFixFractionalSeconds = 1,
552  kDTPGSkeletonUsesCapJ = 2
553  // with #13183, no longer need flags for b, B
554  };
555 
556  void initData(const Locale &locale, UErrorCode &status);
557  void addCanonicalItems(UErrorCode &status);
558  void addICUPatterns(const Locale& locale, UErrorCode& status);
559  void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
560  void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
561  void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
562  void addCLDRData(const Locale& locale, UErrorCode& status);
563  UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
564  void initHashtable(UErrorCode& status);
565  void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
566  void setDecimalSymbols(const Locale& locale, UErrorCode& status);
567  UDateTimePatternField getAppendFormatNumber(const char* field) const;
568  // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
569  UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
570  void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
571  UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
572  void getAppendName(UDateTimePatternField field, UnicodeString& value);
573  UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
574  const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
575  UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
576  UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
577  int32_t getTopBitNumber(int32_t foundMask) const;
578  void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
579  UBool isAvailableFormatSet(const UnicodeString &key) const;
580  void copyHashtable(Hashtable *other, UErrorCode &status);
581  UBool isCanonicalItem(const UnicodeString& item) const;
582  static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
583  void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
584 
585  struct AppendItemFormatsSink;
586  struct AppendItemNamesSink;
587  struct AvailableFormatsSink;
588 } ;// end class DateTimePatternGenerator
589 
590 U_NAMESPACE_END
591 
592 #endif /* U_SHOW_CPLUSPLUS_API */
593 
594 #endif
This class provides flexible generation of date format patterns, like "yy-MM-dd". ...
Definition: dtptngen.h:58
C++ API: Unicode String.
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:870
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:251
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:139
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:96
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:55
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:104
C++ API: Abstract class for converting dates.
C++ API: Locale ID object.
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
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:120
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195