ICU 63.1 63.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/datefmt.h"
18 #include "unicode/locid.h"
19 #include "unicode/udat.h"
20 #include "unicode/udatpg.h"
21 #include "unicode/unistr.h"
22
23 U_NAMESPACE_BEGIN
24
31 class CharString;
32 class Hashtable;
33 class FormatParser;
34 class DateTimeMatcher;
35 class DistanceInfo;
36 class PatternMap;
37 class PtnSkeleton;
38 class SharedDateTimePatternGenerator;
39
54 class U_I18N_API DateTimePatternGenerator : public UObject {
55 public:
62 static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
63
71 static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
72
73 #ifndef U_HIDE_INTERNAL_API
74
80 static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
81
82 #endif /* U_HIDE_INTERNAL_API */
83
90 static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
91
96 virtual ~DateTimePatternGenerator();
97
103 DateTimePatternGenerator* clone() const;
104
112 UBool operator==(const DateTimePatternGenerator& other) const;
113
121 UBool operator!=(const DateTimePatternGenerator& other) const;
122
133 static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
134
147 UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
148 The function is commented out because it is a stable API calling a draft API.
149 After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
150 these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
151 return staticGetSkeleton(pattern, status);
152 }*/
153
167 static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
168
184 UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
185 The function is commented out because it is a stable API calling a draft API.
186 After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
187 these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
188 return staticGetBaseSkeleton(pattern, status);
189 }*/
190
216 UDateTimePatternConflict addPattern(const UnicodeString& pattern,
217 UBool override,
218 UnicodeString& conflictingPattern,
219 UErrorCode& status);
220
239 void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
240
249 const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
250
262 void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
263
274 const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
275
276 #ifndef U_HIDE_DRAFT_API
277
286 UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
287 #endif // U_HIDE_DRAFT_API
288
310 void setDateTimeFormat(const UnicodeString& dateTimeFormat);
311
317 const UnicodeString& getDateTimeFormat() const;
318
337 UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
338
339
359 UnicodeString getBestPattern(const UnicodeString& skeleton,
360 UDateTimePatternMatchOptions options,
361 UErrorCode& status);
362
363
385 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
386 const UnicodeString& skeleton,
387 UErrorCode& status);
388
411 UnicodeString replaceFieldTypes(const UnicodeString& pattern,
412 const UnicodeString& skeleton,
413 UDateTimePatternMatchOptions options,
414 UErrorCode& status);
415
427 StringEnumeration* getSkeletons(UErrorCode& status) const;
428
435 const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
436
446 StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
447
448 #ifndef U_HIDE_INTERNAL_API
449
461 StringEnumeration* getRedundants(UErrorCode& status);
462 #endif /* U_HIDE_INTERNAL_API */
463
475 void setDecimal(const UnicodeString& decimal);
476
482 const UnicodeString& getDecimal() const;
483
489 virtual UClassID getDynamicClassID() const;
490
496 static UClassID U_EXPORT2 getStaticClassID(void);
497
498 private:
502 DateTimePatternGenerator(UErrorCode & status);
503
507 DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
508
513 DateTimePatternGenerator(const DateTimePatternGenerator& other);
514
519 DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
520
521 // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
522 // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
523
524 Locale pLocale; // pattern locale
525 FormatParser *fp;
526 DateTimeMatcher* dtMatcher;
527 DistanceInfo *distanceInfo;
528 PatternMap *patternMap;
529 UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
530 // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
531 UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
532 UnicodeString dateTimeFormat;
533 UnicodeString decimal;
534 DateTimeMatcher *skipMatcher;
535 Hashtable *fAvailableFormatKeyHash;
536 UnicodeString emptyString;
537 char16_t fDefaultHourFormatChar;
538
539 int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
540
541 // Internal error code used for recording/reporting errors that occur during methods that do not
542 // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
543 // When this is set to an error the object is in an invalid state.
544 UErrorCode internalErrorCode;
545
546 /* internal flags masks for adjustFieldTypes etc. */
547 enum {
548 kDTPGNoFlags = 0,
549 kDTPGFixFractionalSeconds = 1,
550 kDTPGSkeletonUsesCapJ = 2
551 // with #13183, no longer need flags for b, B
552 };
553
554 void initData(const Locale &locale, UErrorCode &status);
555 void addCanonicalItems(UErrorCode &status);
556 void addICUPatterns(const Locale& locale, UErrorCode& status);
557 void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
558 void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
559 void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
560 void addCLDRData(const Locale& locale, UErrorCode& status);
561 UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
562 void initHashtable(UErrorCode& status);
563 void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
564 void setDecimalSymbols(const Locale& locale, UErrorCode& status);
565 UDateTimePatternField getAppendFormatNumber(const char* field) const;
566 #ifndef U_HIDE_DRAFT_API
567 UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
568 void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
569 UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
570 #endif // U_HIDE_DRAFT_API
571 void getAppendName(UDateTimePatternField field, UnicodeString& value);
572 UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
573 const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
574 UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
575 UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
576 int32_t getTopBitNumber(int32_t foundMask) const;
577 void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
578 UBool isAvailableFormatSet(const UnicodeString &key) const;
579 void copyHashtable(Hashtable *other, UErrorCode &status);
580 UBool isCanonicalItem(const UnicodeString& item) const;
581 static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
582 void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
583
584 struct AppendItemFormatsSink;
585 struct AppendItemNamesSink;
586 struct AvailableFormatsSink;
587 } ;// end class DateTimePatternGenerator
588
589 U_NAMESPACE_END
590
591 #endif
icu::DateTimePatternGenerator
This class provides flexible generation of date format patterns, like "yy-MM-dd". ...
Definition: dtptngen.h:54
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
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:840
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
icu::StringEnumeration
Base class for &#39;pure&#39; C++ implementations of uenum api.
Definition: strenum.h:57
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
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
udatpg.h
C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
udat.h
C API: DateFormat.
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UDATPG_MATCH_NO_OPTIONS
Definition: udatpg.h:122
UDateTimePatternConflict
UDateTimePatternConflict
Status return values from udatpg_addPattern().
Definition: udatpg.h:139
UDATPG_FIELD_COUNT
One more than the highest normal UDateTimePatternField value.
Definition: udatpg.h:95
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UDateTimePatternField
UDateTimePatternField
Field number constants for udatpg_getAppendItemFormats() and similar functions.
Definition: udatpg.h:55
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
UDateTimePGDisplayWidth
UDateTimePGDisplayWidth
Field display name width constants for udatpg_getFieldDisplayName().
Definition: udatpg.h:103
datefmt.h
C++ API: Abstract class for converting dates.
locid.h
C++ API: Locale ID object.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
UDateTimePatternMatchOptions
UDateTimePatternMatchOptions
Masks to control forcing the length of specified fields in the returned pattern to match those in the...
Definition: udatpg.h:120
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192