]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/uameasureformat.h
ICU-64232.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / uameasureformat.h
1 /*
2 *****************************************************************************************
3 * Copyright (C) 2014-2017 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 UAMEASUNIT_AREA_DUNAM = (2 << 8) + 9, // (CLDR 35, ICU-641)
101 //
102 // (3 reserved for currency, handled separately)
103 //
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)
119 //
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)
141 //
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)
156 //
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)
163 //
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)
172 //
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)
177 //
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)
182 //
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)
210 //
211 // new categories/values in CLDR 26
212 //
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)
221 //
222 // new categories/values in CLDR 26 & ICU-541
223 //
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+)
228 //
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)
240 //
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,
245 //
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,
250 //
251 UAMEASUNIT_LIGHT_LUX = (17 << 8) + 0,
252 UAMEASUNIT_LIGHT_SOLAR_LUMINOSITY = (17 << 8) + 1, // (CLDR 35, ICU-641)
253 //
254 // new categories/values in CLDR 29, ICU-561.8+
255 //
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)
264 //
265 // new categories/values in CLDR 35, ICU-641+
266 //
267 UAMEASUNIT_FORCE_NEWTON = (19 << 8) + 0, // (CLDR 35, ICU-641)
268 UAMEASUNIT_FORCE_POUND_FORCE = (19 << 8) + 1, // (CLDR 35, ICU-641)
269 //
270 UAMEASUNIT_TORQUE_NEWTON_METER = (20 << 8) + 0, // (CLDR 35, ICU-641)
271 UAMEASUNIT_TORQUE_POUND_FOOT = (20 << 8) + 1, // (CLDR 35, ICU-641)
272 //
273 } UAMeasureUnit;
274
275 enum {
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)
279 };
280
281 /**
282 * Structure that combines value and UAMeasureUnit,
283 * for use with uameasfmt_formatMultiple to specify a
284 * list of value/unit combinations to format.
285 * @draft ICU 54
286 */
287 typedef struct UAMeasure {
288 double value;
289 UAMeasureUnit unit;
290 } UAMeasure;
291
292
293 /**
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".
303 *
304 * @param locale
305 * The locale
306 * @param style
307 * The width - wide, short, narrow, etc.
308 * @param nfToAdopt
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
316 * formatter.
317 * @param status
318 * A pointer to a UErrorCode to receive any errors.
319 * @return
320 * A pointer to a UAMeasureFormat object for the specified locale,
321 * or NULL if an error occurred.
322 * @draft ICU 54
323 */
324 U_DRAFT UAMeasureFormat* U_EXPORT2
325 uameasfmt_open( const char* locale,
326 UAMeasureFormatWidth width,
327 UNumberFormat* nfToAdopt,
328 UErrorCode* status );
329
330 /**
331 * Close a UAMeasureFormat object. Once closed it may no longer be used.
332 * @param measfmt
333 * The UATimeUnitFormat object to close.
334 * @draft ICU 54
335 */
336 U_DRAFT void U_EXPORT2
337 uameasfmt_close(UAMeasureFormat *measfmt);
338
339 #if U_SHOW_CPLUSPLUS_API
340
341 U_NAMESPACE_BEGIN
342
343 /**
344 * \class LocalUAMeasureFormatPointer
345 * "Smart pointer" class, closes a UAMeasureFormat via uameasfmt_close().
346 * For most methods see the LocalPointerBase base class.
347 *
348 * @see LocalPointerBase
349 * @see LocalPointer
350 * @draft ICU 54
351 */
352 U_DEFINE_LOCAL_OPEN_POINTER(LocalUAMeasureFormatPointer, UAMeasureFormat, uameasfmt_close);
353
354 U_NAMESPACE_END
355
356 #endif // U_SHOW_CPLUSPLUS_API
357
358
359 /**
360 * Format a value like 1.0 and a field like UAMEASUNIT_DURATION_MINUTE to e.g. "1.0 minutes".
361 *
362 * @param measfmt
363 * The UAMeasureFormat object specifying the format conventions.
364 * @param value
365 * The numeric value to format
366 * @param unit
367 * The unit to format with the specified numeric value
368 * @param result
369 * A pointer to a buffer to receive the formatted result.
370 * @param resultCapacity
371 * The maximum size of result.
372 * @param status
373 * A pointer to a UErrorCode to receive any errors. In case of error status,
374 * the contents of result are undefined.
375 * @return
376 * The length of the formatted result; may be greater than resultCapacity,
377 * in which case an error is returned.
378 * @draft ICU 54
379 */
380 U_DRAFT int32_t U_EXPORT2
381 uameasfmt_format( const UAMeasureFormat* measfmt,
382 double value,
383 UAMeasureUnit unit,
384 UChar* result,
385 int32_t resultCapacity,
386 UErrorCode* status );
387
388 /**
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.
391 *
392 * @param measfmt
393 * The UAMeasureFormat object specifying the format conventions.
394 * @param value
395 * The numeric value to format
396 * @param unit
397 * The unit to format with the specified numeric value
398 * @param result
399 * A pointer to a buffer to receive the formatted result.
400 * @param resultCapacity
401 * The maximum size of result.
402 * @param pos
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.
408 * @param status
409 * A pointer to a UErrorCode to receive any errors. In case of error status,
410 * the contents of result are undefined.
411 * @return
412 * The length of the formatted result; may be greater than resultCapacity,
413 * in which case an error is returned.
414 * @draft ICU 54
415 */
416 U_DRAFT int32_t U_EXPORT2
417 uameasfmt_formatGetPosition( const UAMeasureFormat* measfmt,
418 double value,
419 UAMeasureUnit unit,
420 UChar* result,
421 int32_t resultCapacity,
422 UFieldPosition* pos,
423 UErrorCode* status );
424
425 /**
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".
434 *
435 * @param measfmt
436 * The UAMeasureFormat object specifying the format conventions.
437 * @param measures
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.
442 * @param result
443 * A pointer to a buffer to receive the formatted result.
444 * @param resultCapacity
445 * The maximum size of result.
446 * @param status
447 * A pointer to a UErrorCode to receive any errors. In case of error status,
448 * the contents of result are undefined.
449 * @return
450 * The length of the formatted result; may be greater than resultCapacity,
451 * in which case an error is returned.
452 * @draft ICU 54
453 */
454 U_DRAFT int32_t U_EXPORT2
455 uameasfmt_formatMultiple( const UAMeasureFormat* measfmt,
456 const UAMeasure* measures,
457 int32_t measureCount,
458 UChar* result,
459 int32_t resultCapacity,
460 UErrorCode* status );
461
462 /**
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.
466 *
467 * @param measfmt
468 * The UAMeasureFormat object specifying the format conventions.
469 * @param measures
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.
474 * @param result
475 * A pointer to a buffer to receive the formatted result.
476 * @param resultCapacity
477 * The maximum size of result.
478 * @param fpositer
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
498 * @param status
499 * A pointer to a UErrorCode to receive any errors. In case of error status,
500 * the contents of result are undefined.
501 * @return
502 * The length of the formatted result; may be greater than resultCapacity,
503 * in which case an error is returned.
504 * @draft ICU 58
505 */
506 U_DRAFT int32_t U_EXPORT2
507 uameasfmt_formatMultipleForFields( const UAMeasureFormat* measfmt,
508 const UAMeasure* measures,
509 int32_t measureCount,
510 UChar* result,
511 int32_t resultCapacity,
512 UFieldPositionIterator* fpositer,
513 UErrorCode* status );
514
515 /**
516 * Get the display name for a unit, such as "minutes" or "kilometers".
517 *
518 * @param measfmt
519 * The UAMeasureFormat object specifying the format conventions.
520 * @param unit
521 * The unit whose localized name to get
522 * @param result
523 * A pointer to a buffer to receive the name.
524 * @param resultCapacity
525 * The maximum size of result.
526 * @param status
527 * A pointer to a UErrorCode to receive any errors. In case of error status,
528 * the contents of result are undefined.
529 * @return
530 * The length of the name; may be greater than resultCapacity,
531 * in which case an error is returned.
532 * @draft ICU 57
533 */
534 U_DRAFT int32_t U_EXPORT2
535 uameasfmt_getUnitName( const UAMeasureFormat* measfmt,
536 UAMeasureUnit unit,
537 UChar* result,
538 int32_t resultCapacity,
539 UErrorCode* status );
540
541 /**
542 * Constants for unit display name list styles
543 * @draft ICU 57
544 */
545 typedef enum UAMeasureNameListStyle {
546 /**
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"
551 * @draft ICU 57
552 */
553 UAMEASNAME_LIST_STANDARD,
554
555 /**
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"
560 * @draft ICU 57
561 */
562 UAMEASNAME_LIST_MATCHUNITS,
563 } UAMeasureNameListStyle;
564
565 /**
566 * Get a list of display names for multiple units
567 *
568 * @param measfmt
569 * The UAMeasureFormat object specifying the format conventions.
570 * @param units
571 * The array of unit types whose names to get.
572 * @param unitCount
573 * The number of unit types in the units array.
574 * @param listStyle
575 * The list style used for combining the unit names.
576 * @param result
577 * A pointer to a buffer to receive the list of names.
578 * @param resultCapacity
579 * The maximum size of result.
580 * @param status
581 * A pointer to a UErrorCode to receive any errors. In case of error status,
582 * the contents of result are undefined.
583 * @return
584 * The length of the list of names; may be greater than resultCapacity,
585 * in which case an error is returned.
586 * @draft ICU 57
587 */
588 U_DRAFT int32_t U_EXPORT2
589 uameasfmt_getMultipleUnitNames( const UAMeasureFormat* measfmt,
590 const UAMeasureUnit* units,
591 int32_t unitCount,
592 UAMeasureNameListStyle listStyle,
593 UChar* result,
594 int32_t resultCapacity,
595 UErrorCode* status );
596
597 /**
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.
601 *
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.
609 *
610 * @param locale
611 * The locale, which determines the usage as specified above.
612 * @param category
613 * A string representing the CLDR category key for the desired usage,
614 * such as "length" or "mass". Must not be NULL.
615 * @param usage
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.
622 * @param units
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
627 * non-zero.
628 *
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).
635 *
636 * Negative return values may be used for future uses (such as
637 * indicating an X-per-Y relationship among the returned units).
638 *
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.
644 * @param status
645 * A pointer to a UErrorCode to receive any errors. In case of error status,
646 * the contents of result are undefined.
647 * @return
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.
652 * @draft ICU 57
653 */
654 U_DRAFT int32_t U_EXPORT2
655 uameasfmt_getUnitsForUsage( const char* locale,
656 const char* category,
657 const char* usage,
658 UAMeasureUnit* units,
659 int32_t unitsCapacity,
660 UErrorCode* status );
661
662 /**
663 * Get the (non-localized) category name for a unit. For example, for
664 * UAMEASUNIT_VOLUME_LITER, returns "volume".
665 *
666 * @param unit
667 * The unit whose category name to get
668 * @param status
669 * A pointer to a UErrorCode to receive any errors. In case of error status,
670 * the return value is undefined.
671 * @return
672 * Pointer to a zero-terminated string giving the
673 * (non-localized) category name.
674 * @draft ICU 58
675 */
676 U_DRAFT const char * U_EXPORT2
677 uameasfmt_getUnitCategory(UAMeasureUnit unit,
678 UErrorCode* status );
679
680
681 #endif /* U_HIDE_DRAFT_API */
682 #endif /* #if !UCONFIG_NO_FORMATTING */
683
684 #endif /* #ifndef UAMEASUREFORMAT_H */