]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/unicode/measfmt.h
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / measfmt.h
index febc75d9c7f6c9315d9e45c3e5b3188189618a03..2bd7631011d3b65677b1f057082db40e41333037 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-* Copyright (c) 2004-2014, International Business Machines
+* Copyright (c) 2004-2015, International Business Machines
 * Corporation and others.  All Rights Reserved.
 **********************************************************************
 * Author: Alan Liu
@@ -12,7 +12,6 @@
 #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;
 
@@ -94,34 +95,32 @@ class U_I18N_API MeasureFormat : public Format {
     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);
 
@@ -133,19 +132,19 @@ class U_I18N_API MeasureFormat : public Format {
 
     /**
      * 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,
@@ -164,7 +163,6 @@ class U_I18N_API MeasureFormat : public Format {
             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
@@ -179,7 +177,7 @@ class U_I18N_API MeasureFormat : public Format {
      * @param status the error.
      * @return appendTo reference
      *
-     * @draft ICU 53
+     * @stable ICU 53
      */
     UnicodeString &formatMeasures(
             const Measure *measures,
@@ -187,9 +185,39 @@ class U_I18N_API MeasureFormat : public Format {
             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.
@@ -219,7 +247,7 @@ class U_I18N_API MeasureFormat : public Format {
      * .       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);
 
@@ -232,7 +260,7 @@ class U_I18N_API MeasureFormat : public Format {
      * @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;
 
@@ -245,7 +273,6 @@ class U_I18N_API MeasureFormat : public Format {
 
 #ifndef U_HIDE_INTERNAL_API 
 
-#ifndef U_HIDE_DRAFT_API
     /**
      * ICU use only.
      * Initialize or change MeasureFormat class from subclass.
@@ -256,7 +283,6 @@ class U_I18N_API MeasureFormat : public Format {
             UMeasureFormatWidth width,
             NumberFormat *nfToAdopt,
             UErrorCode &status);
-#endif
     /**
      * ICU use only.
      * Allows subclass to change locale. Note that this method also changes
@@ -306,9 +332,7 @@ class U_I18N_API MeasureFormat : public Format {
     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
@@ -320,6 +344,20 @@ class U_I18N_API MeasureFormat : public Format {
             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,