ICU 76.1: i18n/unicode/dtptngen.h Source File

ICU 76.1 76.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
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 bool operator==(const DateTimePatternGenerator& other) const;
117
125 bool 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
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
273 const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
274
284 UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
285
312 void setDateTimeFormat(const UnicodeString& dateTimeFormat);
313
325 const UnicodeString& getDateTimeFormat() const;
326
327 #if !UCONFIG_NO_FORMATTING
350 void setDateTimeFormat(UDateFormatStyle style, const UnicodeString& dateTimeFormat,
351 UErrorCode& status);
352
370 const UnicodeString& getDateTimeFormat(UDateFormatStyle style,
371 UErrorCode& status) const;
372 #endif /* #if !UCONFIG_NO_FORMATTING */
373
387 UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
388
389
409 UnicodeString getBestPattern(const UnicodeString& skeleton,
410 UDateTimePatternMatchOptions options,
411 UErrorCode& status);
412
413
430 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
431 const UnicodeString& skeleton,
432 UErrorCode& status);
433
456 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
457 const UnicodeString& skeleton,
458 UDateTimePatternMatchOptions options,
459 UErrorCode& status);
460
472 StringEnumeration* getSkeletons(UErrorCode& status) const;
473
480 const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
481
491 StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
492
493 #ifndef U_HIDE_INTERNAL_API
506 StringEnumeration* getRedundants(UErrorCode& status);
507 #endif /* U_HIDE_INTERNAL_API */
508
520 void setDecimal(const UnicodeString& decimal);
521
527 const UnicodeString& getDecimal() const;
528
529 #if !UCONFIG_NO_FORMATTING
530
543 UDateFormatHourCycle getDefaultHourCycle(UErrorCode& status) const;
544
545 #endif /* #if !UCONFIG_NO_FORMATTING */
546
552 virtual UClassID getDynamicClassID() const override;
553
559 static UClassID U_EXPORT2 getStaticClassID();
560
561 private:
565 DateTimePatternGenerator(UErrorCode & status);
566
570 DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
571
576 DateTimePatternGenerator(const DateTimePatternGenerator& other);
577
582 DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
583
584 static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
585
586 Locale pLocale; // pattern locale
587 FormatParser *fp;
588 DateTimeMatcher* dtMatcher;
589 DistanceInfo *distanceInfo;
590 PatternMap *patternMap;
591 UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
592 UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][UDATPG_WIDTH_COUNT];
593 UnicodeString dateTimeFormat[4];
594 UnicodeString decimal;
595 DateTimeMatcher *skipMatcher;
596 Hashtable *fAvailableFormatKeyHash;
597 UnicodeString emptyString;
598 char16_t fDefaultHourFormatChar;
599
600 int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
601
602 // Internal error code used for recording/reporting errors that occur during methods that do not
603 // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
604 // When this is set to an error the object is in an invalid state.
605 UErrorCode internalErrorCode;
606
607 /* internal flags masks for adjustFieldTypes etc. */
608 enum {
609 kDTPGNoFlags = 0,
610 kDTPGFixFractionalSeconds = 1,
611 kDTPGSkeletonUsesCapJ = 2
612 // with #13183, no longer need flags for b, B
613 };
614
615 void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
616 void addCanonicalItems(UErrorCode &status);
617 void addICUPatterns(const Locale& locale, UErrorCode& status);
618 void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
619 void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
620 void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
621 void addCLDRData(const Locale& locale, UErrorCode& status);
622 UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
623 void initHashtable(UErrorCode& status);
624 void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
625 void setDecimalSymbols(const Locale& locale, UErrorCode& status);
626 UDateTimePatternField getAppendFormatNumber(const char* field) const;
627 // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
628 UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
629 void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
630 UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
631 void getAppendName(UDateTimePatternField field, UnicodeString& value);
632 UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
633 const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = nullptr);
634 UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
635 UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
636 int32_t getTopBitNumber(int32_t foundMask) const;
637 void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
638 UBool isAvailableFormatSet(const UnicodeString &key) const;
639 void copyHashtable(Hashtable *other, UErrorCode &status);
640 UBool isCanonicalItem(const UnicodeString& item) const;
641 static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
642 void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
643
644 struct U_HIDDEN AppendItemFormatsSink;
645 struct U_HIDDEN AppendItemNamesSink;
646 struct U_HIDDEN AvailableFormatsSink;
647 } ;// end class DateTimePatternGenerator
648
649 U_NAMESPACE_END
650
651 #endif /* U_SHOW_CPLUSPLUS_API */
652
653 #endif
icu::DateTimePatternGenerator
This class provides flexible generation of date format patterns, like "yy-MM-dd".
Definition: dtptngen.h:58
icu::DateTimePatternGenerator::getBestPattern
UnicodeString getBestPattern(const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Return the best pattern matching the input skeleton.
icu::DateTimePatternGenerator::getDateTimeFormat
const UnicodeString & getDateTimeFormat(UDateFormatStyle style, UErrorCode &status) const
Getter corresponding to setDateTimeFormat.
icu::DateTimePatternGenerator::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::DateTimePatternGenerator::setDecimal
void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
icu::DateTimePatternGenerator::operator!=
bool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
icu::DateTimePatternGenerator::getDecimal
const UnicodeString & getDecimal() const
Getter corresponding to setDecimal.
icu::DateTimePatternGenerator::clone
DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
icu::DateTimePatternGenerator::operator==
bool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
icu::DateTimePatternGenerator::getPatternForSkeleton
const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
icu::DateTimePatternGenerator::getDateTimeFormat
const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
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::getBestPattern
UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
icu::DateTimePatternGenerator::setDateTimeFormat
void setDateTimeFormat(UDateFormatStyle style, const UnicodeString &dateTimeFormat, UErrorCode &status)
dateTimeFormats are message patterns used to compose combinations of date and time patterns.
icu::DateTimePatternGenerator::createEmptyInstance
static DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
icu::DateTimePatternGenerator::getAppendItemFormat
const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
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::createInstance
static DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
icu::DateTimePatternGenerator::setAppendItemName
void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
icu::DateTimePatternGenerator::staticGetBaseSkeleton
static UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
icu::DateTimePatternGenerator::getBaseSkeletons
StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
icu::DateTimePatternGenerator::setDateTimeFormat
void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
icu::DateTimePatternGenerator::getSkeletons
StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
icu::DateTimePatternGenerator::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DateTimePatternGenerator::getAppendItemName
const UnicodeString & getAppendItemName(UDateTimePatternField field) const
Getter corresponding to setAppendItemNames.
icu::DateTimePatternGenerator::createInstance
static DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
icu::DateTimePatternGenerator::getDefaultHourCycle
UDateFormatHourCycle getDefaultHourCycle(UErrorCode &status) const
Get the default hour cycle for a locale.
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::createInstanceNoStdPat
static DateTimePatternGenerator * createInstanceNoStdPat(const Locale &uLocale, UErrorCode &status)
For ICU use only.
icu::DateTimePatternGenerator::staticGetSkeleton
static UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
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.
icu::DateTimePatternGenerator::getBaseSkeleton
UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
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::getSkeleton
UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
icu::DateTimePatternGenerator::~DateTimePatternGenerator
virtual ~DateTimePatternGenerator()
Destructor.
icu::DateTimePatternGenerator::addPattern
UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
datefmt.h
C++ API: Abstract class for converting dates.
locid.h
C++ API: Locale ID object.
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:846
U_HIDDEN
#define U_HIDDEN
This is used to mark internal structs declared within external classes, to prevent the internal struc...
Definition: platform.h:823
udat.h
C API: DateFormat.
UDateFormatStyle
UDateFormatStyle
The possible date/time format styles.
Definition: udat.h:162
UDateFormatHourCycle
UDateFormatHourCycle
Hour Cycle.
Definition: udat.h:983
udatpg.h
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
UDateTimePGDisplayWidth
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:108
UDATPG_NARROW
@ UDATPG_NARROW
Definition: udatpg.h:114
UDateTimePatternConflict
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:143
UDateTimePatternMatchOptions
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:124
UDATPG_MATCH_NO_OPTIONS
@ UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:126
UDateTimePatternField
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:59
UDATPG_FIELD_COUNT
@ UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:100
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:316