ICU 68.2  68.2
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 
75  static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
76 
77 #ifndef U_HIDE_INTERNAL_API
78 
84  static DateTimePatternGenerator* U_EXPORT2 createInstanceNoStdPat(const Locale& uLocale, UErrorCode& status);
85 
91  static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
92 
93 #endif /* U_HIDE_INTERNAL_API */
94 
102 
108 
115 
124 
133 
144  static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
145 
158  UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
159  The function is commented out because it is a stable API calling a draft API.
160  After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
161  these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
162  return staticGetSkeleton(pattern, status);
163  }*/
164 
179 
195  UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
196  The function is commented out because it is a stable API calling a draft API.
197  After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
198  these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
199  return staticGetBaseSkeleton(pattern, status);
200  }*/
201 
228  UBool override,
229  UnicodeString& conflictingPattern,
230  UErrorCode& status);
231 
251 
261 
274 
286 
297 
319  void setDateTimeFormat(const UnicodeString& dateTimeFormat);
320 
327 
347 
348 
370  UErrorCode& status);
371 
372 
395  const UnicodeString& skeleton,
396  UErrorCode& status);
397 
421  const UnicodeString& skeleton,
423  UErrorCode& status);
424 
437 
444  const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
445 
456 
457 #ifndef U_HIDE_INTERNAL_API
458 
471 #endif /* U_HIDE_INTERNAL_API */
472 
484  void setDecimal(const UnicodeString& decimal);
485 
491  const UnicodeString& getDecimal() const;
492 
493 #if !UCONFIG_NO_FORMATTING
494 
495 #ifndef U_HIDE_DRAFT_API
496 
509 #endif /* U_HIDE_DRAFT_API */
510 
511 #endif /* #if !UCONFIG_NO_FORMATTING */
512 
518  virtual UClassID getDynamicClassID() const;
519 
525  static UClassID U_EXPORT2 getStaticClassID(void);
526 
527 private:
532 
536  DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
537 
543 
548  DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
549 
550  // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
551  // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
552 
553  Locale pLocale; // pattern locale
554  FormatParser *fp;
555  DateTimeMatcher* dtMatcher;
556  DistanceInfo *distanceInfo;
557  PatternMap *patternMap;
558  UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
559  // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
560  UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
561  UnicodeString dateTimeFormat;
562  UnicodeString decimal;
563  DateTimeMatcher *skipMatcher;
564  Hashtable *fAvailableFormatKeyHash;
565  UnicodeString emptyString;
566  char16_t fDefaultHourFormatChar;
567 
568  int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
569 
570  // Internal error code used for recording/reporting errors that occur during methods that do not
571  // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
572  // When this is set to an error the object is in an invalid state.
573  UErrorCode internalErrorCode;
574 
575  /* internal flags masks for adjustFieldTypes etc. */
576  enum {
577  kDTPGNoFlags = 0,
578  kDTPGFixFractionalSeconds = 1,
579  kDTPGSkeletonUsesCapJ = 2
580  // with #13183, no longer need flags for b, B
581  };
582 
583  void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
584  void addCanonicalItems(UErrorCode &status);
585  void addICUPatterns(const Locale& locale, UErrorCode& status);
586  void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
587  void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
588  void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
589  void addCLDRData(const Locale& locale, UErrorCode& status);
590  UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
591  void initHashtable(UErrorCode& status);
592  void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
593  void setDecimalSymbols(const Locale& locale, UErrorCode& status);
594  UDateTimePatternField getAppendFormatNumber(const char* field) const;
595  // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
596  UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
597  void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
598  UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
599  void getAppendName(UDateTimePatternField field, UnicodeString& value);
600  UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
601  const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
602  UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
603  UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
604  int32_t getTopBitNumber(int32_t foundMask) const;
605  void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
606  UBool isAvailableFormatSet(const UnicodeString &key) const;
607  void copyHashtable(Hashtable *other, UErrorCode &status);
608  UBool isCanonicalItem(const UnicodeString& item) const;
609  static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
610  void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
611 
612  struct AppendItemFormatsSink;
613  struct AppendItemNamesSink;
614  struct AvailableFormatsSink;
615 } ;// end class DateTimePatternGenerator
616 
617 U_NAMESPACE_END
618 
619 #endif /* U_SHOW_CPLUSPLUS_API */
620 
621 #endif
icu::DateTimePatternGenerator::addPattern
UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
UDATPG_FIELD_COUNT
@ UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:100
icu::DateTimePatternGenerator::getFieldDisplayName
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...
icu::DateTimePatternGenerator::replaceFieldTypes
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.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UDateTimePatternConflict
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:143
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::DateTimePatternGenerator::getBestPattern
UnicodeString getBestPattern(const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Return the best pattern matching the input skeleton.
udatpg.h
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
icu::DateTimePatternGenerator::operator!=
UBool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
icu::DateTimePatternGenerator::setDecimal
void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
U_CALLCONV
#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
icu::DateTimePatternGenerator::getRedundants
StringEnumeration * getRedundants(UErrorCode &status)
Return a list of redundant patterns are those which if removed, make no difference in the resulting g...
icu::DateTimePatternGenerator::staticGetBaseSkeleton
static UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
icu::DateTimePatternGenerator
This class provides flexible generation of date format patterns, like "yy-MM-dd".
Definition: dtptngen.h:58
UDateTimePatternField
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:59
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::DateTimePatternGenerator::getBestPattern
UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
icu::DateTimePatternGenerator::setAppendItemName
void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::DateTimePatternGenerator::getSkeleton
UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
icu::DateTimePatternGenerator::getAppendItemFormat
const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UDateFormatHourCycle
UDateFormatHourCycle
Hour Cycle.
Definition: udat.h:984
icu::DateTimePatternGenerator::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::DateTimePatternGenerator::clone
DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
UDATPG_MATCH_NO_OPTIONS
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:126
icu::DateTimePatternGenerator::getStaticClassID
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DateTimePatternGenerator::getSkeletons
StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
icu::DateTimePatternGenerator::replaceFieldTypes
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.
icu::DateTimePatternGenerator::getDecimal
const UnicodeString & getDecimal() const
Getter corresponding to setDecimal.
UDateTimePatternMatchOptions
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:124
icu::DateTimePatternGenerator::createInstance
static DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
icu::DateTimePatternGenerator::getAppendItemName
const UnicodeString & getAppendItemName(UDateTimePatternField field) const
Getter corresponding to setAppendItemNames.
datefmt.h
C++ API: Abstract class for converting dates.
icu::DateTimePatternGenerator::getDefaultHourCycle
UDateFormatHourCycle getDefaultHourCycle(UErrorCode &status) const
Get the default hour cycle for a locale.
icu::DateTimePatternGenerator::operator==
UBool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
icu::DateTimePatternGenerator::setDateTimeFormat
void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
icu::DateTimePatternGenerator::getDateTimeFormat
const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
icu::DateTimePatternGenerator::internalMakeInstance
static DateTimePatternGenerator * internalMakeInstance(const Locale &uLocale, UErrorCode &status)
For ICU use only.
locid.h
C++ API: Locale ID object.
icu::DateTimePatternGenerator::getPatternForSkeleton
const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
icu::DateTimePatternGenerator::setAppendItemFormat
void setAppendItemFormat(UDateTimePatternField field, const UnicodeString &value)
An AppendItem format is a pattern used to append a field if there is no good match.
icu::DateTimePatternGenerator::staticGetSkeleton
static UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
icu::DateTimePatternGenerator::createEmptyInstance
static DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
icu::DateTimePatternGenerator::~DateTimePatternGenerator
virtual ~DateTimePatternGenerator()
Destructor.
icu::DateTimePatternGenerator::getBaseSkeleton
UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
udat.h
C API: DateFormat.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::DateTimePatternGenerator::createInstanceNoStdPat
static DateTimePatternGenerator * createInstanceNoStdPat(const Locale &uLocale, UErrorCode &status)
For ICU use only.
icu::DateTimePatternGenerator::createInstance
static DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
unistr.h
C++ API: Unicode String.
icu::DateTimePatternGenerator::getBaseSkeletons
StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
UDateTimePGDisplayWidth
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:108