| Index: source/i18n/unicode/measfmt.h
|
| diff --git a/source/i18n/unicode/measfmt.h b/source/i18n/unicode/measfmt.h
|
| index d49a9b572d2072aa69ac43bb86e45d1ccfe48469..91e08ef8d82c76649e0e0cfa563caebe542e4cf9 100644
|
| --- a/source/i18n/unicode/measfmt.h
|
| +++ b/source/i18n/unicode/measfmt.h
|
| @@ -1,6 +1,6 @@
|
| /*
|
| **********************************************************************
|
| -* Copyright (c) 2004-2011, International Business Machines
|
| +* Copyright (c) 2004-2014, International Business Machines
|
| * Corporation and others. All Rights Reserved.
|
| **********************************************************************
|
| * Author: Alan Liu
|
| @@ -16,23 +16,77 @@
|
| #if !UCONFIG_NO_FORMATTING
|
|
|
| #include "unicode/format.h"
|
| +#include "unicode/udat.h"
|
|
|
| /**
|
| * \file
|
| * \brief C++ API: Formatter for measure objects.
|
| */
|
|
|
| +/**
|
| + * Constants for various widths.
|
| + * There are 4 widths: Wide, Short, Narrow, Numeric.
|
| + * For example, for English, when formatting "3 hours"
|
| + * Wide is "3 hours"; short is "3 hrs"; narrow is "3h";
|
| + * formatting "3 hours 17 minutes" as numeric give "3:17"
|
| + * @draft ICU 53
|
| + */
|
| +enum UMeasureFormatWidth {
|
| +
|
| +#ifndef U_HIDE_DRAFT_API
|
| + // Wide, short, and narrow must be first and in this order.
|
| + /**
|
| + * Spell out measure units.
|
| + * @draft ICU 53
|
| + */
|
| + UMEASFMT_WIDTH_WIDE,
|
| +
|
| + /**
|
| + * Abbreviate measure units.
|
| + * @draft ICU 53
|
| + */
|
| + UMEASFMT_WIDTH_SHORT,
|
| +
|
| + /**
|
| + * Use symbols for measure units when possible.
|
| + * @draft ICU 53
|
| + */
|
| + UMEASFMT_WIDTH_NARROW,
|
| +
|
| + /**
|
| + * Completely omit measure units when possible. For example, format
|
| + * '5 hours, 37 minutes' as '5:37'
|
| + * @draft ICU 53
|
| + */
|
| + UMEASFMT_WIDTH_NUMERIC,
|
| +#endif /* U_HIDE_DRAFT_API */
|
| +
|
| + /**
|
| + * Count of values in this enum.
|
| + * @draft ICU 53
|
| + */
|
| + UMEASFMT_WIDTH_COUNT = 4
|
| +};
|
| +/** @draft ICU 53 */
|
| +typedef enum UMeasureFormatWidth UMeasureFormatWidth;
|
| +
|
| U_NAMESPACE_BEGIN
|
|
|
| +class Measure;
|
| +class MeasureUnit;
|
| +class NumberFormat;
|
| +class PluralRules;
|
| +class MeasureFormatCacheData;
|
| +class SharedNumberFormat;
|
| +class SharedPluralRules;
|
| +class QuantityFormatter;
|
| +class SimplePatternFormatter;
|
| +class ListFormatter;
|
| +class DateFormat;
|
| +
|
| /**
|
| *
|
| - * A formatter for measure objects. This is an abstract base class.
|
| - *
|
| - * <p>To format or parse a measure object, first create a formatter
|
| - * object using a MeasureFormat factory method. Then use that
|
| - * object's format and parse methods.
|
| - *
|
| - * <p>This is an abstract class.
|
| + * A formatter for measure objects.
|
| *
|
| * @see Format
|
| * @author Alan Liu
|
| @@ -40,6 +94,40 @@ U_NAMESPACE_BEGIN
|
| */
|
| class U_I18N_API MeasureFormat : public Format {
|
| public:
|
| + using Format::parseObject;
|
| + using Format::format;
|
| +
|
| +#ifndef U_HIDE_DRAFT_API
|
| + /**
|
| + * Constructor.
|
| + * @draft ICU 53
|
| + */
|
| + MeasureFormat(
|
| + const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
|
| +
|
| + /**
|
| + * Constructor.
|
| + * @draft ICU 53
|
| + */
|
| + MeasureFormat(
|
| + const Locale &locale,
|
| + UMeasureFormatWidth width,
|
| + NumberFormat *nfToAdopt,
|
| + UErrorCode &status);
|
| +#endif /* U_HIDE_DRAFT_API */
|
| +
|
| + /**
|
| + * Copy constructor.
|
| + * @draft ICU 53
|
| + */
|
| + MeasureFormat(const MeasureFormat &other);
|
| +
|
| + /**
|
| + * Assignment operator.
|
| + * @draft ICU 53
|
| + */
|
| + MeasureFormat &operator=(const MeasureFormat &rhs);
|
| +
|
| /**
|
| * Destructor.
|
| * @stable ICU 3.0
|
| @@ -47,6 +135,88 @@ class U_I18N_API MeasureFormat : public Format {
|
| virtual ~MeasureFormat();
|
|
|
| /**
|
| + * Return true if given Format objects are semantically equal.
|
| + * @draft ICU 53
|
| + */
|
| + virtual UBool operator==(const Format &other) const;
|
| +
|
| + /**
|
| + * Clones this object polymorphically.
|
| + * @draft ICU 53
|
| + */
|
| + virtual Format *clone() const;
|
| +
|
| + /**
|
| + * Formats object to produce a string.
|
| + * @draft ICU 53
|
| + */
|
| + virtual UnicodeString &format(
|
| + const Formattable &obj,
|
| + UnicodeString &appendTo,
|
| + FieldPosition &pos,
|
| + UErrorCode &status) const;
|
| +
|
| + /**
|
| + * Parse a string to produce an object. This implementation sets
|
| + * status to U_UNSUPPORTED_ERROR.
|
| + *
|
| + * @draft ICU 53
|
| + */
|
| + virtual void parseObject(
|
| + const UnicodeString &source,
|
| + Formattable &reslt,
|
| + ParsePosition &pos) const;
|
| +
|
| +#ifndef U_HIDE_DRAFT_API
|
| + /**
|
| + * Formats measure objects to produce a string. An example of such a
|
| + * formatted string is 3 meters, 3.5 centimeters. Measure objects appear
|
| + * in the formatted string in the same order they appear in the "measures"
|
| + * array. The NumberFormat of this object is used only to format the amount
|
| + * of the very last measure. The other amounts are formatted with zero
|
| + * decimal places while rounding toward zero.
|
| + * @param measures array of measure objects.
|
| + * @param measureCount the number of measure objects.
|
| + * @param appendTo formatted string appended here.
|
| + * @param pos the field position.
|
| + * @param status the error.
|
| + * @return appendTo reference
|
| + *
|
| + * @draft ICU 53
|
| + */
|
| + UnicodeString &formatMeasures(
|
| + const Measure *measures,
|
| + int32_t measureCount,
|
| + UnicodeString &appendTo,
|
| + FieldPosition &pos,
|
| + UErrorCode &status) const;
|
| +#endif /* U_HIDE_DRAFT_API */
|
| +
|
| +#ifndef U_HIDE_INTERNAL_API
|
| + /**
|
| + * Works like formatMeasures but adds a per unit. An example of such a
|
| + * formatted string is 3 meters, 3.5 centimeters per second.
|
| + * @param measures array of measure objects.
|
| + * @param measureCount the number of measure objects.
|
| + * @param perUnit The per unit. In the example formatted string,
|
| + * it is *MeasureUnit::createSecond(status).
|
| + * @param appendTo formatted string appended here.
|
| + * @param pos the field position.
|
| + * @param status the error.
|
| + * @return appendTo reference
|
| + *
|
| + * @internal Technology preview
|
| + */
|
| + UnicodeString &formatMeasuresPer(
|
| + const Measure *measures,
|
| + int32_t measureCount,
|
| + const MeasureUnit &perUnit,
|
| + UnicodeString &appendTo,
|
| + FieldPosition &pos,
|
| + UErrorCode &status) const;
|
| +#endif /* U_HIDE_INTERNAL_API */
|
| +
|
| + /**
|
| * Return a formatter for CurrencyAmount objects in the given
|
| * locale.
|
| * @param locale desired locale
|
| @@ -66,13 +236,151 @@ class U_I18N_API MeasureFormat : public Format {
|
| */
|
| static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
|
|
|
| - protected:
|
| + /**
|
| + * Return the class ID for this class. This is useful only for comparing to
|
| + * a return value from getDynamicClassID(). For example:
|
| + * <pre>
|
| + * . Base* polymorphic_pointer = createPolymorphicObject();
|
| + * . if (polymorphic_pointer->getDynamicClassID() ==
|
| + * . erived::getStaticClassID()) ...
|
| + * </pre>
|
| + * @return The class ID for all objects of this class.
|
| + * @draft ICU 53
|
| + */
|
| + static UClassID U_EXPORT2 getStaticClassID(void);
|
|
|
| /**
|
| + * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
| + * method is to implement a simple version of RTTI, since not all C++
|
| + * compilers support genuine RTTI. Polymorphic operator==() and clone()
|
| + * methods call this method.
|
| + *
|
| + * @return The class ID for this object. All objects of a
|
| + * given class have the same class ID. Objects of
|
| + * other classes have different class IDs.
|
| + * @draft ICU 53
|
| + */
|
| + virtual UClassID getDynamicClassID(void) const;
|
| +
|
| + protected:
|
| + /**
|
| * Default constructor.
|
| * @stable ICU 3.0
|
| */
|
| MeasureFormat();
|
| +
|
| +#ifndef U_HIDE_INTERNAL_API
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * Initialize or change MeasureFormat class from subclass.
|
| + * @internal.
|
| + */
|
| + void initMeasureFormat(
|
| + const Locale &locale,
|
| + UMeasureFormatWidth width,
|
| + NumberFormat *nfToAdopt,
|
| + UErrorCode &status);
|
| + /**
|
| + * ICU use only.
|
| + * Allows subclass to change locale. Note that this method also changes
|
| + * the NumberFormat object. Returns TRUE if locale changed; FALSE if no
|
| + * change was made.
|
| + * @internal.
|
| + */
|
| + UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * Let subclass change NumberFormat.
|
| + * @internal.
|
| + */
|
| + void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * @internal.
|
| + */
|
| + const NumberFormat &getNumberFormat() const;
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * @internal.
|
| + */
|
| + const PluralRules &getPluralRules() const;
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * @internal.
|
| + */
|
| + Locale getLocale(UErrorCode &status) const;
|
| +
|
| + /**
|
| + * ICU use only.
|
| + * @internal.
|
| + */
|
| + const char *getLocaleID(UErrorCode &status) const;
|
| +
|
| +#endif /* U_HIDE_INTERNAL_API */
|
| +
|
| + private:
|
| + const MeasureFormatCacheData *cache;
|
| + const SharedNumberFormat *numberFormat;
|
| + const SharedPluralRules *pluralRules;
|
| + UMeasureFormatWidth width;
|
| +
|
| + // Declared outside of MeasureFormatSharedData because ListFormatter
|
| + // objects are relatively cheap to copy; therefore, they don't need to be
|
| + // shared across instances.
|
| + ListFormatter *listFormatter;
|
| +
|
| + const QuantityFormatter *getQuantityFormatter(
|
| + int32_t index,
|
| + int32_t widthIndex,
|
| + UErrorCode &status) const;
|
| +
|
| + const SimplePatternFormatter *getPerUnitFormatter(
|
| + int32_t index,
|
| + int32_t widthIndex) const;
|
| +
|
| + const SimplePatternFormatter *getPerFormatter(
|
| + int32_t widthIndex,
|
| + UErrorCode &status) const;
|
| +
|
| + int32_t withPerUnit(
|
| + const UnicodeString &formatted,
|
| + const MeasureUnit &perUnit,
|
| + UnicodeString &appendTo,
|
| + UErrorCode &status) const;
|
| +
|
| + UnicodeString &formatMeasure(
|
| + const Measure &measure,
|
| + const NumberFormat &nf,
|
| + UnicodeString &appendTo,
|
| + FieldPosition &pos,
|
| + UErrorCode &status) const;
|
| +
|
| + UnicodeString &formatMeasuresSlowTrack(
|
| + const Measure *measures,
|
| + int32_t measureCount,
|
| + UnicodeString& appendTo,
|
| + FieldPosition& pos,
|
| + UErrorCode& status) const;
|
| +
|
| + UnicodeString &formatNumeric(
|
| + const Formattable *hms, // always length 3: [0] is hour; [1] is
|
| + // minute; [2] is second.
|
| + int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
|
| + UnicodeString &appendTo,
|
| + UErrorCode &status) const;
|
| +
|
| + UnicodeString &formatNumeric(
|
| + UDate date,
|
| + const DateFormat &dateFmt,
|
| + UDateFormatField smallestField,
|
| + const Formattable &smallestAmount,
|
| + UnicodeString &appendTo,
|
| + UErrorCode &status) const;
|
| };
|
|
|
| U_NAMESPACE_END
|
|
|