/*
**********************************************************************
-* Copyright (c) 2004-2014, International Business Machines
+* Copyright (c) 2004-2015, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
#define MEASUREFORMAT_H
#include "unicode/utypes.h"
-#include "unicode/measure.h"
#if !UCONFIG_NO_FORMATTING
* \brief C++ API: Formatter for measure objects.
*/
-#ifndef U_HIDE_DRAFT_API
/**
* Constants for various widths.
- * There are 3 widths: Wide, Short, Narrow.
+ * 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"
- * @draft ICU 53
+ * Wide is "3 hours"; short is "3 hrs"; narrow is "3h";
+ * formatting "3 hours 17 minutes" as numeric give "3:17"
+ * @stable ICU 53
*/
enum UMeasureFormatWidth {
// Wide, short, and narrow must be first and in this order.
/**
* Spell out measure units.
- * @draft ICU 53
+ * @stable ICU 53
*/
UMEASFMT_WIDTH_WIDE,
/**
* Abbreviate measure units.
- * @draft ICU 53
+ * @stable ICU 53
*/
UMEASFMT_WIDTH_SHORT,
/**
* Use symbols for measure units when possible.
- * @draft ICU 53
+ * @stable ICU 53
*/
UMEASFMT_WIDTH_NARROW,
/**
* Completely omit measure units when possible. For example, format
* '5 hours, 37 minutes' as '5:37'
- * @draft ICU 53
+ * @stable ICU 53
*/
UMEASFMT_WIDTH_NUMERIC,
/**
* Count of values in this enum.
- * @draft ICU 53
+ * @stable ICU 53
*/
- UMEASFMT_WIDTH_COUNT
+ UMEASFMT_WIDTH_COUNT = 4
};
-/** @draft ICU 53 */
+/** @stable ICU 53 */
typedef enum UMeasureFormatWidth UMeasureFormatWidth;
-#endif /* U_HIDE_DRAFT_API */
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;
using Format::parseObject;
using Format::format;
-#ifndef U_HIDE_DRAFT_API
/**
* Constructor.
- * @draft ICU 53
+ * @stable ICU 53
*/
MeasureFormat(
const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
/**
* Constructor.
- * @draft ICU 53
+ * @stable ICU 53
*/
MeasureFormat(
const Locale &locale,
UMeasureFormatWidth width,
NumberFormat *nfToAdopt,
UErrorCode &status);
-#endif /* U_HIDE_DRAFT_API */
/**
* Copy constructor.
- * @draft ICU 53
+ * @stable ICU 3.0
*/
MeasureFormat(const MeasureFormat &other);
/**
* Assignment operator.
- * @draft ICU 53
+ * @stable ICU 3.0
*/
MeasureFormat &operator=(const MeasureFormat &rhs);
/**
* Return true if given Format objects are semantically equal.
- * @draft ICU 53
+ * @stable ICU 53
*/
virtual UBool operator==(const Format &other) const;
/**
* Clones this object polymorphically.
- * @draft ICU 53
+ * @stable ICU 53
*/
virtual Format *clone() const;
/**
* Formats object to produce a string.
- * @draft ICU 53
+ * @stable ICU 53
*/
virtual UnicodeString &format(
const Formattable &obj,
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
* @param status the error.
* @return appendTo reference
*
- * @draft ICU 53
+ * @stable ICU 53
*/
UnicodeString &formatMeasures(
const Measure *measures,
UnicodeString &appendTo,
FieldPosition &pos,
UErrorCode &status) const;
-#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Apple-specific for now
+ * @internal.
+ */
+ UMeasureFormatWidth getWidth(void) const;
+#endif /* U_HIDE_INTERNAL_API */
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Formats a single measure per unit. An example of such a
+ * formatted string is 3.5 meters per second.
+ * @param measure The measure object. In above example, 3.5 meters.
+ * @param perUnit The per unit. In above example, it is
+ * *MeasureUnit::createSecond(status).
+ * @param appendTo formatted string appended here.
+ * @param pos the field position.
+ * @param status the error.
+ * @return appendTo reference
+ *
+ * @draft ICU 55
+ */
+ UnicodeString &formatMeasurePerUnit(
+ const Measure &measure,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+#endif /* U_HIDE_DRAFT_API */
+
/**
* Return a formatter for CurrencyAmount objects in the given
* locale.
* . erived::getStaticClassID()) ...
* </pre>
* @return The class ID for all objects of this class.
- * @draft ICU 53
+ * @stable ICU 53
*/
static UClassID U_EXPORT2 getStaticClassID(void);
* @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
+ * @stable ICU 53
*/
virtual UClassID getDynamicClassID(void) const;
#ifndef U_HIDE_INTERNAL_API
-#ifndef U_HIDE_DRAFT_API
/**
* ICU use only.
* Initialize or change MeasureFormat class from subclass.
UMeasureFormatWidth width,
NumberFormat *nfToAdopt,
UErrorCode &status);
-#endif
/**
* ICU use only.
* Allows subclass to change locale. Note that this method also changes
const MeasureFormatCacheData *cache;
const SharedNumberFormat *numberFormat;
const SharedPluralRules *pluralRules;
-#ifndef U_HIDE_DRAFT_API
UMeasureFormatWidth width;
-#endif
// Declared outside of MeasureFormatSharedData because ListFormatter
// objects are relatively cheap to copy; therefore, they don't need to be
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 withPerUnitAndAppend(
+ const UnicodeString &formatted,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
UnicodeString &formatMeasure(
const Measure &measure,
const NumberFormat &nf,