2 *****************************************************************************************
3 * Copyright (C) 2014-2017 Apple Inc. All Rights Reserved.
4 *****************************************************************************************
7 #ifndef UAMEASUREFORMAT_H
8 #define UAMEASUREFORMAT_H
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
13 #ifndef U_HIDE_DRAFT_API
15 #include "unicode/localpointer.h"
16 #include "unicode/unum.h"
17 #include "unicode/umisc.h"
18 #include "unicode/ufieldpositer.h"
22 * \brief C API: Format combinations of measurement units and numeric values.
24 * This is a somewhat temporary Apple-specific wrapper for using C++ MeasureFormat
25 * to format Measure objects, until the official ICU C API is available.
29 * Opaque UAMeasureFormat object for use in C programs.
32 struct UAMeasureFormat
;
33 typedef struct UAMeasureFormat UAMeasureFormat
; /**< C typedef for struct UAMeasureFormat. @draft ICU 53 */
36 * Constants for various widths.
39 typedef enum UAMeasureFormatWidth
{
41 * Full unit names, e.g. "5 hours, 37 minutes"
47 * Abbreviated unit names, e.g. "5 hr, 37 min"
50 UAMEASFMT_WIDTH_SHORT
,
53 * Use unit symbols if possible, e.g. "5h 37m"
56 UAMEASFMT_WIDTH_NARROW
,
59 * Completely omit unit designatins if possible, e.g. "5:37"
62 UAMEASFMT_WIDTH_NUMERIC
,
65 * Shorter, between SHORT and NARROW, e.g. "5hr 37min"
68 UAMEASFMT_WIDTH_SHORTER
,
71 * Count of values in this enum.
75 } UAMeasureFormatWidth
;
81 typedef enum UAMeasureUnit
{
82 UAMEASUNIT_ACCELERATION_G_FORCE
= (0 << 8) + 0,
83 UAMEASUNIT_ACCELERATION_METER_PER_SECOND_SQUARED
= (0 << 8) + 1, // (CLDR 26, ICU-541)
85 UAMEASUNIT_ANGLE_DEGREE
= (1 << 8) + 0,
86 UAMEASUNIT_ANGLE_ARC_MINUTE
= (1 << 8) + 1,
87 UAMEASUNIT_ANGLE_ARC_SECOND
= (1 << 8) + 2,
88 UAMEASUNIT_ANGLE_RADIAN
= (1 << 8) + 3, // (CLDR 26, ICU-541)
89 UAMEASUNIT_ANGLE_REVOLUTION
= (1 << 8) + 4, // (CLDR 28, ICU-561.3)
91 UAMEASUNIT_AREA_SQUARE_METER
= (2 << 8) + 0,
92 UAMEASUNIT_AREA_SQUARE_KILOMETER
= (2 << 8) + 1,
93 UAMEASUNIT_AREA_SQUARE_FOOT
= (2 << 8) + 2,
94 UAMEASUNIT_AREA_SQUARE_MILE
= (2 << 8) + 3,
95 UAMEASUNIT_AREA_ACRE
= (2 << 8) + 4,
96 UAMEASUNIT_AREA_HECTARE
= (2 << 8) + 5,
97 UAMEASUNIT_AREA_SQUARE_CENTIMETER
= (2 << 8) + 6, // (CLDR 26, ICU-541)
98 UAMEASUNIT_AREA_SQUARE_INCH
= (2 << 8) + 7, // (CLDR 26, ICU-541)
99 UAMEASUNIT_AREA_SQUARE_YARD
= (2 << 8) + 8, // (CLDR 26, ICU-541)
100 UAMEASUNIT_AREA_DUNAM
= (2 << 8) + 9, // (CLDR 35, ICU-641)
102 // (3 reserved for currency, handled separately)
104 UAMEASUNIT_DURATION_YEAR
= (4 << 8) + 0,
105 UAMEASUNIT_DURATION_MONTH
= (4 << 8) + 1,
106 UAMEASUNIT_DURATION_WEEK
= (4 << 8) + 2,
107 UAMEASUNIT_DURATION_DAY
= (4 << 8) + 3,
108 UAMEASUNIT_DURATION_HOUR
= (4 << 8) + 4,
109 UAMEASUNIT_DURATION_MINUTE
= (4 << 8) + 5,
110 UAMEASUNIT_DURATION_SECOND
= (4 << 8) + 6,
111 UAMEASUNIT_DURATION_MILLISECOND
= (4 << 8) + 7,
112 UAMEASUNIT_DURATION_MICROSECOND
= (4 << 8) + 8, // (CLDR 26, ICU-541)
113 UAMEASUNIT_DURATION_NANOSECOND
= (4 << 8) + 9, // (CLDR 26, ICU-541)
114 UAMEASUNIT_DURATION_CENTURY
= (4 << 8) + 10, // (CLDR 28, ICU-561.3)
115 UAMEASUNIT_DURATION_YEAR_PERSON
= (4 << 8) + 11, // (CLDR 35, ICU-641)
116 UAMEASUNIT_DURATION_MONTH_PERSON
= (4 << 8) + 12, // (CLDR 35, ICU-641)
117 UAMEASUNIT_DURATION_WEEK_PERSON
= (4 << 8) + 13, // (CLDR 35, ICU-641)
118 UAMEASUNIT_DURATION_DAY_PERSON
= (4 << 8) + 14, // (CLDR 35, ICU-641)
120 UAMEASUNIT_LENGTH_METER
= (5 << 8) + 0,
121 UAMEASUNIT_LENGTH_CENTIMETER
= (5 << 8) + 1,
122 UAMEASUNIT_LENGTH_KILOMETER
= (5 << 8) + 2,
123 UAMEASUNIT_LENGTH_MILLIMETER
= (5 << 8) + 3,
124 UAMEASUNIT_LENGTH_PICOMETER
= (5 << 8) + 4,
125 UAMEASUNIT_LENGTH_FOOT
= (5 << 8) + 5,
126 UAMEASUNIT_LENGTH_INCH
= (5 << 8) + 6,
127 UAMEASUNIT_LENGTH_MILE
= (5 << 8) + 7,
128 UAMEASUNIT_LENGTH_YARD
= (5 << 8) + 8,
129 UAMEASUNIT_LENGTH_LIGHT_YEAR
= (5 << 8) + 9,
130 UAMEASUNIT_LENGTH_DECIMETER
= (5 << 8) + 10, // (CLDR 26, ICU-541)
131 UAMEASUNIT_LENGTH_MICROMETER
= (5 << 8) + 11, // (CLDR 26, ICU-541)
132 UAMEASUNIT_LENGTH_NANOMETER
= (5 << 8) + 12, // (CLDR 26, ICU-541)
133 UAMEASUNIT_LENGTH_NAUTICAL_MILE
= (5 << 8) + 13, // (CLDR 26, ICU-541)
134 UAMEASUNIT_LENGTH_FATHOM
= (5 << 8) + 14, // (CLDR 26, ICU-541)
135 UAMEASUNIT_LENGTH_FURLONG
= (5 << 8) + 15, // (CLDR 26, ICU-541)
136 UAMEASUNIT_LENGTH_ASTRONOMICAL_UNIT
= (5 << 8) + 16, // (CLDR 26, ICU-541)
137 UAMEASUNIT_LENGTH_PARSEC
= (5 << 8) + 17, // (CLDR 26, ICU-541)
138 UAMEASUNIT_LENGTH_MILE_SCANDINAVIAN
= (5 << 8) + 18, // (CLDR 28, ICU-561.3)
139 UAMEASUNIT_LENGTH_POINT
= (5 << 8) + 19, // (CLDR 31, ICU-590)
140 UAMEASUNIT_LENGTH_SOLAR_RADIUS
= (5 << 8) + 20, // (CLDR 35, ICU-641)
142 UAMEASUNIT_MASS_GRAM
= (6 << 8) + 0,
143 UAMEASUNIT_MASS_KILOGRAM
= (6 << 8) + 1,
144 UAMEASUNIT_MASS_OUNCE
= (6 << 8) + 2,
145 UAMEASUNIT_MASS_POUND
= (6 << 8) + 3,
146 UAMEASUNIT_MASS_STONE
= (6 << 8) + 4, // = 14 pounds / 6.35 kg, abbr "st", used in UK/Ireland for body weight (CLDR 26)
147 UAMEASUNIT_MASS_MICROGRAM
= (6 << 8) + 5, // (CLDR 26, ICU-541)
148 UAMEASUNIT_MASS_MILLIGRAM
= (6 << 8) + 6, // (CLDR 26, ICU-541)
149 UAMEASUNIT_MASS_METRIC_TON
= (6 << 8) + 7, // = "tonne" (CLDR 26, ICU-541)
150 UAMEASUNIT_MASS_TON
= (6 << 8) + 8, // = "short ton", U.S. ton (CLDR 26, ICU-541)
151 UAMEASUNIT_MASS_CARAT
= (6 << 8) + 9, // (CLDR 26, ICU-541)
152 UAMEASUNIT_MASS_OUNCE_TROY
= (6 << 8) + 10, // (CLDR 26, ICU-541)
153 UAMEASUNIT_MASS_DALTON
= (6 << 8) + 11, // (CLDR 35, ICU-641)
154 UAMEASUNIT_MASS_EARTH_MASS
= (6 << 8) + 12, // (CLDR 35, ICU-641)
155 UAMEASUNIT_MASS_SOLAR_MASS
= (6 << 8) + 13, // (CLDR 35, ICU-641)
157 UAMEASUNIT_POWER_WATT
= (7 << 8) + 0,
158 UAMEASUNIT_POWER_KILOWATT
= (7 << 8) + 1,
159 UAMEASUNIT_POWER_HORSEPOWER
= (7 << 8) + 2,
160 UAMEASUNIT_POWER_MILLIWATT
= (7 << 8) + 3, // (CLDR 26, ICU-541)
161 UAMEASUNIT_POWER_MEGAWATT
= (7 << 8) + 4, // (CLDR 26, ICU-541)
162 UAMEASUNIT_POWER_GIGAWATT
= (7 << 8) + 5, // (CLDR 26, ICU-541)
164 UAMEASUNIT_PRESSURE_HECTOPASCAL
= (8 << 8) + 0,
165 UAMEASUNIT_PRESSURE_INCH_HG
= (8 << 8) + 1,
166 UAMEASUNIT_PRESSURE_MILLIBAR
= (8 << 8) + 2,
167 UAMEASUNIT_PRESSURE_MILLIMETER_OF_MERCURY
= (8 << 8) + 3, // (CLDR 26, ICU-541)
168 UAMEASUNIT_PRESSURE_POUND_PER_SQUARE_INCH
= (8 << 8) + 4, // (CLDR 26, ICU-541)
169 UAMEASUNIT_PRESSURE_ATMOSPHERE
= (8 << 8) + 5, // (CLDR 34, ICU-631)
170 UAMEASUNIT_PRESSURE_KILOPASCAL
= (8 << 8) + 6, // (CLDR 35, ICU-641)
171 UAMEASUNIT_PRESSURE_MEGAPASCAL
= (8 << 8) + 7, // (CLDR 35, ICU-641)
173 UAMEASUNIT_SPEED_METER_PER_SECOND
= (9 << 8) + 0,
174 UAMEASUNIT_SPEED_KILOMETER_PER_HOUR
= (9 << 8) + 1,
175 UAMEASUNIT_SPEED_MILE_PER_HOUR
= (9 << 8) + 2,
176 UAMEASUNIT_SPEED_KNOT
= (9 << 8) + 3, // (CLDR 28, ICU-561.3)
178 UAMEASUNIT_TEMPERATURE_CELSIUS
= (10 << 8) + 0,
179 UAMEASUNIT_TEMPERATURE_FAHRENHEIT
= (10 << 8) + 1,
180 UAMEASUNIT_TEMPERATURE_KELVIN
= (10 << 8) + 2, // (CLDR 26, ICU-541)
181 UAMEASUNIT_TEMPERATURE_GENERIC
= (10 << 8) + 3, // (CLDR 27, ICU-550.2)
183 UAMEASUNIT_VOLUME_LITER
= (11 << 8) + 0,
184 UAMEASUNIT_VOLUME_CUBIC_KILOMETER
= (11 << 8) + 1,
185 UAMEASUNIT_VOLUME_CUBIC_MILE
= (11 << 8) + 2,
186 UAMEASUNIT_VOLUME_MILLILITER
= (11 << 8) + 3, // (CLDR 26, ICU-541)
187 UAMEASUNIT_VOLUME_CENTILITER
= (11 << 8) + 4, // (CLDR 26, ICU-541)
188 UAMEASUNIT_VOLUME_DECILITER
= (11 << 8) + 5, // (CLDR 26, ICU-541)
189 UAMEASUNIT_VOLUME_HECTOLITER
= (11 << 8) + 6, // (CLDR 26, ICU-541)
190 UAMEASUNIT_VOLUME_MEGALITER
= (11 << 8) + 7, // (CLDR 26, ICU-541)
191 UAMEASUNIT_VOLUME_CUBIC_CENTIMETER
= (11 << 8) + 8, // (CLDR 26, ICU-541)
192 UAMEASUNIT_VOLUME_CUBIC_METER
= (11 << 8) + 9, // (CLDR 26, ICU-541)
193 UAMEASUNIT_VOLUME_CUBIC_INCH
= (11 << 8) + 10, // (CLDR 26, ICU-541)
194 UAMEASUNIT_VOLUME_CUBIC_FOOT
= (11 << 8) + 11, // (CLDR 26, ICU-541)
195 UAMEASUNIT_VOLUME_CUBIC_YARD
= (11 << 8) + 12, // (CLDR 26, ICU-541)
196 UAMEASUNIT_VOLUME_ACRE_FOOT
= (11 << 8) + 13, // (CLDR 26, ICU-541)
197 UAMEASUNIT_VOLUME_BUSHEL
= (11 << 8) + 14, // (CLDR 26, ICU-541)
198 UAMEASUNIT_VOLUME_TEASPOON
= (11 << 8) + 15, // (CLDR 26, ICU-541)
199 UAMEASUNIT_VOLUME_TABLESPOON
= (11 << 8) + 16, // (CLDR 26, ICU-541)
200 UAMEASUNIT_VOLUME_FLUID_OUNCE
= (11 << 8) + 17, // (CLDR 26, ICU-541)
201 UAMEASUNIT_VOLUME_CUP
= (11 << 8) + 18, // (CLDR 26, ICU-541)
202 UAMEASUNIT_VOLUME_PINT
= (11 << 8) + 19, // (CLDR 26, ICU-541)
203 UAMEASUNIT_VOLUME_QUART
= (11 << 8) + 20, // (CLDR 26, ICU-541)
204 UAMEASUNIT_VOLUME_GALLON
= (11 << 8) + 21, // (CLDR 26, ICU-541)
205 UAMEASUNIT_VOLUME_CUP_METRIC
= (11 << 8) + 22, // (CLDR 28, ICU-561.3)
206 UAMEASUNIT_VOLUME_PINT_METRIC
= (11 << 8) + 23, // (CLDR 28, ICU-561.3)
207 UAMEASUNIT_VOLUME_GALLON_IMPERIAL
= (11 << 8) + 24, // (CLDR 29, ICU-561.8+)
208 UAMEASUNIT_VOLUME_FLUID_OUNCE_IMPERIAL
= (11 << 8) + 25, // (CLDR 35, ICU-641)
209 UAMEASUNIT_VOLUME_BARREL
= (11 << 8) + 26, // (CLDR 35, ICU-641)
211 // new categories/values in CLDR 26
213 UAMEASUNIT_ENERGY_JOULE
= (12 << 8) + 2,
214 UAMEASUNIT_ENERGY_KILOJOULE
= (12 << 8) + 4,
215 UAMEASUNIT_ENERGY_CALORIE
= (12 << 8) + 0, // chemistry "calories", abbr "cal"
216 UAMEASUNIT_ENERGY_KILOCALORIE
= (12 << 8) + 3, // kilocalories in general (chemistry, food), abbr "kcal"
217 UAMEASUNIT_ENERGY_FOODCALORIE
= (12 << 8) + 1, // kilocalories specifically for food; in US/UK/? "Calories" abbr "C", elsewhere same as "kcal"
218 UAMEASUNIT_ENERGY_KILOWATT_HOUR
= (12 << 8) + 5, // (ICU-541)
219 UAMEASUNIT_ENERGY_ELECTRONVOLT
= (12 << 8) + 6, // (CLDR 35, ICU-641)
220 UAMEASUNIT_ENERGY_BRITISH_THERMAL_UNIT
= (12 << 8) + 7, // (CLDR 35, ICU-641)
222 // new categories/values in CLDR 26 & ICU-541
224 UAMEASUNIT_CONSUMPTION_LITER_PER_KILOMETER
= (13 << 8) + 0,
225 UAMEASUNIT_CONSUMPTION_MILE_PER_GALLON
= (13 << 8) + 1,
226 UAMEASUNIT_CONSUMPTION_LITER_PER_100_KILOMETERs
= (13 << 8) + 2, // (CLDR 28, ICU-561.3)
227 UAMEASUNIT_CONSUMPTION_MILE_PER_GALLON_IMPERIAL
= (13 << 8) + 3, // (CLDR 29, ICU-561.8+)
229 UAMEASUNIT_DIGITAL_BIT
= (14 << 8) + 0,
230 UAMEASUNIT_DIGITAL_BYTE
= (14 << 8) + 1,
231 UAMEASUNIT_DIGITAL_GIGABIT
= (14 << 8) + 2,
232 UAMEASUNIT_DIGITAL_GIGABYTE
= (14 << 8) + 3,
233 UAMEASUNIT_DIGITAL_KILOBIT
= (14 << 8) + 4,
234 UAMEASUNIT_DIGITAL_KILOBYTE
= (14 << 8) + 5,
235 UAMEASUNIT_DIGITAL_MEGABIT
= (14 << 8) + 6,
236 UAMEASUNIT_DIGITAL_MEGABYTE
= (14 << 8) + 7,
237 UAMEASUNIT_DIGITAL_TERABIT
= (14 << 8) + 8,
238 UAMEASUNIT_DIGITAL_TERABYTE
= (14 << 8) + 9,
239 UAMEASUNIT_DIGITAL_PETABYTE
= (14 << 8) + 10, // (CLDR 34, ICU-631)
241 UAMEASUNIT_ELECTRIC_AMPERE
= (15 << 8) + 0,
242 UAMEASUNIT_ELECTRIC_MILLIAMPERE
= (15 << 8) + 1,
243 UAMEASUNIT_ELECTRIC_OHM
= (15 << 8) + 2,
244 UAMEASUNIT_ELECTRIC_VOLT
= (15 << 8) + 3,
246 UAMEASUNIT_FREQUENCY_HERTZ
= (16 << 8) + 0,
247 UAMEASUNIT_FREQUENCY_KILOHERTZ
= (16 << 8) + 1,
248 UAMEASUNIT_FREQUENCY_MEGAHERTZ
= (16 << 8) + 2,
249 UAMEASUNIT_FREQUENCY_GIGAHERTZ
= (16 << 8) + 3,
251 UAMEASUNIT_LIGHT_LUX
= (17 << 8) + 0,
252 UAMEASUNIT_LIGHT_SOLAR_LUMINOSITY
= (17 << 8) + 1, // (CLDR 35, ICU-641)
254 // new categories/values in CLDR 29, ICU-561.8+
256 UAMEASUNIT_CONCENTRATION_KARAT
= (18 << 8) + 0, // (CLDR 29, ICU-561.8+)
257 UAMEASUNIT_CONCENTRATION_MILLIGRAM_PER_DECILITER
= (18 << 8) + 1, // (CLDR 29, ICU-561.8+)
258 UAMEASUNIT_CONCENTRATION_MILLIMOLE_PER_LITER
= (18 << 8) + 2, // (CLDR 29, ICU-561.8+)
259 UAMEASUNIT_CONCENTRATION_PART_PER_MILLION
= (18 << 8) + 3, // (CLDR 29, ICU-561.8+)
260 UAMEASUNIT_CONCENTRATION_PERCENT
= (18 << 8) + 4, // (CLDR 34, ICU-631nn)
261 UAMEASUNIT_CONCENTRATION_PERMILLE
= (18 << 8) + 5, // (CLDR 34, ICU-631nn)
262 UAMEASUNIT_CONCENTRATION_PERMYRIAD
= (18 << 8) + 6, // (CLDR 35, ICU-641)
263 UAMEASUNIT_CONCENTRATION_MOLE
= (18 << 8) + 7, // (CLDR 35, ICU-641)
265 // new categories/values in CLDR 35, ICU-641+
267 UAMEASUNIT_FORCE_NEWTON
= (19 << 8) + 0, // (CLDR 35, ICU-641)
268 UAMEASUNIT_FORCE_POUND_FORCE
= (19 << 8) + 1, // (CLDR 35, ICU-641)
270 UAMEASUNIT_TORQUE_NEWTON_METER
= (20 << 8) + 0, // (CLDR 35, ICU-641)
271 UAMEASUNIT_TORQUE_POUND_FOOT
= (20 << 8) + 1, // (CLDR 35, ICU-641)
276 // Mask bit set in UFieldPosition, in addition to a UAMeasureUnit value,
277 // to indicate the numeric portion of the field corresponding to the UAMeasureUnit.
278 UAMEASFMT_NUMERIC_FIELD_FLAG
= (1 << 30)
282 * Structure that combines value and UAMeasureUnit,
283 * for use with uameasfmt_formatMultiple to specify a
284 * list of value/unit combinations to format.
287 typedef struct UAMeasure
{
294 * Open a new UAMeasureFormat object for a given locale using the specified width,
295 * along with a number formatter (if desired) to override the default formatter
296 * that would be used for the numeric part of the unit in uameasfmt_format, or the
297 * numeric part of the *last unit* (only) in uameasfmt_formatMultiple. The default
298 * formatter typically rounds toward 0 and has a minimum of 0 fraction digits and a
299 * maximum of 3 fraction digits (i.e. it will show as many decimal places as
300 * necessary up to 3, without showing trailing 0s). An alternate number formatter
301 * can be used to produce (e.g.) "37.0 mins" instead of "37 mins", or
302 * "5 hours, 37.2 minutes" instead of "5 hours, 37.217 minutes".
307 * The width - wide, short, narrow, etc.
309 * A number formatter to set for this UAMeasureFormat object (instead of
310 * the default decimal formatter). Ownership of this UNumberFormat object
311 * will pass to the UAMeasureFormat object (the UAMeasureFormat adopts the
312 * UNumberFormat), which becomes responsible for closing it. If the caller
313 * wishes to retain ownership of the UNumberFormat object, the caller must
314 * clone it (with unum_clone) and pass the clone to
315 * uatmufmt_openWithNumberFormat. May be NULL to use the default decimal
318 * A pointer to a UErrorCode to receive any errors.
320 * A pointer to a UAMeasureFormat object for the specified locale,
321 * or NULL if an error occurred.
324 U_DRAFT UAMeasureFormat
* U_EXPORT2
325 uameasfmt_open( const char* locale
,
326 UAMeasureFormatWidth width
,
327 UNumberFormat
* nfToAdopt
,
328 UErrorCode
* status
);
331 * Close a UAMeasureFormat object. Once closed it may no longer be used.
333 * The UATimeUnitFormat object to close.
336 U_DRAFT
void U_EXPORT2
337 uameasfmt_close(UAMeasureFormat
*measfmt
);
339 #if U_SHOW_CPLUSPLUS_API
344 * \class LocalUAMeasureFormatPointer
345 * "Smart pointer" class, closes a UAMeasureFormat via uameasfmt_close().
346 * For most methods see the LocalPointerBase base class.
348 * @see LocalPointerBase
352 U_DEFINE_LOCAL_OPEN_POINTER(LocalUAMeasureFormatPointer
, UAMeasureFormat
, uameasfmt_close
);
356 #endif // U_SHOW_CPLUSPLUS_API
360 * Format a value like 1.0 and a field like UAMEASUNIT_DURATION_MINUTE to e.g. "1.0 minutes".
363 * The UAMeasureFormat object specifying the format conventions.
365 * The numeric value to format
367 * The unit to format with the specified numeric value
369 * A pointer to a buffer to receive the formatted result.
370 * @param resultCapacity
371 * The maximum size of result.
373 * A pointer to a UErrorCode to receive any errors. In case of error status,
374 * the contents of result are undefined.
376 * The length of the formatted result; may be greater than resultCapacity,
377 * in which case an error is returned.
380 U_DRAFT
int32_t U_EXPORT2
381 uameasfmt_format( const UAMeasureFormat
* measfmt
,
385 int32_t resultCapacity
,
386 UErrorCode
* status
);
389 * Format a value like 1.0 and a field like UAMEASUNIT_DURATION_MINUTE to e.g. "1.0 minutes",
390 * and get the position in the formatted result for certain types for fields.
393 * The UAMeasureFormat object specifying the format conventions.
395 * The numeric value to format
397 * The unit to format with the specified numeric value
399 * A pointer to a buffer to receive the formatted result.
400 * @param resultCapacity
401 * The maximum size of result.
403 * A pointer to a UFieldPosition. On input, pos->field is read; this should
404 * be a value from the UNumberFormatFields enum in unum.h. On output,
405 * pos->beginIndex and pos->endIndex indicate the beginning and ending offsets
406 * of that field in the formatted output, if relevant. This parameter may be
407 * NULL if no position information is desired.
409 * A pointer to a UErrorCode to receive any errors. In case of error status,
410 * the contents of result are undefined.
412 * The length of the formatted result; may be greater than resultCapacity,
413 * in which case an error is returned.
416 U_DRAFT
int32_t U_EXPORT2
417 uameasfmt_formatGetPosition( const UAMeasureFormat
* measfmt
,
421 int32_t resultCapacity
,
423 UErrorCode
* status
);
426 * Format a list of value and unit combinations, using locale-appropriate
427 * conventions for the list. Each combination is represented by a UAMeasure
428 * that combines a value and unit, such as 5.3 + UAMEASUNIT_DURATION_HOUR or
429 * 37.2 + UAMEASUNIT_DURATION_MINUTE. For all except the last UAMeasure in the
430 * list, the numeric part will be formatted using the default formatter (zero
431 * decimal places, rounds toward 0); for the last UAMeasure, the default may
432 * be overriden by passing a number formatter in uameasfmt_open. The result
433 * can thus be something like "5 hours, 37.2 minutes" or "5 hrs, 37.2 mins".
436 * The UAMeasureFormat object specifying the format conventions.
438 * A list of UAMeasure structs each specifying a numeric value
439 * and a UAMeasureUnit.
440 * @param measureCount
441 * The count of UAMeasureUnits in measures. Currently this has a limit of 8.
443 * A pointer to a buffer to receive the formatted result.
444 * @param resultCapacity
445 * The maximum size of result.
447 * A pointer to a UErrorCode to receive any errors. In case of error status,
448 * the contents of result are undefined.
450 * The length of the formatted result; may be greater than resultCapacity,
451 * in which case an error is returned.
454 U_DRAFT
int32_t U_EXPORT2
455 uameasfmt_formatMultiple( const UAMeasureFormat
* measfmt
,
456 const UAMeasure
* measures
,
457 int32_t measureCount
,
459 int32_t resultCapacity
,
460 UErrorCode
* status
);
463 * Format a list of value and unit combinations, using locale-appropriate
464 * conventions for the list. This has the same format behavior as
465 * uameasfmt_formatMultiple but adds the fpositer parameter.
468 * The UAMeasureFormat object specifying the format conventions.
470 * A list of UAMeasure structs each specifying a numeric value
471 * and a UAMeasureUnit.
472 * @param measureCount
473 * The count of UAMeasureUnits in measures. Currently this has a limit of 8.
475 * A pointer to a buffer to receive the formatted result.
476 * @param resultCapacity
477 * The maximum size of result.
479 * A pointer to a UFieldPositionIterator created by ufieldpositer_open
480 * (may be NULL if field position information is not needed). Any
481 * iteration information already present in the UFieldPositionIterator
482 * will be deleted, and the iterator will be reset to apply to the
483 * fields in the formatted string created by this function call. In the
484 * the formatted result, each unit field (unit name or symbol plus any
485 * associated numeric value) will correspond to one or two results from
486 * ufieldpositer_next. The first result returns a UAMeasureUnit value and
487 * indicates the begin and end index for the complete field. If there is
488 * a numeric value contained in the field, then a subsequent call to
489 * ufieldpositer_next returns a value with UAMEASFMT_NUMERIC_FIELD_FLAG
490 * set and the same UAMeasureUnit value in the low-order bits, and
491 * indicates the begin and end index for the numeric portion of the field.
492 * For example with the string "3 hours, dualminute" the sequence of
493 * calls to ufieldpositer_next would result in:
494 * (1) return UAMEASUNIT_DURATION_HOUR, begin index 0, end index 7
495 * (2) return UAMEASUNIT_DURATION_HOUR | UAMEASFMT_NUMERIC_FIELD_FLAG, begin index 0, end index 1
496 * (3) return UAMEASUNIT_DURATION_MINUTE, begin index 9, end index 19
497 * (4) return -1 to indicate end of interation
499 * A pointer to a UErrorCode to receive any errors. In case of error status,
500 * the contents of result are undefined.
502 * The length of the formatted result; may be greater than resultCapacity,
503 * in which case an error is returned.
506 U_DRAFT
int32_t U_EXPORT2
507 uameasfmt_formatMultipleForFields( const UAMeasureFormat
* measfmt
,
508 const UAMeasure
* measures
,
509 int32_t measureCount
,
511 int32_t resultCapacity
,
512 UFieldPositionIterator
* fpositer
,
513 UErrorCode
* status
);
516 * Get the display name for a unit, such as "minutes" or "kilometers".
519 * The UAMeasureFormat object specifying the format conventions.
521 * The unit whose localized name to get
523 * A pointer to a buffer to receive the name.
524 * @param resultCapacity
525 * The maximum size of result.
527 * A pointer to a UErrorCode to receive any errors. In case of error status,
528 * the contents of result are undefined.
530 * The length of the name; may be greater than resultCapacity,
531 * in which case an error is returned.
534 U_DRAFT
int32_t U_EXPORT2
535 uameasfmt_getUnitName( const UAMeasureFormat
* measfmt
,
538 int32_t resultCapacity
,
539 UErrorCode
* status
);
542 * Constants for unit display name list styles
545 typedef enum UAMeasureNameListStyle
{
547 * Use standard (linguistic) list style, the same for all unit widths; e.g.
548 * wide: "hours, minutes, and seconds"
549 * short: "hours, min, and secs"
550 * narrow: "hour, min, and sec"
553 UAMEASNAME_LIST_STANDARD
,
556 * Use the same list style as used by the formatted units, depends on width; e.g.
557 * wide: "hours, minutes, seconds"
558 * short: "hours, min, secs"
559 * narrow: "hour min sec"
562 UAMEASNAME_LIST_MATCHUNITS
,
563 } UAMeasureNameListStyle
;
566 * Get a list of display names for multiple units
569 * The UAMeasureFormat object specifying the format conventions.
571 * The array of unit types whose names to get.
573 * The number of unit types in the units array.
575 * The list style used for combining the unit names.
577 * A pointer to a buffer to receive the list of names.
578 * @param resultCapacity
579 * The maximum size of result.
581 * A pointer to a UErrorCode to receive any errors. In case of error status,
582 * the contents of result are undefined.
584 * The length of the list of names; may be greater than resultCapacity,
585 * in which case an error is returned.
588 U_DRAFT
int32_t U_EXPORT2
589 uameasfmt_getMultipleUnitNames( const UAMeasureFormat
* measfmt
,
590 const UAMeasureUnit
* units
,
592 UAMeasureNameListStyle listStyle
,
594 int32_t resultCapacity
,
595 UErrorCode
* status
);
598 * Get the units used for a particular usage. This low-level function depends
599 * one some knowledge of the relevant CLDR keys. After more experience with
600 * usage, enums for relevant usage values may be created.
602 * This is sensitive to two locale keywords.
603 * If the "ms" keyword is present, then the measurement system specified by its
604 * value is used (except for certain categories like duration and concentr).
605 * Else if the "rg" keyword is present, then the region specified by its value
606 * determines the unit usage.
607 * Else if the locale has a region subtag, it determines the unit usage.
608 * Otherwise the likely region for the language determines the usage.
611 * The locale, which determines the usage as specified above.
613 * A string representing the CLDR category key for the desired usage,
614 * such as "length" or "mass". Must not be NULL.
616 * A string representing the CLDR usage subkey for the desired usage,
617 * such as "person", "person-small" (for infants), "person-informal"
618 * (for conversational/informal usage), etc. To get the general unit
619 * for the category (not for a specific usage), this may be NULL, or
620 * may be just "large" or "small" to indicate a variant of the general
621 * unit for larger or smaller ranges than normal.
623 * Array to be filled in with UAMeasureUnit values; the size is
624 * specified by unitsCapacity (which in general should be at least 3).
625 * The number of array elements actually filled in is indicated by
626 * the return value; if no error status is set then this will be
629 * If the return value is positive then units represents an ordered
630 * list of one or more units that should be used in combination for
631 * the desired usage (e.g. the values UAMEASUNIT_LENGTH_FOOT,
632 * UAMEASUNIT_LENGTH_INCH to indicate a height expressed as a
633 * combination of feet and inches, or just UAMEASUNIT_LENGTH_CENTIMETER
634 * to indicate height expressed in centimeters alone).
636 * Negative return values may be used for future uses (such as
637 * indicating an X-per-Y relationship among the returned units).
639 * The units parameter may be NULL if unitsCapacity is 0, for
640 * pre-flighting (i.e. to determine the size of the units array that
641 * woud be required for the given category and usage).
642 * @param unitsCapacity
643 * The maximum capacity of the passed-in units array.
645 * A pointer to a UErrorCode to receive any errors. In case of error status,
646 * the contents of result are undefined.
648 * Positive values indicate the number of units require for the usage;
649 * may be greater than resultCapacity, in which case an error is returned.
650 * If no error, than this number of units are actually provided in the
651 * units array. Negative return values are reserved for future uses.
654 U_DRAFT
int32_t U_EXPORT2
655 uameasfmt_getUnitsForUsage( const char* locale
,
656 const char* category
,
658 UAMeasureUnit
* units
,
659 int32_t unitsCapacity
,
660 UErrorCode
* status
);
663 * Get the (non-localized) category name for a unit. For example, for
664 * UAMEASUNIT_VOLUME_LITER, returns "volume".
667 * The unit whose category name to get
669 * A pointer to a UErrorCode to receive any errors. In case of error status,
670 * the return value is undefined.
672 * Pointer to a zero-terminated string giving the
673 * (non-localized) category name.
676 U_DRAFT
const char * U_EXPORT2
677 uameasfmt_getUnitCategory(UAMeasureUnit unit
,
678 UErrorCode
* status
);
681 #endif /* U_HIDE_DRAFT_API */
682 #endif /* #if !UCONFIG_NO_FORMATTING */
684 #endif /* #ifndef UAMEASUREFORMAT_H */