]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/uameasureformat.h
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / uameasureformat.h
1 /*
2 *****************************************************************************************
3 * Copyright (C) 2014-2016 Apple Inc. All Rights Reserved.
4 *****************************************************************************************
5 */
6
7 #ifndef UAMEASUREFORMAT_H
8 #define UAMEASUREFORMAT_H
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13 #ifndef U_HIDE_DRAFT_API
14
15 #include "unicode/localpointer.h"
16 #include "unicode/unum.h"
17 #include "unicode/umisc.h"
18 #include "unicode/ufieldpositer.h"
19
20 /**
21 * \file
22 * \brief C API: Format combinations of measurement units and numeric values.
23 *
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.
26 */
27
28 /**
29 * Opaque UAMeasureFormat object for use in C programs.
30 * @draft ICU 53
31 */
32 struct UAMeasureFormat;
33 typedef struct UAMeasureFormat UAMeasureFormat; /**< C typedef for struct UAMeasureFormat. @draft ICU 53 */
34
35 /**
36 * Constants for various widths.
37 * @draft ICU 53
38 */
39 typedef enum UAMeasureFormatWidth {
40 /**
41 * Full unit names, e.g. "5 hours, 37 minutes"
42 * @draft ICU 53
43 */
44 UAMEASFMT_WIDTH_WIDE,
45
46 /**
47 * Abbreviated unit names, e.g. "5 hr, 37 min"
48 * @draft ICU 53
49 */
50 UAMEASFMT_WIDTH_SHORT,
51
52 /**
53 * Use unit symbols if possible, e.g. "5h 37m"
54 * @draft ICU 53
55 */
56 UAMEASFMT_WIDTH_NARROW,
57
58 /**
59 * Completely omit unit designatins if possible, e.g. "5:37"
60 * @draft ICU 53
61 */
62 UAMEASFMT_WIDTH_NUMERIC,
63
64 /**
65 * Shorter, between SHORT and NARROW, e.g. "5hr 37min"
66 * @draft ICU 57
67 */
68 UAMEASFMT_WIDTH_SHORTER,
69
70 /**
71 * Count of values in this enum.
72 * @draft ICU 53
73 */
74 UAMEASFMT_WIDTH_COUNT
75 } UAMeasureFormatWidth;
76
77 /**
78 * Measurement units
79 * @draft ICU 54
80 */
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)
84 //
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)
90 //
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 //
101 // (3 reserved for currency, handled separately)
102 //
103 UAMEASUNIT_DURATION_YEAR = (4 << 8) + 0,
104 UAMEASUNIT_DURATION_MONTH = (4 << 8) + 1,
105 UAMEASUNIT_DURATION_WEEK = (4 << 8) + 2,
106 UAMEASUNIT_DURATION_DAY = (4 << 8) + 3,
107 UAMEASUNIT_DURATION_HOUR = (4 << 8) + 4,
108 UAMEASUNIT_DURATION_MINUTE = (4 << 8) + 5,
109 UAMEASUNIT_DURATION_SECOND = (4 << 8) + 6,
110 UAMEASUNIT_DURATION_MILLISECOND = (4 << 8) + 7,
111 UAMEASUNIT_DURATION_MICROSECOND = (4 << 8) + 8, // (CLDR 26, ICU-541)
112 UAMEASUNIT_DURATION_NANOSECOND = (4 << 8) + 9, // (CLDR 26, ICU-541)
113 UAMEASUNIT_DURATION_CENTURY = (4 << 8) + 10, // (CLDR 28, ICU-561.3)
114 //
115 UAMEASUNIT_LENGTH_METER = (5 << 8) + 0,
116 UAMEASUNIT_LENGTH_CENTIMETER = (5 << 8) + 1,
117 UAMEASUNIT_LENGTH_KILOMETER = (5 << 8) + 2,
118 UAMEASUNIT_LENGTH_MILLIMETER = (5 << 8) + 3,
119 UAMEASUNIT_LENGTH_PICOMETER = (5 << 8) + 4,
120 UAMEASUNIT_LENGTH_FOOT = (5 << 8) + 5,
121 UAMEASUNIT_LENGTH_INCH = (5 << 8) + 6,
122 UAMEASUNIT_LENGTH_MILE = (5 << 8) + 7,
123 UAMEASUNIT_LENGTH_YARD = (5 << 8) + 8,
124 UAMEASUNIT_LENGTH_LIGHT_YEAR = (5 << 8) + 9,
125 UAMEASUNIT_LENGTH_DECIMETER = (5 << 8) + 10, // (CLDR 26, ICU-541)
126 UAMEASUNIT_LENGTH_MICROMETER = (5 << 8) + 11, // (CLDR 26, ICU-541)
127 UAMEASUNIT_LENGTH_NANOMETER = (5 << 8) + 12, // (CLDR 26, ICU-541)
128 UAMEASUNIT_LENGTH_NAUTICAL_MILE = (5 << 8) + 13, // (CLDR 26, ICU-541)
129 UAMEASUNIT_LENGTH_FATHOM = (5 << 8) + 14, // (CLDR 26, ICU-541)
130 UAMEASUNIT_LENGTH_FURLONG = (5 << 8) + 15, // (CLDR 26, ICU-541)
131 UAMEASUNIT_LENGTH_ASTRONOMICAL_UNIT = (5 << 8) + 16, // (CLDR 26, ICU-541)
132 UAMEASUNIT_LENGTH_PARSEC = (5 << 8) + 17, // (CLDR 26, ICU-541)
133 UAMEASUNIT_LENGTH_MILE_SCANDINAVIAN = (5 << 8) + 18, // (CLDR 28, ICU-561.3)
134 //
135 UAMEASUNIT_MASS_GRAM = (6 << 8) + 0,
136 UAMEASUNIT_MASS_KILOGRAM = (6 << 8) + 1,
137 UAMEASUNIT_MASS_OUNCE = (6 << 8) + 2,
138 UAMEASUNIT_MASS_POUND = (6 << 8) + 3,
139 UAMEASUNIT_MASS_STONE = (6 << 8) + 4, // = 14 pounds / 6.35 kg, abbr "st", used in UK/Ireland for body weight (CLDR 26)
140 UAMEASUNIT_MASS_MICROGRAM = (6 << 8) + 5, // (CLDR 26, ICU-541)
141 UAMEASUNIT_MASS_MILLIGRAM = (6 << 8) + 6, // (CLDR 26, ICU-541)
142 UAMEASUNIT_MASS_METRIC_TON = (6 << 8) + 7, // = "tonne" (CLDR 26, ICU-541)
143 UAMEASUNIT_MASS_TON = (6 << 8) + 8, // = "short ton", U.S. ton (CLDR 26, ICU-541)
144 UAMEASUNIT_MASS_CARAT = (6 << 8) + 9, // (CLDR 26, ICU-541)
145 UAMEASUNIT_MASS_OUNCE_TROY = (6 << 8) + 10, // (CLDR 26, ICU-541)
146 //
147 UAMEASUNIT_POWER_WATT = (7 << 8) + 0,
148 UAMEASUNIT_POWER_KILOWATT = (7 << 8) + 1,
149 UAMEASUNIT_POWER_HORSEPOWER = (7 << 8) + 2,
150 UAMEASUNIT_POWER_MILLIWATT = (7 << 8) + 3, // (CLDR 26, ICU-541)
151 UAMEASUNIT_POWER_MEGAWATT = (7 << 8) + 4, // (CLDR 26, ICU-541)
152 UAMEASUNIT_POWER_GIGAWATT = (7 << 8) + 5, // (CLDR 26, ICU-541)
153 //
154 UAMEASUNIT_PRESSURE_HECTOPASCAL = (8 << 8) + 0,
155 UAMEASUNIT_PRESSURE_INCH_HG = (8 << 8) + 1,
156 UAMEASUNIT_PRESSURE_MILLIBAR = (8 << 8) + 2,
157 UAMEASUNIT_PRESSURE_MILLIMETER_OF_MERCURY = (8 << 8) + 3, // (CLDR 26, ICU-541)
158 UAMEASUNIT_PRESSURE_POUND_PER_SQUARE_INCH = (8 << 8) + 4, // (CLDR 26, ICU-541)
159 //
160 UAMEASUNIT_SPEED_METER_PER_SECOND = (9 << 8) + 0,
161 UAMEASUNIT_SPEED_KILOMETER_PER_HOUR = (9 << 8) + 1,
162 UAMEASUNIT_SPEED_MILE_PER_HOUR = (9 << 8) + 2,
163 UAMEASUNIT_SPEED_KNOT = (9 << 8) + 3, // (CLDR 28, ICU-561.3)
164 //
165 UAMEASUNIT_TEMPERATURE_CELSIUS = (10 << 8) + 0,
166 UAMEASUNIT_TEMPERATURE_FAHRENHEIT = (10 << 8) + 1,
167 UAMEASUNIT_TEMPERATURE_KELVIN = (10 << 8) + 2, // (CLDR 26, ICU-541)
168 UAMEASUNIT_TEMPERATURE_GENERIC = (10 << 8) + 3, // (CLDR 27, ICU-550.2)
169 //
170 UAMEASUNIT_VOLUME_LITER = (11 << 8) + 0,
171 UAMEASUNIT_VOLUME_CUBIC_KILOMETER = (11 << 8) + 1,
172 UAMEASUNIT_VOLUME_CUBIC_MILE = (11 << 8) + 2,
173 UAMEASUNIT_VOLUME_MILLILITER = (11 << 8) + 3, // (CLDR 26, ICU-541)
174 UAMEASUNIT_VOLUME_CENTILITER = (11 << 8) + 4, // (CLDR 26, ICU-541)
175 UAMEASUNIT_VOLUME_DECILITER = (11 << 8) + 5, // (CLDR 26, ICU-541)
176 UAMEASUNIT_VOLUME_HECTOLITER = (11 << 8) + 6, // (CLDR 26, ICU-541)
177 UAMEASUNIT_VOLUME_MEGALITER = (11 << 8) + 7, // (CLDR 26, ICU-541)
178 UAMEASUNIT_VOLUME_CUBIC_CENTIMETER = (11 << 8) + 8, // (CLDR 26, ICU-541)
179 UAMEASUNIT_VOLUME_CUBIC_METER = (11 << 8) + 9, // (CLDR 26, ICU-541)
180 UAMEASUNIT_VOLUME_CUBIC_INCH = (11 << 8) + 10, // (CLDR 26, ICU-541)
181 UAMEASUNIT_VOLUME_CUBIC_FOOT = (11 << 8) + 11, // (CLDR 26, ICU-541)
182 UAMEASUNIT_VOLUME_CUBIC_YARD = (11 << 8) + 12, // (CLDR 26, ICU-541)
183 UAMEASUNIT_VOLUME_ACRE_FOOT = (11 << 8) + 13, // (CLDR 26, ICU-541)
184 UAMEASUNIT_VOLUME_BUSHEL = (11 << 8) + 14, // (CLDR 26, ICU-541)
185 UAMEASUNIT_VOLUME_TEASPOON = (11 << 8) + 15, // (CLDR 26, ICU-541)
186 UAMEASUNIT_VOLUME_TABLESPOON = (11 << 8) + 16, // (CLDR 26, ICU-541)
187 UAMEASUNIT_VOLUME_FLUID_OUNCE = (11 << 8) + 17, // (CLDR 26, ICU-541)
188 UAMEASUNIT_VOLUME_CUP = (11 << 8) + 18, // (CLDR 26, ICU-541)
189 UAMEASUNIT_VOLUME_PINT = (11 << 8) + 19, // (CLDR 26, ICU-541)
190 UAMEASUNIT_VOLUME_QUART = (11 << 8) + 20, // (CLDR 26, ICU-541)
191 UAMEASUNIT_VOLUME_GALLON = (11 << 8) + 21, // (CLDR 26, ICU-541)
192 UAMEASUNIT_VOLUME_CUP_METRIC = (11 << 8) + 22, // (CLDR 28, ICU-561.3)
193 UAMEASUNIT_VOLUME_PINT_METRIC = (11 << 8) + 23, // (CLDR 28, ICU-561.3)
194 UAMEASUNIT_VOLUME_GALLON_IMPERIAL = (11 << 8) + 24, // (CLDR 29, ICU-561.8+)
195 //
196 // new categories/values in CLDR 26
197 //
198 UAMEASUNIT_ENERGY_JOULE = (12 << 8) + 2,
199 UAMEASUNIT_ENERGY_KILOJOULE = (12 << 8) + 4,
200 UAMEASUNIT_ENERGY_CALORIE = (12 << 8) + 0, // chemistry "calories", abbr "cal"
201 UAMEASUNIT_ENERGY_KILOCALORIE = (12 << 8) + 3, // kilocalories in general (chemistry, food), abbr "kcal"
202 UAMEASUNIT_ENERGY_FOODCALORIE = (12 << 8) + 1, // kilocalories specifically for food; in US/UK/? "Calories" abbr "C", elsewhere same as "kcal"
203 UAMEASUNIT_ENERGY_KILOWATT_HOUR = (12 << 8) + 5, // (ICU-541)
204 //
205 // new categories/values in CLDR 26 & ICU-541
206 //
207 UAMEASUNIT_CONSUMPTION_LITER_PER_KILOMETER = (13 << 8) + 0,
208 UAMEASUNIT_CONSUMPTION_MILE_PER_GALLON = (13 << 8) + 1,
209 UAMEASUNIT_CONSUMPTION_LITER_PER_100_KILOMETERs = (13 << 8) + 2, // (CLDR 28, ICU-561.3)
210 UAMEASUNIT_CONSUMPTION_MILE_PER_GALLON_IMPERIAL = (13 << 8) + 3, // (CLDR 29, ICU-561.8+)
211 //
212 UAMEASUNIT_DIGITAL_BIT = (14 << 8) + 0,
213 UAMEASUNIT_DIGITAL_BYTE = (14 << 8) + 1,
214 UAMEASUNIT_DIGITAL_GIGABIT = (14 << 8) + 2,
215 UAMEASUNIT_DIGITAL_GIGABYTE = (14 << 8) + 3,
216 UAMEASUNIT_DIGITAL_KILOBIT = (14 << 8) + 4,
217 UAMEASUNIT_DIGITAL_KILOBYTE = (14 << 8) + 5,
218 UAMEASUNIT_DIGITAL_MEGABIT = (14 << 8) + 6,
219 UAMEASUNIT_DIGITAL_MEGABYTE = (14 << 8) + 7,
220 UAMEASUNIT_DIGITAL_TERABIT = (14 << 8) + 8,
221 UAMEASUNIT_DIGITAL_TERABYTE = (14 << 8) + 9,
222 //
223 UAMEASUNIT_ELECTRIC_AMPERE = (15 << 8) + 0,
224 UAMEASUNIT_ELECTRIC_MILLIAMPERE = (15 << 8) + 1,
225 UAMEASUNIT_ELECTRIC_OHM = (15 << 8) + 2,
226 UAMEASUNIT_ELECTRIC_VOLT = (15 << 8) + 3,
227 //
228 UAMEASUNIT_FREQUENCY_HERTZ = (16 << 8) + 0,
229 UAMEASUNIT_FREQUENCY_KILOHERTZ = (16 << 8) + 1,
230 UAMEASUNIT_FREQUENCY_MEGAHERTZ = (16 << 8) + 2,
231 UAMEASUNIT_FREQUENCY_GIGAHERTZ = (16 << 8) + 3,
232 //
233 UAMEASUNIT_LIGHT_LUX = (17 << 8) + 0,
234 //
235 // new categories/values in CLDR 29, ICU-561.8+
236 //
237 UAMEASUNIT_CONCENTRATION_KARAT = (18 << 8) + 0, // (CLDR 29, ICU-561.8+)
238 UAMEASUNIT_CONCENTRATION_MILLIGRAM_PER_DECILITER = (18 << 8) + 1, // (CLDR 29, ICU-561.8+)
239 UAMEASUNIT_CONCENTRATION_MILLIMOLE_PER_LITER = (18 << 8) + 2, // (CLDR 29, ICU-561.8+)
240 UAMEASUNIT_CONCENTRATION_PART_PER_MILLION = (18 << 8) + 3, // (CLDR 29, ICU-561.8+)
241 //
242 } UAMeasureUnit;
243
244 enum {
245 // Mask bit set in UFieldPosition, in addition to a UAMeasureUnit value,
246 // to indicate the numeric portion of the field corresponding to the UAMeasureUnit.
247 UAMEASFMT_NUMERIC_FIELD_FLAG = (1 << 30)
248 };
249
250 /**
251 * Structure that combines value and UAMeasureUnit,
252 * for use with uameasfmt_formatMultiple to specify a
253 * list of value/unit combinations to format.
254 * @draft ICU 54
255 */
256 typedef struct UAMeasure {
257 double value;
258 UAMeasureUnit unit;
259 } UAMeasure;
260
261
262 /**
263 * Open a new UAMeasureFormat object for a given locale using the specified width,
264 * along with a number formatter (if desired) to override the default formatter
265 * that would be used for the numeric part of the unit in uameasfmt_format, or the
266 * numeric part of the *last unit* (only) in uameasfmt_formatMultiple. The default
267 * formatter typically rounds toward 0 and has a minimum of 0 fraction digits and a
268 * maximum of 3 fraction digits (i.e. it will show as many decimal places as
269 * necessary up to 3, without showing trailing 0s). An alternate number formatter
270 * can be used to produce (e.g.) "37.0 mins" instead of "37 mins", or
271 * "5 hours, 37.2 minutes" instead of "5 hours, 37.217 minutes".
272 *
273 * @param locale
274 * The locale
275 * @param style
276 * The width - wide, short, narrow, etc.
277 * @param nfToAdopt
278 * A number formatter to set for this UAMeasureFormat object (instead of
279 * the default decimal formatter). Ownership of this UNumberFormat object
280 * will pass to the UAMeasureFormat object (the UAMeasureFormat adopts the
281 * UNumberFormat), which becomes responsible for closing it. If the caller
282 * wishes to retain ownership of the UNumberFormat object, the caller must
283 * clone it (with unum_clone) and pass the clone to
284 * uatmufmt_openWithNumberFormat. May be NULL to use the default decimal
285 * formatter.
286 * @param status
287 * A pointer to a UErrorCode to receive any errors.
288 * @return
289 * A pointer to a UAMeasureFormat object for the specified locale,
290 * or NULL if an error occurred.
291 * @draft ICU 54
292 */
293 U_DRAFT UAMeasureFormat* U_EXPORT2
294 uameasfmt_open( const char* locale,
295 UAMeasureFormatWidth width,
296 UNumberFormat* nfToAdopt,
297 UErrorCode* status );
298
299 /**
300 * Close a UAMeasureFormat object. Once closed it may no longer be used.
301 * @param measfmt
302 * The UATimeUnitFormat object to close.
303 * @draft ICU 54
304 */
305 U_DRAFT void U_EXPORT2
306 uameasfmt_close(UAMeasureFormat *measfmt);
307
308 #if U_SHOW_CPLUSPLUS_API
309
310 U_NAMESPACE_BEGIN
311
312 /**
313 * \class LocalUAMeasureFormatPointer
314 * "Smart pointer" class, closes a UAMeasureFormat via uameasfmt_close().
315 * For most methods see the LocalPointerBase base class.
316 *
317 * @see LocalPointerBase
318 * @see LocalPointer
319 * @draft ICU 54
320 */
321 U_DEFINE_LOCAL_OPEN_POINTER(LocalUAMeasureFormatPointer, UAMeasureFormat, uameasfmt_close);
322
323 U_NAMESPACE_END
324
325 #endif
326
327
328 /**
329 * Format a value like 1.0 and a field like UAMEASUNIT_DURATION_MINUTE to e.g. "1.0 minutes".
330 *
331 * @param measfmt
332 * The UAMeasureFormat object specifying the format conventions.
333 * @param value
334 * The numeric value to format
335 * @param unit
336 * The unit to format with the specified numeric value
337 * @param result
338 * A pointer to a buffer to receive the formatted result.
339 * @param resultCapacity
340 * The maximum size of result.
341 * @param status
342 * A pointer to a UErrorCode to receive any errors. In case of error status,
343 * the contents of result are undefined.
344 * @return
345 * The length of the formatted result; may be greater than resultCapacity,
346 * in which case an error is returned.
347 * @draft ICU 54
348 */
349 U_DRAFT int32_t U_EXPORT2
350 uameasfmt_format( const UAMeasureFormat* measfmt,
351 double value,
352 UAMeasureUnit unit,
353 UChar* result,
354 int32_t resultCapacity,
355 UErrorCode* status );
356
357 /**
358 * Format a value like 1.0 and a field like UAMEASUNIT_DURATION_MINUTE to e.g. "1.0 minutes",
359 * and get the position in the formatted result for certain types for fields.
360 *
361 * @param measfmt
362 * The UAMeasureFormat object specifying the format conventions.
363 * @param value
364 * The numeric value to format
365 * @param unit
366 * The unit to format with the specified numeric value
367 * @param result
368 * A pointer to a buffer to receive the formatted result.
369 * @param resultCapacity
370 * The maximum size of result.
371 * @param pos
372 * A pointer to a UFieldPosition. On input, pos->field is read; this should
373 * be a value from the UNumberFormatFields enum in unum.h. On output,
374 * pos->beginIndex and pos->endIndex indicate the beginning and ending offsets
375 * of that field in the formatted output, if relevant. This parameter may be
376 * NULL if no position information is desired.
377 * @param status
378 * A pointer to a UErrorCode to receive any errors. In case of error status,
379 * the contents of result are undefined.
380 * @return
381 * The length of the formatted result; may be greater than resultCapacity,
382 * in which case an error is returned.
383 * @draft ICU 54
384 */
385 U_DRAFT int32_t U_EXPORT2
386 uameasfmt_formatGetPosition( const UAMeasureFormat* measfmt,
387 double value,
388 UAMeasureUnit unit,
389 UChar* result,
390 int32_t resultCapacity,
391 UFieldPosition* pos,
392 UErrorCode* status );
393
394 /**
395 * Format a list of value and unit combinations, using locale-appropriate
396 * conventions for the list. Each combination is represented by a UAMeasure
397 * that combines a value and unit, such as 5.3 + UAMEASUNIT_DURATION_HOUR or
398 * 37.2 + UAMEASUNIT_DURATION_MINUTE. For all except the last UAMeasure in the
399 * list, the numeric part will be formatted using the default formatter (zero
400 * decimal places, rounds toward 0); for the last UAMeasure, the default may
401 * be overriden by passing a number formatter in uameasfmt_open. The result
402 * can thus be something like "5 hours, 37.2 minutes" or "5 hrs, 37.2 mins".
403 *
404 * @param measfmt
405 * The UAMeasureFormat object specifying the format conventions.
406 * @param measures
407 * A list of UAMeasure structs each specifying a numeric value
408 * and a UAMeasureUnit.
409 * @param measureCount
410 * The count of UAMeasureUnits in measures. Currently this has a limit of 8.
411 * @param result
412 * A pointer to a buffer to receive the formatted result.
413 * @param resultCapacity
414 * The maximum size of result.
415 * @param status
416 * A pointer to a UErrorCode to receive any errors. In case of error status,
417 * the contents of result are undefined.
418 * @return
419 * The length of the formatted result; may be greater than resultCapacity,
420 * in which case an error is returned.
421 * @draft ICU 54
422 */
423 U_DRAFT int32_t U_EXPORT2
424 uameasfmt_formatMultiple( const UAMeasureFormat* measfmt,
425 const UAMeasure* measures,
426 int32_t measureCount,
427 UChar* result,
428 int32_t resultCapacity,
429 UErrorCode* status );
430
431 /**
432 * Format a list of value and unit combinations, using locale-appropriate
433 * conventions for the list. This has the same format behavior as
434 * uameasfmt_formatMultiple but adds the fpositer parameter.
435 *
436 * @param measfmt
437 * The UAMeasureFormat object specifying the format conventions.
438 * @param measures
439 * A list of UAMeasure structs each specifying a numeric value
440 * and a UAMeasureUnit.
441 * @param measureCount
442 * The count of UAMeasureUnits in measures. Currently this has a limit of 8.
443 * @param result
444 * A pointer to a buffer to receive the formatted result.
445 * @param resultCapacity
446 * The maximum size of result.
447 * @param fpositer
448 * A pointer to a UFieldPositionIterator created by ufieldpositer_open
449 * (may be NULL if field position information is not needed). Any
450 * iteration information already present in the UFieldPositionIterator
451 * will be deleted, and the iterator will be reset to apply to the
452 * fields in the formatted string created by this function call. In the
453 * the formatted result, each unit field (unit name or symbol plus any
454 * associated numeric value) will correspond to one or two results from
455 * ufieldpositer_next. The first result returns a UAMeasureUnit value and
456 * indicates the begin and end index for the complete field. If there is
457 * a numeric value contained in the field, then a subsequent call to
458 * ufieldpositer_next returns a value with UAMEASFMT_NUMERIC_FIELD_FLAG
459 * set and the same UAMeasureUnit value in the low-order bits, and
460 * indicates the begin and end index for the numeric portion of the field.
461 * For example with the string "3 hours, dualminute" the sequence of
462 * calls to ufieldpositer_next would result in:
463 * (1) return UAMEASUNIT_DURATION_HOUR, begin index 0, end index 7
464 * (2) return UAMEASUNIT_DURATION_HOUR | UAMEASFMT_NUMERIC_FIELD_FLAG, begin index 0, end index 1
465 * (3) return UAMEASUNIT_DURATION_MINUTE, begin index 9, end index 19
466 * (4) return -1 to indicate end of interation
467 * @param status
468 * A pointer to a UErrorCode to receive any errors. In case of error status,
469 * the contents of result are undefined.
470 * @return
471 * The length of the formatted result; may be greater than resultCapacity,
472 * in which case an error is returned.
473 * @draft ICU 58
474 */
475 U_DRAFT int32_t U_EXPORT2
476 uameasfmt_formatMultipleForFields( const UAMeasureFormat* measfmt,
477 const UAMeasure* measures,
478 int32_t measureCount,
479 UChar* result,
480 int32_t resultCapacity,
481 UFieldPositionIterator* fpositer,
482 UErrorCode* status );
483
484 /**
485 * Get the display name for a unit, such as "minutes" or "kilometers".
486 *
487 * @param measfmt
488 * The UAMeasureFormat object specifying the format conventions.
489 * @param unit
490 * The unit whose localized name to get
491 * @param result
492 * A pointer to a buffer to receive the name.
493 * @param resultCapacity
494 * The maximum size of result.
495 * @param status
496 * A pointer to a UErrorCode to receive any errors. In case of error status,
497 * the contents of result are undefined.
498 * @return
499 * The length of the name; may be greater than resultCapacity,
500 * in which case an error is returned.
501 * @draft ICU 57
502 */
503 U_DRAFT int32_t U_EXPORT2
504 uameasfmt_getUnitName( const UAMeasureFormat* measfmt,
505 UAMeasureUnit unit,
506 UChar* result,
507 int32_t resultCapacity,
508 UErrorCode* status );
509
510 /**
511 * Constants for unit display name list styles
512 * @draft ICU 57
513 */
514 typedef enum UAMeasureNameListStyle {
515 /**
516 * Use standard (linguistic) list style, the same for all unit widths; e.g.
517 * wide: "hours, minutes, and seconds"
518 * short: "hours, min, and secs"
519 * narrow: "hour, min, and sec"
520 * @draft ICU 57
521 */
522 UAMEASNAME_LIST_STANDARD,
523
524 /**
525 * Use the same list style as used by the formatted units, depends on width; e.g.
526 * wide: "hours, minutes, seconds"
527 * short: "hours, min, secs"
528 * narrow: "hour min sec"
529 * @draft ICU 57
530 */
531 UAMEASNAME_LIST_MATCHUNITS,
532 } UAMeasureNameListStyle;
533
534 /**
535 * Get a list of display names for multiple units
536 *
537 * @param measfmt
538 * The UAMeasureFormat object specifying the format conventions.
539 * @param units
540 * The array of unit types whose names to get.
541 * @param unitCount
542 * The number of unit types in the units array.
543 * @param listStyle
544 * The list style used for combining the unit names.
545 * @param result
546 * A pointer to a buffer to receive the list of names.
547 * @param resultCapacity
548 * The maximum size of result.
549 * @param status
550 * A pointer to a UErrorCode to receive any errors. In case of error status,
551 * the contents of result are undefined.
552 * @return
553 * The length of the list of names; may be greater than resultCapacity,
554 * in which case an error is returned.
555 * @draft ICU 57
556 */
557 U_DRAFT int32_t U_EXPORT2
558 uameasfmt_getMultipleUnitNames( const UAMeasureFormat* measfmt,
559 const UAMeasureUnit* units,
560 int32_t unitCount,
561 UAMeasureNameListStyle listStyle,
562 UChar* result,
563 int32_t resultCapacity,
564 UErrorCode* status );
565
566 /**
567 * Get the units used for a particular usage. This low-level function depends
568 * one some knowledge of the relevant CLDR keys. After more experience with
569 * usage, enums for relevant usage values may be created.
570 *
571 * @param locale
572 * The locale.
573 * @param category
574 * A string representing the CLDR category key for the desired usage,
575 * such as "length" or "mass". Must not be NULL.
576 * @param usage
577 * A string representing the CLDR usage subkey for the desired usage,
578 * such as "person", "person-small" (for infants), "person-informal"
579 * (for conversational/informal usage), etc. To get the general unit
580 * for the category (not for a specific usage), this may be NULL, or
581 * may be just "large" or "small" to indicate a variant of the general
582 * unit for larger or smaller ranges than normal.
583 * @param units
584 * Array to be filled in with UAMeasureUnit values; the size is
585 * specified by unitsCapacity (which in general should be at least 3).
586 * The number of array elements actually filled in is indicated by
587 * the return value; if no error status is set then this will be
588 * non-zero.
589 *
590 * If the return value is positive then units represents an ordered
591 * list of one or more units that should be used in combination for
592 * the desired usage (e.g. the values UAMEASUNIT_LENGTH_FOOT,
593 * UAMEASUNIT_LENGTH_INCH to indicate a height expressed as a
594 * combination of feet and inches, or just UAMEASUNIT_LENGTH_CENTIMETER
595 * to indicate height expressed in centimeters alone).
596 *
597 * Negative return values may be used for future uses (such as
598 * indicating an X-per-Y relationship among the returned units).
599 *
600 * The units parameter may be NULL if unitsCapacity is 0, for
601 * pre-flighting (i.e. to determine the size of the units array that
602 * woud be required for the given category and usage).
603 * @param unitsCapacity
604 * The maximum capacity of the passed-in units array.
605 * @param status
606 * A pointer to a UErrorCode to receive any errors. In case of error status,
607 * the contents of result are undefined.
608 * @return
609 * Positive values indicate the number of units require for the usage;
610 * may be greater than resultCapacity, in which case an error is returned.
611 * If no error, than this number of units are actually provided in the
612 * units array. Negative return values are reserved for future uses.
613 * @draft ICU 57
614 */
615 U_DRAFT int32_t U_EXPORT2
616 uameasfmt_getUnitsForUsage( const char* locale,
617 const char* category,
618 const char* usage,
619 UAMeasureUnit* units,
620 int32_t unitsCapacity,
621 UErrorCode* status );
622
623 /**
624 * Get the (non-localized) category name for a unit. For example, for
625 * UAMEASUNIT_VOLUME_LITER, returns "volume".
626 *
627 * @param unit
628 * The unit whose category name to get
629 * @param status
630 * A pointer to a UErrorCode to receive any errors. In case of error status,
631 * the return value is undefined.
632 * @return
633 * Pointer to a zero-terminated string giving the
634 * (non-localized) category name.
635 * @draft ICU 58
636 */
637 U_DRAFT const char * U_EXPORT2
638 uameasfmt_getUnitCategory(UAMeasureUnit unit,
639 UErrorCode* status );
640
641
642 #endif /* U_HIDE_DRAFT_API */
643 #endif /* #if !UCONFIG_NO_FORMATTING */
644
645 #endif /* #ifndef UAMEASUREFORMAT_H */