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