tmutfmt.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) 2008-2014, Google, International Business Machines Corporation
* and others. All Rights Reserved.
*******************************************************************************
*/
#ifndef __TMUTFMT_H__
#define __TMUTFMT_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
#include "unicode/tmunit.h"
#include "unicode/tmutamt.h"
#include "unicode/measfmt.h"
#include "unicode/numfmt.h"
#include "unicode/plurrule.h"
#ifndef U_HIDE_DEPRECATED_API
enum UTimeUnitFormatStyle {
UTMUTFMT_FULL_STYLE,
UTMUTFMT_ABBREVIATED_STYLE,
UTMUTFMT_FORMAT_STYLE_COUNT
};
typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle;
U_NAMESPACE_BEGIN
class Hashtable;
class UVector;
struct TimeUnitFormatReadSink;
class U_I18N_API TimeUnitFormat: public MeasureFormat {
public:
TimeUnitFormat(UErrorCode& status);
TimeUnitFormat(const Locale& locale, UErrorCode& status);
TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
TimeUnitFormat(const TimeUnitFormat&);
virtual ~TimeUnitFormat();
virtual TimeUnitFormat* clone() const override;
TimeUnitFormat& operator=(const TimeUnitFormat& other);
void setLocale(const Locale& locale, UErrorCode& status);
void setNumberFormat(const NumberFormat& format, UErrorCode& status);
virtual void parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& pos) const override;
static UClassID U_EXPORT2 getStaticClassID();
virtual UClassID getDynamicClassID() const override;
private:
Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
UTimeUnitFormatStyle fStyle;
void create(UTimeUnitFormatStyle style, UErrorCode& status);
// it might actually be simpler to make them Decimal Formats later.
// initialize all private data members
void setup(UErrorCode& status);
// initialize data member without fill in data for fTimeUnitToCountToPattern
void initDataMembers(UErrorCode& status);
// initialize fTimeUnitToCountToPatterns from current locale's resource.
void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
UErrorCode& status);
// check completeness of fTimeUnitToCountToPatterns against all time units,
// and all plural rules, fill in fallback as necessary.
void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
// fill in fTimeUnitToCountToPatterns from locale fall-back chain
void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
TimeUnit::UTimeUnitFields field, const UnicodeString&,
const char*, Hashtable*, UErrorCode&);
// initialize hash table
Hashtable* initHash(UErrorCode& status);
// delete hash table
void deleteHash(Hashtable* htable);
// copy hash table
void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
// get time unit name, such as "year", from time unit field enum, such as
// UTIMEUNIT_YEAR.
static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
friend struct TimeUnitFormatReadSink;
};
U_NAMESPACE_END
#endif /* U_HIDE_DEPRECATED_API */
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __TMUTFMT_H__
//eof
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
icu::MeasureFormat
Definition measfmt.h:101
icu::NumberFormat
Definition numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
icu::TimeUnitFormat
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition tmutfmt.h:89
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UErrorCode &status)
Create TimeUnitFormat given locale, and full name style.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const TimeUnitFormat &)
Copy constructor.
icu::TimeUnitFormat::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::TimeUnitFormat::setNumberFormat
void setNumberFormat(const NumberFormat &format, UErrorCode &status)
Set the number format used for formatting or parsing.
icu::TimeUnitFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(UErrorCode &status)
Create TimeUnitFormat with default locale, and full name style.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
Create TimeUnitFormat given locale and style.
icu::TimeUnitFormat::setLocale
void setLocale(const Locale &locale, UErrorCode &status)
Set the locale used for formatting or parsing.
icu::TimeUnitFormat::clone
virtual TimeUnitFormat * clone() const override
Clone this Format object polymorphically.
icu::TimeUnitFormat::~TimeUnitFormat
virtual ~TimeUnitFormat()
deconstructor
icu::TimeUnitFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &pos) const override
Parse a TimeUnitAmount.
icu::TimeUnitFormat::operator=
TimeUnitFormat & operator=(const TimeUnitFormat &other)
Assignment operator.
icu::TimeUnit::UTimeUnitFields
UTimeUnitFields
Constants for all the time units we supported.
Definition tmunit.h:41
icu::TimeUnit::UTIMEUNIT_FIELD_COUNT
@ UTIMEUNIT_FIELD_COUNT
One more than the highest normal UTimeUnitFields value.
Definition tmunit.h:54
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
measfmt.h
C++ API: Compatibility APIs for measure formatting.
numfmt.h
C++ API: Compatibility APIs for number formatting.
plurrule.h
C++ API: PluralRules object.
tmunit.h
C++ API: time unit object.
tmutamt.h
C++ API: time unit amount object.
UTimeUnitFormatStyle
UTimeUnitFormatStyle
Constants for various styles.
Definition tmutfmt.h:41
UTMUTFMT_ABBREVIATED_STYLE
@ UTMUTFMT_ABBREVIATED_STYLE
Definition tmutfmt.h:45
UTMUTFMT_FORMAT_STYLE_COUNT
@ UTMUTFMT_FORMAT_STYLE_COUNT
Definition tmutfmt.h:47
UTMUTFMT_FULL_STYLE
@ UTMUTFMT_FULL_STYLE
Definition tmutfmt.h:43
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