Loading...
Searching...
No Matches
dtptngen.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2007-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File DTPTNGEN.H
*
*******************************************************************************
*/
#ifndef __DTPTNGEN_H__
#define __DTPTNGEN_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/datefmt.h"
#include "unicode/locid.h"
#include "unicode/udat.h"
#include "unicode/udatpg.h"
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
class CharString;
class Hashtable;
class FormatParser;
class DateTimeMatcher;
class DistanceInfo;
class PatternMap;
class PtnSkeleton;
class SharedDateTimePatternGenerator;
class U_I18N_API_CLASS DateTimePatternGenerator : public UObject {
public:
U_I18N_API static DateTimePatternGenerator* createInstance(UErrorCode& status);
U_I18N_API static DateTimePatternGenerator* createInstance(const Locale& uLocale, UErrorCode& status);
#ifndef U_HIDE_INTERNAL_API
U_I18N_API static DateTimePatternGenerator* createInstanceNoStdPat(const Locale& uLocale,
UErrorCode& status);
#endif /* U_HIDE_INTERNAL_API */
U_I18N_API static DateTimePatternGenerator* createEmptyInstance(UErrorCode& status);
U_I18N_API virtual ~DateTimePatternGenerator();
U_I18N_API DateTimePatternGenerator* clone() const;
U_I18N_API bool operator==(const DateTimePatternGenerator& other) const;
U_I18N_API bool operator!=(const DateTimePatternGenerator& other) const;
U_I18N_API static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
The function is commented out because it is a stable API calling a draft API.
After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
return staticGetSkeleton(pattern, status);
}*/
U_I18N_API static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern,
UErrorCode& status);
U_I18N_API UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
The function is commented out because it is a stable API calling a draft API.
After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
return staticGetBaseSkeleton(pattern, status);
}*/
U_I18N_API UDateTimePatternConflict addPattern(const UnicodeString& pattern,
UBool override,
UnicodeString& conflictingPattern,
UErrorCode& status);
#ifndef U_HIDE_INTERNAL_API
U_I18N_API UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern,
const UnicodeString& skeletonToUse,
UBool override,
UnicodeString& conflictingPattern,
UErrorCode& status);
#endif /* U_HIDE_INTERNAL_API */
U_I18N_API void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
U_I18N_API const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
U_I18N_API void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
U_I18N_API const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
U_I18N_API UnicodeString getFieldDisplayName(UDateTimePatternField field,
UDateTimePGDisplayWidth width) const;
U_I18N_API void setDateTimeFormat(const UnicodeString& dateTimeFormat);
U_I18N_API const UnicodeString& getDateTimeFormat() const;
#if !UCONFIG_NO_FORMATTING
U_I18N_API void setDateTimeFormat(UDateFormatStyle style,
const UnicodeString& dateTimeFormat,
UErrorCode& status);
U_I18N_API const UnicodeString& getDateTimeFormat(UDateFormatStyle style, UErrorCode& status) const;
#endif /* #if !UCONFIG_NO_FORMATTING */
U_I18N_API UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
U_I18N_API UnicodeString getBestPattern(const UnicodeString& skeleton,
UDateTimePatternMatchOptions options,
UErrorCode& status);
U_I18N_API UnicodeString replaceFieldTypes(const UnicodeString& pattern,
const UnicodeString& skeleton,
UErrorCode& status);
U_I18N_API UnicodeString replaceFieldTypes(const UnicodeString& pattern,
const UnicodeString& skeleton,
UDateTimePatternMatchOptions options,
UErrorCode& status);
U_I18N_API StringEnumeration* getSkeletons(UErrorCode& status) const;
U_I18N_API const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
U_I18N_API StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
#ifndef U_HIDE_INTERNAL_API
U_I18N_API StringEnumeration* getRedundants(UErrorCode& status);
#endif /* U_HIDE_INTERNAL_API */
U_I18N_API void setDecimal(const UnicodeString& decimal);
U_I18N_API const UnicodeString& getDecimal() const;
#if !UCONFIG_NO_FORMATTING
U_I18N_API UDateFormatHourCycle getDefaultHourCycle(UErrorCode& status) const;
#endif /* #if !UCONFIG_NO_FORMATTING */
U_I18N_API virtual UClassID getDynamicClassID() const override;
U_I18N_API static UClassID getStaticClassID();
private:
DateTimePatternGenerator(UErrorCode & status);
DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
DateTimePatternGenerator(const DateTimePatternGenerator& other);
DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
Locale pLocale; // pattern locale
FormatParser *fp;
DateTimeMatcher* dtMatcher;
DistanceInfo *distanceInfo;
PatternMap *patternMap;
UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][UDATPG_WIDTH_COUNT];
UnicodeString dateTimeFormat[4];
UnicodeString decimal;
DateTimeMatcher *skipMatcher;
Hashtable *fAvailableFormatKeyHash;
UnicodeString emptyString;
char16_t fDefaultHourFormatChar;
int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
// Internal error code used for recording/reporting errors that occur during methods that do not
// have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
// When this is set to an error the object is in an invalid state.
UErrorCode internalErrorCode;
/* internal flags masks for adjustFieldTypes etc. */
enum {
kDTPGNoFlags = 0,
kDTPGFixFractionalSeconds = 1,
kDTPGSkeletonUsesCapJ = 2
// with #13183, no longer need flags for b, B
};
void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
void addCanonicalItems(UErrorCode &status);
void addICUPatterns(const Locale& locale, UErrorCode& status);
void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
void addCLDRData(const Locale& locale, UErrorCode& status);
UDateTimePatternConflict addPatternWithOptionalSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
void initHashtable(UErrorCode& status);
void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
void setDecimalSymbols(const Locale& locale, UErrorCode& status);
UDateTimePatternField getAppendFormatNumber(const char* field) const;
// Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
void getAppendName(UDateTimePatternField field, UnicodeString& value);
UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = nullptr);
UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
int32_t getTopBitNumber(int32_t foundMask) const;
void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
UBool isAvailableFormatSet(const UnicodeString &key) const;
void copyHashtable(Hashtable *other, UErrorCode &status);
UBool isCanonicalItem(const UnicodeString& item) const;
static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
struct U_HIDDEN AppendItemFormatsSink;
struct U_HIDDEN AppendItemNamesSink;
struct U_HIDDEN AvailableFormatsSink;
} ;// end class DateTimePatternGenerator
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
icu::DateTimePatternGenerator::replaceFieldTypes
U_I18N_API 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
U_I18N_API const UnicodeString & getDecimal() const
Getter corresponding to setDecimal.
icu::DateTimePatternGenerator::staticGetBaseSkeleton
static U_I18N_API UnicodeString staticGetBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
icu::DateTimePatternGenerator::setDecimal
U_I18N_API void setDecimal(const UnicodeString &decimal)
The decimal value is used in formatting fractions of seconds.
icu::DateTimePatternGenerator::getDefaultHourCycle
U_I18N_API UDateFormatHourCycle getDefaultHourCycle(UErrorCode &status) const
Get the default hour cycle for a locale.
icu::DateTimePatternGenerator::replaceFieldTypes
U_I18N_API 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::addPatternWithSkeleton
U_I18N_API UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString &pattern, const UnicodeString &skeletonToUse, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Like addPattern, but associates the pattern with the given skeleton.
icu::DateTimePatternGenerator::operator==
U_I18N_API bool operator==(const DateTimePatternGenerator &other) const
Return true if another object is semantically equal to this one.
icu::DateTimePatternGenerator::getFieldDisplayName
U_I18N_API 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::createInstanceNoStdPat
static U_I18N_API DateTimePatternGenerator * createInstanceNoStdPat(const Locale &uLocale, UErrorCode &status)
For ICU use only.
icu::DateTimePatternGenerator::getAppendItemName
U_I18N_API const UnicodeString & getAppendItemName(UDateTimePatternField field) const
Getter corresponding to setAppendItemNames.
icu::DateTimePatternGenerator::getDateTimeFormat
U_I18N_API const UnicodeString & getDateTimeFormat() const
Getter corresponding to setDateTimeFormat.
icu::DateTimePatternGenerator::operator!=
U_I18N_API bool operator!=(const DateTimePatternGenerator &other) const
Return true if another object is semantically unequal to this one.
icu::DateTimePatternGenerator::getDateTimeFormat
U_I18N_API const UnicodeString & getDateTimeFormat(UDateFormatStyle style, UErrorCode &status) const
Getter corresponding to setDateTimeFormat.
icu::DateTimePatternGenerator::staticGetSkeleton
static U_I18N_API UnicodeString staticGetSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
icu::DateTimePatternGenerator::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::DateTimePatternGenerator::createInstance
static U_I18N_API DateTimePatternGenerator * createInstance(const Locale &uLocale, UErrorCode &status)
Construct a flexible generator according to data for a given locale.
icu::DateTimePatternGenerator::getBaseSkeletons
U_I18N_API StringEnumeration * getBaseSkeletons(UErrorCode &status) const
Return a list of all the base skeletons (in canonical form) from this class.
icu::DateTimePatternGenerator::getBestPattern
U_I18N_API UnicodeString getBestPattern(const UnicodeString &skeleton, UDateTimePatternMatchOptions options, UErrorCode &status)
Return the best pattern matching the input skeleton.
icu::DateTimePatternGenerator::getPatternForSkeleton
U_I18N_API const UnicodeString & getPatternForSkeleton(const UnicodeString &skeleton) const
Get the pattern corresponding to a given skeleton.
icu::DateTimePatternGenerator::createInstance
static U_I18N_API DateTimePatternGenerator * createInstance(UErrorCode &status)
Construct a flexible generator according to default locale.
icu::DateTimePatternGenerator::createEmptyInstance
static U_I18N_API DateTimePatternGenerator * createEmptyInstance(UErrorCode &status)
Create an empty generator, to be constructed with addPattern(...) etc.
icu::DateTimePatternGenerator::getSkeleton
U_I18N_API UnicodeString getSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique skeleton from a given pattern.
icu::DateTimePatternGenerator::~DateTimePatternGenerator
virtual U_I18N_API ~DateTimePatternGenerator()
Destructor.
icu::DateTimePatternGenerator::getBestPattern
U_I18N_API UnicodeString getBestPattern(const UnicodeString &skeleton, UErrorCode &status)
Return the best pattern matching the input skeleton.
icu::DateTimePatternGenerator::getAppendItemFormat
U_I18N_API const UnicodeString & getAppendItemFormat(UDateTimePatternField field) const
Getter corresponding to setAppendItemFormat.
icu::DateTimePatternGenerator::setAppendItemName
U_I18N_API void setAppendItemName(UDateTimePatternField field, const UnicodeString &value)
Sets the names of field, eg "era" in English for ERA.
icu::DateTimePatternGenerator::getSkeletons
U_I18N_API StringEnumeration * getSkeletons(UErrorCode &status) const
Return a list of all the skeletons (in canonical form) from this class.
icu::DateTimePatternGenerator::setDateTimeFormat
U_I18N_API void setDateTimeFormat(UDateFormatStyle style, const UnicodeString &dateTimeFormat, UErrorCode &status)
dateTimeFormats are message patterns used to compose combinations of date and time patterns.
icu::DateTimePatternGenerator::setDateTimeFormat
U_I18N_API void setDateTimeFormat(const UnicodeString &dateTimeFormat)
The DateTimeFormat is a message format pattern used to compose date and time patterns.
icu::DateTimePatternGenerator::clone
U_I18N_API DateTimePatternGenerator * clone() const
Clone DateTimePatternGenerator object.
icu::DateTimePatternGenerator::getRedundants
U_I18N_API StringEnumeration * getRedundants(UErrorCode &status)
Return a list of redundant patterns are those which if removed, make no difference in the resulting g...
icu::DateTimePatternGenerator::addPattern
U_I18N_API UDateTimePatternConflict addPattern(const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
Adds a pattern to the generator.
icu::DateTimePatternGenerator::getBaseSkeleton
U_I18N_API UnicodeString getBaseSkeleton(const UnicodeString &pattern, UErrorCode &status)
Utility to return a unique base skeleton from a given pattern.
icu::DateTimePatternGenerator::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::DateTimePatternGenerator::setAppendItemFormat
U_I18N_API 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::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
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:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
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:836
U_HIDDEN
#define U_HIDDEN
This is used to mark internal structs declared within external classes, to prevent the internal struc...
Definition platform.h:813
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:269
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:509
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
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