IMPORTANT: New users are strongly encouraged to see if 93 * numberformatter.h fits their use case. Although not deprecated, this header 94 * is provided for backwards compatibility only, and has much more limited 95 * capabilities. 96 * 97 * @see Format 98 * @author Alan Liu 99 * @stable ICU 3.0 100 */ 101 class U_I18N_API MeasureFormat : public Format { 102 public: 103 using Format::parseObject; 104 using Format::format; 105 106 /** 107 * Constructor. 108 *
109 * NOTE: New users are strongly encouraged to use 110 * {@link icu::number::NumberFormatter} instead of NumberFormat. 111 * @stable ICU 53 112 */ 113 MeasureFormat( 114 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status); 115 116 /** 117 * Constructor. 118 *
119 * NOTE: New users are strongly encouraged to use 120 * {@link icu::number::NumberFormatter} instead of NumberFormat. 121 * @stable ICU 53 122 */ 123 MeasureFormat( 124 const Locale &locale, 125 UMeasureFormatWidth width, 126 NumberFormat *nfToAdopt, 127 UErrorCode &status); 128 129 /** 130 * Copy constructor. 131 * @stable ICU 3.0 132 */ 133 MeasureFormat(const MeasureFormat &other); 134 135 /** 136 * Assignment operator. 137 * @stable ICU 3.0 138 */ 139 MeasureFormat &operator=(const MeasureFormat &rhs); 140 141 /** 142 * Destructor. 143 * @stable ICU 3.0 144 */ 145 virtual ~MeasureFormat(); 146 147 /** 148 * Return true if given Format objects are semantically equal. 149 * @stable ICU 53 150 */ 151 virtual bool operator==(const Format &other) const override; 152 153 /** 154 * Clones this object polymorphically. 155 * @stable ICU 53 156 */ 157 virtual MeasureFormat *clone() const override; 158 159 /** 160 * Formats object to produce a string. 161 * @stable ICU 53 162 */ 163 virtual UnicodeString &format( 164 const Formattable &obj, 165 UnicodeString &appendTo, 166 FieldPosition &pos, 167 UErrorCode &status) const override; 168 169 #ifndef U_FORCE_HIDE_DRAFT_API 170 /** 171 * Parse a string to produce an object. This implementation sets 172 * status to U_UNSUPPORTED_ERROR. 173 * 174 * @draft ICU 53 175 */ 176 virtual void parseObject( 177 const UnicodeString &source, 178 Formattable &reslt, 179 ParsePosition &pos) const override; 180 #endif // U_FORCE_HIDE_DRAFT_API 181 182 /** 183 * Formats measure objects to produce a string. An example of such a 184 * formatted string is 3 meters, 3.5 centimeters. Measure objects appear 185 * in the formatted string in the same order they appear in the "measures" 186 * array. The NumberFormat of this object is used only to format the amount 187 * of the very last measure. The other amounts are formatted with zero 188 * decimal places while rounding toward zero. 189 * @param measures array of measure objects. 190 * @param measureCount the number of measure objects. 191 * @param appendTo formatted string appended here. 192 * @param pos the field position. 193 * @param status the error. 194 * @return appendTo reference 195 * 196 * @stable ICU 53 197 */ 198 UnicodeString &formatMeasures( 199 const Measure *measures, 200 int32_t measureCount, 201 UnicodeString &appendTo, 202 FieldPosition &pos, 203 UErrorCode &status) const; 204 205 /** 206 * Formats a single measure per unit. An example of such a 207 * formatted string is 3.5 meters per second. 208 * @param measure The measure object. In above example, 3.5 meters. 209 * @param perUnit The per unit. In above example, it is 210 * `*%MeasureUnit::createSecond(status)`. 211 * @param appendTo formatted string appended here. 212 * @param pos the field position. 213 * @param status the error. 214 * @return appendTo reference 215 * 216 * @stable ICU 55 217 */ 218 UnicodeString &formatMeasurePerUnit( 219 const Measure &measure, 220 const MeasureUnit &perUnit, 221 UnicodeString &appendTo, 222 FieldPosition &pos, 223 UErrorCode &status) const; 224 225 /** 226 * Gets the display name of the specified {@link MeasureUnit} corresponding to the current 227 * locale and format width. 228 * @param unit The unit for which to get a display name. 229 * @param status the error. 230 * @return The display name in the locale and width specified in 231 * the MeasureFormat constructor, or null if there is no display name available 232 * for the specified unit. 233 * 234 * @stable ICU 58 235 */ 236 UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const; 237 238 239 /** 240 * Return a formatter for CurrencyAmount objects in the given 241 * locale. 242 *
243 * NOTE: New users are strongly encouraged to use 244 * {@link icu::number::NumberFormatter} instead of NumberFormat. 245 * @param locale desired locale 246 * @param ec input-output error code 247 * @return a formatter object, or nullptr upon error 248 * @stable ICU 3.0 249 */ 250 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale, 251 UErrorCode& ec); 252 253 /** 254 * Return a formatter for CurrencyAmount objects in the default 255 * locale. 256 *
257 * NOTE: New users are strongly encouraged to use 258 * {@link icu::number::NumberFormatter} instead of NumberFormat. 259 * @param ec input-output error code 260 * @return a formatter object, or nullptr upon error 261 * @stable ICU 3.0 262 */ 263 static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec); 264 265 /** 266 * Return the class ID for this class. This is useful only for comparing to 267 * a return value from getDynamicClassID(). For example: 268 *
269 * . Base* polymorphic_pointer = createPolymorphicObject(); 270 * . if (polymorphic_pointer->getDynamicClassID() == 271 * . erived::getStaticClassID()) ... 272 *