ICU 67.1 67.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
27U_NAMESPACE_BEGIN
28
33
34
35class CharString;
36class Hashtable;
37class FormatParser;
38class DateTimeMatcher;
39class DistanceInfo;
40class PatternMap;
41class PtnSkeleton;
42class SharedDateTimePatternGenerator;
43
58class U_I18N_API DateTimePatternGenerator : public UObject {
59public:
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
101
107 DateTimePatternGenerator* clone() const;
108
116 UBool operator==(const DateTimePatternGenerator& other) const;
117
125 UBool operator!=(const DateTimePatternGenerator& other) const;
126
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
172
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
221 UBool override,
222 UnicodeString& conflictingPattern,
223 UErrorCode& status);
224
244
254
267
279
290
312 void setDateTimeFormat(const UnicodeString& dateTimeFormat);
313
320
340
341
363 UErrorCode& status);
364
365
388 const UnicodeString& skeleton,
389 UErrorCode& status);
390
414 const UnicodeString& skeleton,
416 UErrorCode& status);
417
430
437 const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
438
449
450#ifndef U_HIDE_INTERNAL_API
464#endif /* U_HIDE_INTERNAL_API */
465
477 void setDecimal(const UnicodeString& decimal);
478
484 const UnicodeString& getDecimal() const;
485
486#if !UCONFIG_NO_FORMATTING
487
488#ifndef U_HIDE_DRAFT_API
502#endif /* U_HIDE_DRAFT_API */
503
504#endif /* #if !UCONFIG_NO_FORMATTING */
505
512
518 static UClassID U_EXPORT2 getStaticClassID(void);
519
520private:
524 DateTimePatternGenerator(UErrorCode & status);
525
529 DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
530
535 DateTimePatternGenerator(const DateTimePatternGenerator& other);
536
541 DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
542
543 // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
544 // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
545
546 Locale pLocale; // pattern locale
547 FormatParser *fp;
548 DateTimeMatcher* dtMatcher;
549 DistanceInfo *distanceInfo;
550 PatternMap *patternMap;
551 UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
552 // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
553 UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
554 UnicodeString dateTimeFormat;
555 UnicodeString decimal;
556 DateTimeMatcher *skipMatcher;
557 Hashtable *fAvailableFormatKeyHash;
558 UnicodeString emptyString;
559 char16_t fDefaultHourFormatChar;
560
561 int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
562
563 // Internal error code used for recording/reporting errors that occur during methods that do not
564 // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
565 // When this is set to an error the object is in an invalid state.
566 UErrorCode internalErrorCode;
567
568 /* internal flags masks for adjustFieldTypes etc. */
569 enum {
570 kDTPGNoFlags = 0,
571 kDTPGFixFractionalSeconds = 1,
572 kDTPGSkeletonUsesCapJ = 2
573 // with #13183, no longer need flags for b, B
574 };
575
576 void initData(const Locale &locale, UErrorCode &status);
577 void addCanonicalItems(UErrorCode &status);
578 void addICUPatterns(const Locale& locale, UErrorCode& status);
579 void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
580 void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
581 void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
582 void addCLDRData(const Locale& locale, UErrorCode& status);
583 UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
584 void initHashtable(UErrorCode& status);
585 void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
586 void setDecimalSymbols(const Locale& locale, UErrorCode& status);
587 UDateTimePatternField getAppendFormatNumber(const char* field) const;
588 // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
589 UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
590 void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
591 UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
592 void getAppendName(UDateTimePatternField field, UnicodeString& value);
593 UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
594 const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
595 UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
596 UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
597 int32_t getTopBitNumber(int32_t foundMask) const;
598 void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
599 UBool isAvailableFormatSet(const UnicodeString &key) const;
600 void copyHashtable(Hashtable *other, UErrorCode &status);
601 UBool isCanonicalItem(const UnicodeString& item) const;
602 static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
603 void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
604
605 struct AppendItemFormatsSink;
606 struct AppendItemNamesSink;
607 struct AvailableFormatsSink;
608} ;// end class DateTimePatternGenerator
609
610U_NAMESPACE_END
611
612#endif /* U_SHOW_CPLUSPLUS_API */
613
614#endif
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.
const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
static DateTimePatternGenerator * internalMakeInstance(const Locale &uLocale, UErrorCode &status)
For ICU use only.
UBool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
UBool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
static DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
void setAppendItemFormat(UDateTimePatternField field, const UnicodeString &value)
An AppendItem format is a pattern used to append a field if there is no good match.
UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
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...
StringEnumeration * getRedundants(UErrorCode &status)
Return a list of redundant patterns are those which if removed, make no difference in the resulting g...
StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
static UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
static DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
static DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
UDateFormatHourCycle getDefaultHourCycle(UErrorCode &status) const
Get the default hour cycle for a locale.
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.
const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
static UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
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 & getDecimal() const
Getter corresponding to setDecimal.
UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
virtual ~DateTimePatternGenerator()
Destructor.
UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:61
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:295
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:869
C API: DateFormat.
UDateFormatHourCycle
Hour Cycle.
Definition udat.h:966
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition udatpg.h:105
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition udatpg.h:140
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition udatpg.h:121
@ UDATPG_MATCH_NO_OPTIONS
Definition udatpg.h:123
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition udatpg.h:56
@ UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition udatpg.h:97
int8_t UBool
The ICU boolean type.
Definition umachine.h:261
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:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301