ICU 71.1 71.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
58 class U_I18N_API DateTimePatternGenerator : public UObject {
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 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
101 static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
102
107 virtual ~DateTimePatternGenerator();
108
114 DateTimePatternGenerator* clone() const;
115
123 bool operator==(const DateTimePatternGenerator& other) const;
124
132 bool operator!=(const DateTimePatternGenerator& other) const;
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
178 static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
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
227 UDateTimePatternConflict addPattern(const UnicodeString& pattern,
228 UBool override,
229 UnicodeString& conflictingPattern,
230 UErrorCode& status);
231
250 void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
251
260 const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
261
273 void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
274
285 const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
286
296 UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
297
324 void setDateTimeFormat(const UnicodeString& dateTimeFormat);
325
337 const UnicodeString& getDateTimeFormat() const;
338
339 #if !UCONFIG_NO_FORMATTING
340 #ifndef U_HIDE_DRAFT_API
341
363 void setDateTimeFormat(UDateFormatStyle style, const UnicodeString& dateTimeFormat,
364 UErrorCode& status);
365
383 const UnicodeString& getDateTimeFormat(UDateFormatStyle style,
384 UErrorCode& status) const;
385 #endif /* U_HIDE_DRAFT_API */
386 #endif /* #if !UCONFIG_NO_FORMATTING */
387
406 UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
407
408
428 UnicodeString getBestPattern(const UnicodeString& skeleton,
429 UDateTimePatternMatchOptions options,
430 UErrorCode& status);
431
432
454 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
455 const UnicodeString& skeleton,
456 UErrorCode& status);
457
480 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
481 const UnicodeString& skeleton,
482 UDateTimePatternMatchOptions options,
483 UErrorCode& status);
484
496 StringEnumeration* getSkeletons(UErrorCode& status) const;
497
504 const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
505
515 StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
516
517 #ifndef U_HIDE_INTERNAL_API
518
530 StringEnumeration* getRedundants(UErrorCode& status);
531 #endif /* U_HIDE_INTERNAL_API */
532
544 void setDecimal(const UnicodeString& decimal);
545
551 const UnicodeString& getDecimal() const;
552
553 #if !UCONFIG_NO_FORMATTING
554
567 UDateFormatHourCycle getDefaultHourCycle(UErrorCode& status) const;
568
569 #endif /* #if !UCONFIG_NO_FORMATTING */
570
576 virtual UClassID getDynamicClassID() const override;
577
583 static UClassID U_EXPORT2 getStaticClassID(void);
584
585 private:
589 DateTimePatternGenerator(UErrorCode & status);
590
594 DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
595
600 DateTimePatternGenerator(const DateTimePatternGenerator& other);
601
606 DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
607
608 static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
609
610 Locale pLocale; // pattern locale
611 FormatParser *fp;
612 DateTimeMatcher* dtMatcher;
613 DistanceInfo *distanceInfo;
614 PatternMap *patternMap;
615 UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
616 UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][UDATPG_WIDTH_COUNT];
617 UnicodeString dateTimeFormat[4];
618 UnicodeString decimal;
619 DateTimeMatcher *skipMatcher;
620 Hashtable *fAvailableFormatKeyHash;
621 UnicodeString emptyString;
622 char16_t fDefaultHourFormatChar;
623
624 int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
625
626 // Internal error code used for recording/reporting errors that occur during methods that do not
627 // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
628 // When this is set to an error the object is in an invalid state.
629 UErrorCode internalErrorCode;
630
631 /* internal flags masks for adjustFieldTypes etc. */
632 enum {
633 kDTPGNoFlags = 0,
634 kDTPGFixFractionalSeconds = 1,
635 kDTPGSkeletonUsesCapJ = 2
636 // with #13183, no longer need flags for b, B
637 };
638
639 void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
640 void addCanonicalItems(UErrorCode &status);
641 void addICUPatterns(const Locale& locale, UErrorCode& status);
642 void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
643 void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
644 void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
645 void addCLDRData(const Locale& locale, UErrorCode& status);
646 UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
647 void initHashtable(UErrorCode& status);
648 void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
649 void setDecimalSymbols(const Locale& locale, UErrorCode& status);
650 UDateTimePatternField getAppendFormatNumber(const char* field) const;
651 // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
652 UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
653 void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
654 UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
655 void getAppendName(UDateTimePatternField field, UnicodeString& value);
656 UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
657 const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
658 UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
659 UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
660 int32_t getTopBitNumber(int32_t foundMask) const;
661 void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
662 UBool isAvailableFormatSet(const UnicodeString &key) const;
663 void copyHashtable(Hashtable *other, UErrorCode &status);
664 UBool isCanonicalItem(const UnicodeString& item) const;
665 static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
666 void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
667
668 struct AppendItemFormatsSink;
669 struct AppendItemNamesSink;
670 struct AvailableFormatsSink;
671 } ;// end class DateTimePatternGenerator
672
673 U_NAMESPACE_END
674
675 #endif /* U_SHOW_CPLUSPLUS_API */
676
677 #endif
UDATPG_FIELD_COUNT
@ UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:100
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
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
udatpg.h
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
U_CALLCONV
#define U_CALLCONV
Definition: platform.h:870
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
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::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
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:983
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UDATPG_MATCH_NO_OPTIONS
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:126
UDATPG_NARROW
@ UDATPG_NARROW
Definition: udatpg.h:114
UDateTimePatternMatchOptions
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:124
datefmt.h
C++ API: Abstract class for converting dates.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
UDateFormatStyle
UDateFormatStyle
The possible date/time format styles.
Definition: udat.h:162
locid.h
C++ API: Locale ID object.
udat.h
C API: DateFormat.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
unistr.h
C++ API: Unicode String.
UDateTimePGDisplayWidth
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:108