]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
57a6839d A |
3 | /* |
4 | ********************************************************************** | |
2ca993e8 | 5 | * Copyright (c) 2004-2016, International Business Machines |
57a6839d A |
6 | * Corporation and others. All Rights Reserved. |
7 | ********************************************************************** | |
8 | * Author: Alan Liu | |
9 | * Created: April 26, 2004 | |
10 | * Since: ICU 3.0 | |
11 | ********************************************************************** | |
12 | */ | |
13 | #include "utypeinfo.h" // for 'typeid' to work | |
14 | ||
15 | #include "unicode/measunit.h" | |
16 | ||
17 | #if !UCONFIG_NO_FORMATTING | |
18 | ||
19 | #include "unicode/uenum.h" | |
20 | #include "ustrenum.h" | |
21 | #include "cstring.h" | |
22 | #include "uassert.h" | |
23 | ||
57a6839d A |
24 | U_NAMESPACE_BEGIN |
25 | ||
26 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureUnit) | |
27 | ||
b331163b A |
28 | // All code between the "Start generated code" comment and |
29 | // the "End generated code" comment is auto generated code | |
30 | // and must not be edited manually. For instructions on how to correctly | |
31 | // update this code, refer to: | |
32 | // http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit | |
33 | // | |
34 | // Start generated code | |
35 | ||
0f5d89e8 | 36 | |
57a6839d A |
37 | static const int32_t gOffsets[] = { |
38 | 0, | |
b331163b | 39 | 2, |
2ca993e8 A |
40 | 7, |
41 | 16, | |
42 | 20, | |
43 | 24, | |
4f1e1a09 A |
44 | 322, |
45 | 332, | |
46 | 343, | |
47 | 347, | |
48 | 353, | |
49 | 357, | |
0f5d89e8 | 50 | 377, |
4f1e1a09 A |
51 | 378, |
52 | 389, | |
53 | 392, | |
54 | 398, | |
55 | 403, | |
56 | 407, | |
57 | 411, | |
58 | 436 | |
57a6839d A |
59 | }; |
60 | ||
61 | static const int32_t gIndexes[] = { | |
62 | 0, | |
b331163b | 63 | 2, |
2ca993e8 A |
64 | 7, |
65 | 16, | |
66 | 20, | |
67 | 24, | |
68 | 24, | |
69 | 34, | |
70 | 45, | |
71 | 49, | |
72 | 55, | |
73 | 59, | |
2ca993e8 | 74 | 79, |
f3c0d7a5 A |
75 | 80, |
76 | 91, | |
0f5d89e8 A |
77 | 94, |
78 | 100, | |
79 | 105, | |
80 | 109, | |
81 | 113, | |
82 | 138 | |
57a6839d A |
83 | }; |
84 | ||
b331163b | 85 | // Must be sorted alphabetically. |
57a6839d A |
86 | static const char * const gTypes[] = { |
87 | "acceleration", | |
88 | "angle", | |
89 | "area", | |
2ca993e8 | 90 | "concentr", |
b331163b | 91 | "consumption", |
57a6839d | 92 | "currency", |
b331163b | 93 | "digital", |
57a6839d | 94 | "duration", |
b331163b A |
95 | "electric", |
96 | "energy", | |
97 | "frequency", | |
57a6839d | 98 | "length", |
b331163b | 99 | "light", |
57a6839d | 100 | "mass", |
0f5d89e8 | 101 | "none", |
57a6839d A |
102 | "power", |
103 | "pressure", | |
104 | "speed", | |
105 | "temperature", | |
b331163b | 106 | "volume" |
57a6839d A |
107 | }; |
108 | ||
b331163b | 109 | // Must be grouped by type and sorted alphabetically within each type. |
57a6839d | 110 | static const char * const gSubTypes[] = { |
b331163b A |
111 | "g-force", |
112 | "meter-per-second-squared", | |
113 | "arc-minute", | |
57a6839d A |
114 | "arc-second", |
115 | "degree", | |
b331163b | 116 | "radian", |
2ca993e8 | 117 | "revolution", |
b331163b | 118 | "acre", |
57a6839d | 119 | "hectare", |
b331163b | 120 | "square-centimeter", |
57a6839d | 121 | "square-foot", |
b331163b | 122 | "square-inch", |
57a6839d A |
123 | "square-kilometer", |
124 | "square-meter", | |
125 | "square-mile", | |
b331163b | 126 | "square-yard", |
2ca993e8 A |
127 | "karat", |
128 | "milligram-per-deciliter", | |
129 | "millimole-per-liter", | |
130 | "part-per-million", | |
131 | "liter-per-100kilometers", | |
b331163b A |
132 | "liter-per-kilometer", |
133 | "mile-per-gallon", | |
2ca993e8 | 134 | "mile-per-gallon-imperial", |
b331163b | 135 | "ADP", |
57a6839d A |
136 | "AED", |
137 | "AFA", | |
138 | "AFN", | |
0f5d89e8 | 139 | "ALK", |
57a6839d A |
140 | "ALL", |
141 | "AMD", | |
142 | "ANG", | |
143 | "AOA", | |
0f5d89e8 | 144 | "AOK", |
57a6839d A |
145 | "AON", |
146 | "AOR", | |
147 | "ARA", | |
148 | "ARP", | |
149 | "ARS", | |
0f5d89e8 | 150 | "ARY", |
57a6839d A |
151 | "ATS", |
152 | "AUD", | |
153 | "AWG", | |
154 | "AYM", | |
155 | "AZM", | |
156 | "AZN", | |
157 | "BAD", | |
158 | "BAM", | |
159 | "BBD", | |
160 | "BDT", | |
161 | "BEC", | |
162 | "BEF", | |
163 | "BEL", | |
0f5d89e8 A |
164 | "BGJ", |
165 | "BGK", | |
57a6839d A |
166 | "BGL", |
167 | "BGN", | |
168 | "BHD", | |
169 | "BIF", | |
170 | "BMD", | |
171 | "BND", | |
172 | "BOB", | |
0f5d89e8 | 173 | "BOP", |
57a6839d | 174 | "BOV", |
0f5d89e8 | 175 | "BRB", |
57a6839d A |
176 | "BRC", |
177 | "BRE", | |
178 | "BRL", | |
179 | "BRN", | |
180 | "BRR", | |
181 | "BSD", | |
182 | "BTN", | |
0f5d89e8 | 183 | "BUK", |
57a6839d A |
184 | "BWP", |
185 | "BYB", | |
f3c0d7a5 | 186 | "BYN", |
57a6839d A |
187 | "BYR", |
188 | "BZD", | |
189 | "CAD", | |
190 | "CDF", | |
191 | "CHC", | |
192 | "CHE", | |
193 | "CHF", | |
194 | "CHW", | |
195 | "CLF", | |
196 | "CLP", | |
197 | "CNY", | |
198 | "COP", | |
199 | "COU", | |
200 | "CRC", | |
201 | "CSD", | |
0f5d89e8 | 202 | "CSJ", |
57a6839d A |
203 | "CSK", |
204 | "CUC", | |
205 | "CUP", | |
206 | "CVE", | |
207 | "CYP", | |
208 | "CZK", | |
209 | "DDM", | |
210 | "DEM", | |
211 | "DJF", | |
212 | "DKK", | |
213 | "DOP", | |
214 | "DZD", | |
215 | "ECS", | |
216 | "ECV", | |
217 | "EEK", | |
218 | "EGP", | |
219 | "ERN", | |
220 | "ESA", | |
221 | "ESB", | |
222 | "ESP", | |
223 | "ETB", | |
224 | "EUR", | |
225 | "FIM", | |
226 | "FJD", | |
227 | "FKP", | |
228 | "FRF", | |
229 | "GBP", | |
230 | "GEK", | |
231 | "GEL", | |
232 | "GHC", | |
233 | "GHP", | |
234 | "GHS", | |
235 | "GIP", | |
236 | "GMD", | |
0f5d89e8 | 237 | "GNE", |
57a6839d | 238 | "GNF", |
0f5d89e8 | 239 | "GNS", |
57a6839d A |
240 | "GQE", |
241 | "GRD", | |
242 | "GTQ", | |
0f5d89e8 | 243 | "GWE", |
57a6839d A |
244 | "GWP", |
245 | "GYD", | |
246 | "HKD", | |
247 | "HNL", | |
248 | "HRD", | |
249 | "HRK", | |
250 | "HTG", | |
251 | "HUF", | |
252 | "IDR", | |
253 | "IEP", | |
0f5d89e8 A |
254 | "ILP", |
255 | "ILR", | |
57a6839d A |
256 | "ILS", |
257 | "INR", | |
258 | "IQD", | |
259 | "IRR", | |
0f5d89e8 | 260 | "ISJ", |
57a6839d A |
261 | "ISK", |
262 | "ITL", | |
263 | "JMD", | |
264 | "JOD", | |
265 | "JPY", | |
266 | "KES", | |
267 | "KGS", | |
268 | "KHR", | |
269 | "KMF", | |
270 | "KPW", | |
271 | "KRW", | |
272 | "KWD", | |
273 | "KYD", | |
274 | "KZT", | |
0f5d89e8 | 275 | "LAJ", |
57a6839d A |
276 | "LAK", |
277 | "LBP", | |
278 | "LKR", | |
279 | "LRD", | |
280 | "LSL", | |
0f5d89e8 | 281 | "LSM", |
57a6839d A |
282 | "LTL", |
283 | "LTT", | |
284 | "LUC", | |
285 | "LUF", | |
286 | "LUL", | |
287 | "LVL", | |
288 | "LVR", | |
289 | "LYD", | |
290 | "MAD", | |
291 | "MDL", | |
292 | "MGA", | |
293 | "MGF", | |
294 | "MKD", | |
295 | "MLF", | |
296 | "MMK", | |
297 | "MNT", | |
298 | "MOP", | |
299 | "MRO", | |
0f5d89e8 | 300 | "MRU", |
57a6839d | 301 | "MTL", |
0f5d89e8 | 302 | "MTP", |
57a6839d | 303 | "MUR", |
0f5d89e8 | 304 | "MVQ", |
57a6839d A |
305 | "MVR", |
306 | "MWK", | |
307 | "MXN", | |
0f5d89e8 | 308 | "MXP", |
57a6839d A |
309 | "MXV", |
310 | "MYR", | |
0f5d89e8 | 311 | "MZE", |
57a6839d A |
312 | "MZM", |
313 | "MZN", | |
314 | "NAD", | |
315 | "NGN", | |
0f5d89e8 | 316 | "NIC", |
57a6839d A |
317 | "NIO", |
318 | "NLG", | |
319 | "NOK", | |
320 | "NPR", | |
321 | "NZD", | |
322 | "OMR", | |
323 | "PAB", | |
0f5d89e8 | 324 | "PEH", |
57a6839d A |
325 | "PEI", |
326 | "PEN", | |
327 | "PES", | |
328 | "PGK", | |
329 | "PHP", | |
330 | "PKR", | |
331 | "PLN", | |
332 | "PLZ", | |
333 | "PTE", | |
334 | "PYG", | |
335 | "QAR", | |
0f5d89e8 A |
336 | "RHD", |
337 | "ROK", | |
57a6839d A |
338 | "ROL", |
339 | "RON", | |
340 | "RSD", | |
341 | "RUB", | |
342 | "RUR", | |
343 | "RWF", | |
344 | "SAR", | |
345 | "SBD", | |
346 | "SCR", | |
347 | "SDD", | |
348 | "SDG", | |
0f5d89e8 | 349 | "SDP", |
57a6839d A |
350 | "SEK", |
351 | "SGD", | |
352 | "SHP", | |
353 | "SIT", | |
354 | "SKK", | |
355 | "SLL", | |
356 | "SOS", | |
357 | "SRD", | |
358 | "SRG", | |
359 | "SSP", | |
360 | "STD", | |
0f5d89e8 A |
361 | "STN", |
362 | "SUR", | |
57a6839d A |
363 | "SVC", |
364 | "SYP", | |
365 | "SZL", | |
366 | "THB", | |
367 | "TJR", | |
368 | "TJS", | |
369 | "TMM", | |
370 | "TMT", | |
371 | "TND", | |
372 | "TOP", | |
373 | "TPE", | |
374 | "TRL", | |
375 | "TRY", | |
376 | "TTD", | |
377 | "TWD", | |
378 | "TZS", | |
379 | "UAH", | |
380 | "UAK", | |
0f5d89e8 A |
381 | "UGS", |
382 | "UGW", | |
57a6839d A |
383 | "UGX", |
384 | "USD", | |
385 | "USN", | |
386 | "USS", | |
387 | "UYI", | |
0f5d89e8 A |
388 | "UYN", |
389 | "UYP", | |
57a6839d A |
390 | "UYU", |
391 | "UZS", | |
392 | "VEB", | |
393 | "VEF", | |
4f1e1a09 | 394 | "VES", |
0f5d89e8 | 395 | "VNC", |
57a6839d A |
396 | "VND", |
397 | "VUV", | |
398 | "WST", | |
399 | "XAF", | |
400 | "XAG", | |
401 | "XAU", | |
402 | "XBA", | |
403 | "XBB", | |
404 | "XBC", | |
405 | "XBD", | |
406 | "XCD", | |
407 | "XDR", | |
408 | "XEU", | |
409 | "XOF", | |
410 | "XPD", | |
411 | "XPF", | |
412 | "XPT", | |
413 | "XSU", | |
414 | "XTS", | |
415 | "XUA", | |
416 | "XXX", | |
417 | "YDD", | |
418 | "YER", | |
0f5d89e8 | 419 | "YUD", |
57a6839d A |
420 | "YUM", |
421 | "YUN", | |
422 | "ZAL", | |
423 | "ZAR", | |
424 | "ZMK", | |
425 | "ZMW", | |
426 | "ZRN", | |
427 | "ZRZ", | |
0f5d89e8 | 428 | "ZWC", |
57a6839d A |
429 | "ZWD", |
430 | "ZWL", | |
431 | "ZWN", | |
432 | "ZWR", | |
b331163b A |
433 | "bit", |
434 | "byte", | |
435 | "gigabit", | |
436 | "gigabyte", | |
437 | "kilobit", | |
438 | "kilobyte", | |
439 | "megabit", | |
440 | "megabyte", | |
441 | "terabit", | |
442 | "terabyte", | |
2ca993e8 | 443 | "century", |
b331163b | 444 | "day", |
57a6839d | 445 | "hour", |
b331163b | 446 | "microsecond", |
57a6839d A |
447 | "millisecond", |
448 | "minute", | |
449 | "month", | |
b331163b | 450 | "nanosecond", |
57a6839d A |
451 | "second", |
452 | "week", | |
453 | "year", | |
b331163b A |
454 | "ampere", |
455 | "milliampere", | |
456 | "ohm", | |
457 | "volt", | |
458 | "calorie", | |
459 | "foodcalorie", | |
460 | "joule", | |
461 | "kilocalorie", | |
462 | "kilojoule", | |
463 | "kilowatt-hour", | |
464 | "gigahertz", | |
465 | "hertz", | |
466 | "kilohertz", | |
467 | "megahertz", | |
468 | "astronomical-unit", | |
469 | "centimeter", | |
470 | "decimeter", | |
471 | "fathom", | |
57a6839d | 472 | "foot", |
b331163b | 473 | "furlong", |
57a6839d A |
474 | "inch", |
475 | "kilometer", | |
476 | "light-year", | |
477 | "meter", | |
b331163b | 478 | "micrometer", |
57a6839d | 479 | "mile", |
2ca993e8 | 480 | "mile-scandinavian", |
57a6839d | 481 | "millimeter", |
b331163b A |
482 | "nanometer", |
483 | "nautical-mile", | |
484 | "parsec", | |
57a6839d | 485 | "picometer", |
f3c0d7a5 | 486 | "point", |
57a6839d | 487 | "yard", |
b331163b A |
488 | "lux", |
489 | "carat", | |
490 | "gram", | |
57a6839d | 491 | "kilogram", |
b331163b A |
492 | "metric-ton", |
493 | "microgram", | |
494 | "milligram", | |
57a6839d | 495 | "ounce", |
b331163b | 496 | "ounce-troy", |
57a6839d | 497 | "pound", |
b331163b A |
498 | "stone", |
499 | "ton", | |
0f5d89e8 A |
500 | "base", |
501 | "percent", | |
502 | "permille", | |
b331163b A |
503 | "gigawatt", |
504 | "horsepower", | |
57a6839d | 505 | "kilowatt", |
b331163b A |
506 | "megawatt", |
507 | "milliwatt", | |
57a6839d | 508 | "watt", |
b331163b | 509 | "hectopascal", |
57a6839d A |
510 | "inch-hg", |
511 | "millibar", | |
b331163b A |
512 | "millimeter-of-mercury", |
513 | "pound-per-square-inch", | |
b331163b | 514 | "kilometer-per-hour", |
2ca993e8 | 515 | "knot", |
57a6839d A |
516 | "meter-per-second", |
517 | "mile-per-hour", | |
b331163b | 518 | "celsius", |
57a6839d | 519 | "fahrenheit", |
b331163b | 520 | "generic", |
2ca993e8 | 521 | "kelvin", |
b331163b A |
522 | "acre-foot", |
523 | "bushel", | |
524 | "centiliter", | |
525 | "cubic-centimeter", | |
526 | "cubic-foot", | |
527 | "cubic-inch", | |
528 | "cubic-kilometer", | |
529 | "cubic-meter", | |
57a6839d | 530 | "cubic-mile", |
b331163b A |
531 | "cubic-yard", |
532 | "cup", | |
2ca993e8 | 533 | "cup-metric", |
b331163b A |
534 | "deciliter", |
535 | "fluid-ounce", | |
536 | "gallon", | |
2ca993e8 | 537 | "gallon-imperial", |
b331163b | 538 | "hectoliter", |
57a6839d | 539 | "liter", |
b331163b A |
540 | "megaliter", |
541 | "milliliter", | |
542 | "pint", | |
2ca993e8 | 543 | "pint-metric", |
b331163b A |
544 | "quart", |
545 | "tablespoon", | |
546 | "teaspoon" | |
547 | }; | |
548 | ||
549 | // Must be sorted by first value and then second value. | |
550 | static int32_t unitPerUnitToSingleUnit[][4] = { | |
4f1e1a09 A |
551 | {364, 334, 17, 0}, |
552 | {366, 340, 17, 2}, | |
553 | {368, 334, 17, 3}, | |
554 | {368, 425, 4, 2}, | |
555 | {368, 426, 4, 3}, | |
556 | {383, 423, 3, 1}, | |
557 | {386, 11, 16, 4}, | |
558 | {428, 364, 4, 1} | |
b331163b | 559 | }; |
57a6839d | 560 | |
0f5d89e8 A |
561 | // Shortcuts to the base unit in order to make the default constructor fast |
562 | static const int32_t kBaseTypeIdx = 14; | |
563 | static const int32_t kBaseSubTypeIdx = 0; | |
564 | ||
57a6839d A |
565 | MeasureUnit *MeasureUnit::createGForce(UErrorCode &status) { |
566 | return MeasureUnit::create(0, 0, status); | |
567 | } | |
568 | ||
b331163b A |
569 | MeasureUnit *MeasureUnit::createMeterPerSecondSquared(UErrorCode &status) { |
570 | return MeasureUnit::create(0, 1, status); | |
571 | } | |
572 | ||
57a6839d A |
573 | MeasureUnit *MeasureUnit::createArcMinute(UErrorCode &status) { |
574 | return MeasureUnit::create(1, 0, status); | |
575 | } | |
576 | ||
577 | MeasureUnit *MeasureUnit::createArcSecond(UErrorCode &status) { | |
578 | return MeasureUnit::create(1, 1, status); | |
579 | } | |
580 | ||
581 | MeasureUnit *MeasureUnit::createDegree(UErrorCode &status) { | |
582 | return MeasureUnit::create(1, 2, status); | |
583 | } | |
584 | ||
b331163b A |
585 | MeasureUnit *MeasureUnit::createRadian(UErrorCode &status) { |
586 | return MeasureUnit::create(1, 3, status); | |
587 | } | |
588 | ||
2ca993e8 A |
589 | MeasureUnit *MeasureUnit::createRevolutionAngle(UErrorCode &status) { |
590 | return MeasureUnit::create(1, 4, status); | |
591 | } | |
592 | ||
57a6839d A |
593 | MeasureUnit *MeasureUnit::createAcre(UErrorCode &status) { |
594 | return MeasureUnit::create(2, 0, status); | |
595 | } | |
596 | ||
597 | MeasureUnit *MeasureUnit::createHectare(UErrorCode &status) { | |
598 | return MeasureUnit::create(2, 1, status); | |
599 | } | |
600 | ||
b331163b | 601 | MeasureUnit *MeasureUnit::createSquareCentimeter(UErrorCode &status) { |
57a6839d A |
602 | return MeasureUnit::create(2, 2, status); |
603 | } | |
604 | ||
b331163b | 605 | MeasureUnit *MeasureUnit::createSquareFoot(UErrorCode &status) { |
57a6839d A |
606 | return MeasureUnit::create(2, 3, status); |
607 | } | |
608 | ||
b331163b | 609 | MeasureUnit *MeasureUnit::createSquareInch(UErrorCode &status) { |
57a6839d A |
610 | return MeasureUnit::create(2, 4, status); |
611 | } | |
612 | ||
b331163b | 613 | MeasureUnit *MeasureUnit::createSquareKilometer(UErrorCode &status) { |
57a6839d A |
614 | return MeasureUnit::create(2, 5, status); |
615 | } | |
616 | ||
b331163b A |
617 | MeasureUnit *MeasureUnit::createSquareMeter(UErrorCode &status) { |
618 | return MeasureUnit::create(2, 6, status); | |
619 | } | |
620 | ||
621 | MeasureUnit *MeasureUnit::createSquareMile(UErrorCode &status) { | |
622 | return MeasureUnit::create(2, 7, status); | |
623 | } | |
624 | ||
625 | MeasureUnit *MeasureUnit::createSquareYard(UErrorCode &status) { | |
626 | return MeasureUnit::create(2, 8, status); | |
627 | } | |
628 | ||
2ca993e8 | 629 | MeasureUnit *MeasureUnit::createKarat(UErrorCode &status) { |
b331163b A |
630 | return MeasureUnit::create(3, 0, status); |
631 | } | |
632 | ||
2ca993e8 | 633 | MeasureUnit *MeasureUnit::createMilligramPerDeciliter(UErrorCode &status) { |
b331163b A |
634 | return MeasureUnit::create(3, 1, status); |
635 | } | |
636 | ||
2ca993e8 A |
637 | MeasureUnit *MeasureUnit::createMillimolePerLiter(UErrorCode &status) { |
638 | return MeasureUnit::create(3, 2, status); | |
639 | } | |
640 | ||
641 | MeasureUnit *MeasureUnit::createPartPerMillion(UErrorCode &status) { | |
642 | return MeasureUnit::create(3, 3, status); | |
643 | } | |
644 | ||
645 | MeasureUnit *MeasureUnit::createLiterPer100Kilometers(UErrorCode &status) { | |
646 | return MeasureUnit::create(4, 0, status); | |
647 | } | |
648 | ||
649 | MeasureUnit *MeasureUnit::createLiterPerKilometer(UErrorCode &status) { | |
650 | return MeasureUnit::create(4, 1, status); | |
651 | } | |
652 | ||
653 | MeasureUnit *MeasureUnit::createMilePerGallon(UErrorCode &status) { | |
654 | return MeasureUnit::create(4, 2, status); | |
655 | } | |
656 | ||
657 | MeasureUnit *MeasureUnit::createMilePerGallonImperial(UErrorCode &status) { | |
658 | return MeasureUnit::create(4, 3, status); | |
659 | } | |
660 | ||
b331163b | 661 | MeasureUnit *MeasureUnit::createBit(UErrorCode &status) { |
2ca993e8 | 662 | return MeasureUnit::create(6, 0, status); |
b331163b A |
663 | } |
664 | ||
665 | MeasureUnit *MeasureUnit::createByte(UErrorCode &status) { | |
2ca993e8 | 666 | return MeasureUnit::create(6, 1, status); |
b331163b A |
667 | } |
668 | ||
669 | MeasureUnit *MeasureUnit::createGigabit(UErrorCode &status) { | |
2ca993e8 | 670 | return MeasureUnit::create(6, 2, status); |
b331163b A |
671 | } |
672 | ||
673 | MeasureUnit *MeasureUnit::createGigabyte(UErrorCode &status) { | |
2ca993e8 | 674 | return MeasureUnit::create(6, 3, status); |
b331163b A |
675 | } |
676 | ||
677 | MeasureUnit *MeasureUnit::createKilobit(UErrorCode &status) { | |
2ca993e8 | 678 | return MeasureUnit::create(6, 4, status); |
b331163b A |
679 | } |
680 | ||
681 | MeasureUnit *MeasureUnit::createKilobyte(UErrorCode &status) { | |
2ca993e8 | 682 | return MeasureUnit::create(6, 5, status); |
b331163b A |
683 | } |
684 | ||
685 | MeasureUnit *MeasureUnit::createMegabit(UErrorCode &status) { | |
2ca993e8 | 686 | return MeasureUnit::create(6, 6, status); |
b331163b A |
687 | } |
688 | ||
689 | MeasureUnit *MeasureUnit::createMegabyte(UErrorCode &status) { | |
2ca993e8 | 690 | return MeasureUnit::create(6, 7, status); |
b331163b A |
691 | } |
692 | ||
693 | MeasureUnit *MeasureUnit::createTerabit(UErrorCode &status) { | |
2ca993e8 | 694 | return MeasureUnit::create(6, 8, status); |
b331163b A |
695 | } |
696 | ||
697 | MeasureUnit *MeasureUnit::createTerabyte(UErrorCode &status) { | |
2ca993e8 A |
698 | return MeasureUnit::create(6, 9, status); |
699 | } | |
700 | ||
701 | MeasureUnit *MeasureUnit::createCentury(UErrorCode &status) { | |
702 | return MeasureUnit::create(7, 0, status); | |
b331163b A |
703 | } |
704 | ||
57a6839d | 705 | MeasureUnit *MeasureUnit::createDay(UErrorCode &status) { |
2ca993e8 | 706 | return MeasureUnit::create(7, 1, status); |
57a6839d A |
707 | } |
708 | ||
709 | MeasureUnit *MeasureUnit::createHour(UErrorCode &status) { | |
2ca993e8 | 710 | return MeasureUnit::create(7, 2, status); |
b331163b A |
711 | } |
712 | ||
713 | MeasureUnit *MeasureUnit::createMicrosecond(UErrorCode &status) { | |
2ca993e8 | 714 | return MeasureUnit::create(7, 3, status); |
57a6839d A |
715 | } |
716 | ||
717 | MeasureUnit *MeasureUnit::createMillisecond(UErrorCode &status) { | |
2ca993e8 | 718 | return MeasureUnit::create(7, 4, status); |
57a6839d A |
719 | } |
720 | ||
721 | MeasureUnit *MeasureUnit::createMinute(UErrorCode &status) { | |
2ca993e8 | 722 | return MeasureUnit::create(7, 5, status); |
57a6839d A |
723 | } |
724 | ||
725 | MeasureUnit *MeasureUnit::createMonth(UErrorCode &status) { | |
2ca993e8 | 726 | return MeasureUnit::create(7, 6, status); |
b331163b A |
727 | } |
728 | ||
729 | MeasureUnit *MeasureUnit::createNanosecond(UErrorCode &status) { | |
2ca993e8 | 730 | return MeasureUnit::create(7, 7, status); |
57a6839d A |
731 | } |
732 | ||
733 | MeasureUnit *MeasureUnit::createSecond(UErrorCode &status) { | |
2ca993e8 | 734 | return MeasureUnit::create(7, 8, status); |
57a6839d A |
735 | } |
736 | ||
737 | MeasureUnit *MeasureUnit::createWeek(UErrorCode &status) { | |
2ca993e8 | 738 | return MeasureUnit::create(7, 9, status); |
57a6839d A |
739 | } |
740 | ||
741 | MeasureUnit *MeasureUnit::createYear(UErrorCode &status) { | |
2ca993e8 | 742 | return MeasureUnit::create(7, 10, status); |
b331163b A |
743 | } |
744 | ||
745 | MeasureUnit *MeasureUnit::createAmpere(UErrorCode &status) { | |
2ca993e8 | 746 | return MeasureUnit::create(8, 0, status); |
b331163b A |
747 | } |
748 | ||
749 | MeasureUnit *MeasureUnit::createMilliampere(UErrorCode &status) { | |
2ca993e8 | 750 | return MeasureUnit::create(8, 1, status); |
b331163b A |
751 | } |
752 | ||
753 | MeasureUnit *MeasureUnit::createOhm(UErrorCode &status) { | |
2ca993e8 | 754 | return MeasureUnit::create(8, 2, status); |
b331163b A |
755 | } |
756 | ||
757 | MeasureUnit *MeasureUnit::createVolt(UErrorCode &status) { | |
2ca993e8 | 758 | return MeasureUnit::create(8, 3, status); |
b331163b A |
759 | } |
760 | ||
761 | MeasureUnit *MeasureUnit::createCalorie(UErrorCode &status) { | |
2ca993e8 | 762 | return MeasureUnit::create(9, 0, status); |
b331163b A |
763 | } |
764 | ||
765 | MeasureUnit *MeasureUnit::createFoodcalorie(UErrorCode &status) { | |
2ca993e8 | 766 | return MeasureUnit::create(9, 1, status); |
b331163b A |
767 | } |
768 | ||
769 | MeasureUnit *MeasureUnit::createJoule(UErrorCode &status) { | |
2ca993e8 | 770 | return MeasureUnit::create(9, 2, status); |
b331163b A |
771 | } |
772 | ||
773 | MeasureUnit *MeasureUnit::createKilocalorie(UErrorCode &status) { | |
2ca993e8 | 774 | return MeasureUnit::create(9, 3, status); |
b331163b A |
775 | } |
776 | ||
777 | MeasureUnit *MeasureUnit::createKilojoule(UErrorCode &status) { | |
2ca993e8 | 778 | return MeasureUnit::create(9, 4, status); |
b331163b A |
779 | } |
780 | ||
781 | MeasureUnit *MeasureUnit::createKilowattHour(UErrorCode &status) { | |
2ca993e8 | 782 | return MeasureUnit::create(9, 5, status); |
b331163b A |
783 | } |
784 | ||
785 | MeasureUnit *MeasureUnit::createGigahertz(UErrorCode &status) { | |
2ca993e8 | 786 | return MeasureUnit::create(10, 0, status); |
b331163b A |
787 | } |
788 | ||
789 | MeasureUnit *MeasureUnit::createHertz(UErrorCode &status) { | |
2ca993e8 | 790 | return MeasureUnit::create(10, 1, status); |
b331163b A |
791 | } |
792 | ||
793 | MeasureUnit *MeasureUnit::createKilohertz(UErrorCode &status) { | |
2ca993e8 | 794 | return MeasureUnit::create(10, 2, status); |
b331163b A |
795 | } |
796 | ||
797 | MeasureUnit *MeasureUnit::createMegahertz(UErrorCode &status) { | |
2ca993e8 | 798 | return MeasureUnit::create(10, 3, status); |
b331163b A |
799 | } |
800 | ||
801 | MeasureUnit *MeasureUnit::createAstronomicalUnit(UErrorCode &status) { | |
2ca993e8 | 802 | return MeasureUnit::create(11, 0, status); |
57a6839d A |
803 | } |
804 | ||
805 | MeasureUnit *MeasureUnit::createCentimeter(UErrorCode &status) { | |
2ca993e8 | 806 | return MeasureUnit::create(11, 1, status); |
b331163b A |
807 | } |
808 | ||
809 | MeasureUnit *MeasureUnit::createDecimeter(UErrorCode &status) { | |
2ca993e8 | 810 | return MeasureUnit::create(11, 2, status); |
b331163b A |
811 | } |
812 | ||
813 | MeasureUnit *MeasureUnit::createFathom(UErrorCode &status) { | |
2ca993e8 | 814 | return MeasureUnit::create(11, 3, status); |
57a6839d A |
815 | } |
816 | ||
817 | MeasureUnit *MeasureUnit::createFoot(UErrorCode &status) { | |
2ca993e8 | 818 | return MeasureUnit::create(11, 4, status); |
b331163b A |
819 | } |
820 | ||
821 | MeasureUnit *MeasureUnit::createFurlong(UErrorCode &status) { | |
2ca993e8 | 822 | return MeasureUnit::create(11, 5, status); |
57a6839d A |
823 | } |
824 | ||
825 | MeasureUnit *MeasureUnit::createInch(UErrorCode &status) { | |
2ca993e8 | 826 | return MeasureUnit::create(11, 6, status); |
57a6839d A |
827 | } |
828 | ||
829 | MeasureUnit *MeasureUnit::createKilometer(UErrorCode &status) { | |
2ca993e8 | 830 | return MeasureUnit::create(11, 7, status); |
57a6839d A |
831 | } |
832 | ||
833 | MeasureUnit *MeasureUnit::createLightYear(UErrorCode &status) { | |
2ca993e8 | 834 | return MeasureUnit::create(11, 8, status); |
57a6839d A |
835 | } |
836 | ||
837 | MeasureUnit *MeasureUnit::createMeter(UErrorCode &status) { | |
2ca993e8 | 838 | return MeasureUnit::create(11, 9, status); |
b331163b A |
839 | } |
840 | ||
841 | MeasureUnit *MeasureUnit::createMicrometer(UErrorCode &status) { | |
2ca993e8 | 842 | return MeasureUnit::create(11, 10, status); |
57a6839d A |
843 | } |
844 | ||
845 | MeasureUnit *MeasureUnit::createMile(UErrorCode &status) { | |
2ca993e8 A |
846 | return MeasureUnit::create(11, 11, status); |
847 | } | |
848 | ||
849 | MeasureUnit *MeasureUnit::createMileScandinavian(UErrorCode &status) { | |
850 | return MeasureUnit::create(11, 12, status); | |
57a6839d A |
851 | } |
852 | ||
853 | MeasureUnit *MeasureUnit::createMillimeter(UErrorCode &status) { | |
2ca993e8 | 854 | return MeasureUnit::create(11, 13, status); |
b331163b A |
855 | } |
856 | ||
857 | MeasureUnit *MeasureUnit::createNanometer(UErrorCode &status) { | |
2ca993e8 | 858 | return MeasureUnit::create(11, 14, status); |
b331163b A |
859 | } |
860 | ||
861 | MeasureUnit *MeasureUnit::createNauticalMile(UErrorCode &status) { | |
2ca993e8 | 862 | return MeasureUnit::create(11, 15, status); |
b331163b A |
863 | } |
864 | ||
865 | MeasureUnit *MeasureUnit::createParsec(UErrorCode &status) { | |
2ca993e8 | 866 | return MeasureUnit::create(11, 16, status); |
57a6839d A |
867 | } |
868 | ||
869 | MeasureUnit *MeasureUnit::createPicometer(UErrorCode &status) { | |
2ca993e8 | 870 | return MeasureUnit::create(11, 17, status); |
57a6839d A |
871 | } |
872 | ||
f3c0d7a5 | 873 | MeasureUnit *MeasureUnit::createPoint(UErrorCode &status) { |
2ca993e8 | 874 | return MeasureUnit::create(11, 18, status); |
b331163b A |
875 | } |
876 | ||
f3c0d7a5 A |
877 | MeasureUnit *MeasureUnit::createYard(UErrorCode &status) { |
878 | return MeasureUnit::create(11, 19, status); | |
879 | } | |
880 | ||
b331163b | 881 | MeasureUnit *MeasureUnit::createLux(UErrorCode &status) { |
2ca993e8 | 882 | return MeasureUnit::create(12, 0, status); |
b331163b A |
883 | } |
884 | ||
885 | MeasureUnit *MeasureUnit::createCarat(UErrorCode &status) { | |
2ca993e8 | 886 | return MeasureUnit::create(13, 0, status); |
57a6839d A |
887 | } |
888 | ||
889 | MeasureUnit *MeasureUnit::createGram(UErrorCode &status) { | |
2ca993e8 | 890 | return MeasureUnit::create(13, 1, status); |
57a6839d A |
891 | } |
892 | ||
893 | MeasureUnit *MeasureUnit::createKilogram(UErrorCode &status) { | |
2ca993e8 | 894 | return MeasureUnit::create(13, 2, status); |
b331163b A |
895 | } |
896 | ||
897 | MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) { | |
2ca993e8 | 898 | return MeasureUnit::create(13, 3, status); |
b331163b A |
899 | } |
900 | ||
901 | MeasureUnit *MeasureUnit::createMicrogram(UErrorCode &status) { | |
2ca993e8 | 902 | return MeasureUnit::create(13, 4, status); |
b331163b A |
903 | } |
904 | ||
905 | MeasureUnit *MeasureUnit::createMilligram(UErrorCode &status) { | |
2ca993e8 | 906 | return MeasureUnit::create(13, 5, status); |
57a6839d A |
907 | } |
908 | ||
909 | MeasureUnit *MeasureUnit::createOunce(UErrorCode &status) { | |
2ca993e8 | 910 | return MeasureUnit::create(13, 6, status); |
b331163b A |
911 | } |
912 | ||
913 | MeasureUnit *MeasureUnit::createOunceTroy(UErrorCode &status) { | |
2ca993e8 | 914 | return MeasureUnit::create(13, 7, status); |
57a6839d A |
915 | } |
916 | ||
917 | MeasureUnit *MeasureUnit::createPound(UErrorCode &status) { | |
2ca993e8 | 918 | return MeasureUnit::create(13, 8, status); |
57a6839d A |
919 | } |
920 | ||
921 | MeasureUnit *MeasureUnit::createStone(UErrorCode &status) { | |
2ca993e8 | 922 | return MeasureUnit::create(13, 9, status); |
b331163b A |
923 | } |
924 | ||
925 | MeasureUnit *MeasureUnit::createTon(UErrorCode &status) { | |
2ca993e8 | 926 | return MeasureUnit::create(13, 10, status); |
b331163b A |
927 | } |
928 | ||
929 | MeasureUnit *MeasureUnit::createGigawatt(UErrorCode &status) { | |
0f5d89e8 | 930 | return MeasureUnit::create(15, 0, status); |
57a6839d A |
931 | } |
932 | ||
933 | MeasureUnit *MeasureUnit::createHorsepower(UErrorCode &status) { | |
0f5d89e8 | 934 | return MeasureUnit::create(15, 1, status); |
57a6839d A |
935 | } |
936 | ||
937 | MeasureUnit *MeasureUnit::createKilowatt(UErrorCode &status) { | |
0f5d89e8 | 938 | return MeasureUnit::create(15, 2, status); |
b331163b A |
939 | } |
940 | ||
941 | MeasureUnit *MeasureUnit::createMegawatt(UErrorCode &status) { | |
0f5d89e8 | 942 | return MeasureUnit::create(15, 3, status); |
b331163b A |
943 | } |
944 | ||
945 | MeasureUnit *MeasureUnit::createMilliwatt(UErrorCode &status) { | |
0f5d89e8 | 946 | return MeasureUnit::create(15, 4, status); |
57a6839d A |
947 | } |
948 | ||
949 | MeasureUnit *MeasureUnit::createWatt(UErrorCode &status) { | |
0f5d89e8 | 950 | return MeasureUnit::create(15, 5, status); |
57a6839d A |
951 | } |
952 | ||
953 | MeasureUnit *MeasureUnit::createHectopascal(UErrorCode &status) { | |
0f5d89e8 | 954 | return MeasureUnit::create(16, 0, status); |
57a6839d A |
955 | } |
956 | ||
957 | MeasureUnit *MeasureUnit::createInchHg(UErrorCode &status) { | |
0f5d89e8 | 958 | return MeasureUnit::create(16, 1, status); |
57a6839d A |
959 | } |
960 | ||
961 | MeasureUnit *MeasureUnit::createMillibar(UErrorCode &status) { | |
0f5d89e8 | 962 | return MeasureUnit::create(16, 2, status); |
b331163b A |
963 | } |
964 | ||
965 | MeasureUnit *MeasureUnit::createMillimeterOfMercury(UErrorCode &status) { | |
0f5d89e8 | 966 | return MeasureUnit::create(16, 3, status); |
b331163b A |
967 | } |
968 | ||
969 | MeasureUnit *MeasureUnit::createPoundPerSquareInch(UErrorCode &status) { | |
0f5d89e8 | 970 | return MeasureUnit::create(16, 4, status); |
57a6839d A |
971 | } |
972 | ||
973 | MeasureUnit *MeasureUnit::createKilometerPerHour(UErrorCode &status) { | |
0f5d89e8 | 974 | return MeasureUnit::create(17, 0, status); |
57a6839d A |
975 | } |
976 | ||
2ca993e8 | 977 | MeasureUnit *MeasureUnit::createKnot(UErrorCode &status) { |
0f5d89e8 | 978 | return MeasureUnit::create(17, 1, status); |
57a6839d A |
979 | } |
980 | ||
2ca993e8 | 981 | MeasureUnit *MeasureUnit::createMeterPerSecond(UErrorCode &status) { |
0f5d89e8 | 982 | return MeasureUnit::create(17, 2, status); |
57a6839d A |
983 | } |
984 | ||
2ca993e8 | 985 | MeasureUnit *MeasureUnit::createMilePerHour(UErrorCode &status) { |
0f5d89e8 | 986 | return MeasureUnit::create(17, 3, status); |
2ca993e8 A |
987 | } |
988 | ||
57a6839d | 989 | MeasureUnit *MeasureUnit::createCelsius(UErrorCode &status) { |
0f5d89e8 | 990 | return MeasureUnit::create(18, 0, status); |
57a6839d A |
991 | } |
992 | ||
993 | MeasureUnit *MeasureUnit::createFahrenheit(UErrorCode &status) { | |
0f5d89e8 | 994 | return MeasureUnit::create(18, 1, status); |
b331163b A |
995 | } |
996 | ||
2ca993e8 | 997 | MeasureUnit *MeasureUnit::createGenericTemperature(UErrorCode &status) { |
0f5d89e8 | 998 | return MeasureUnit::create(18, 2, status); |
b331163b A |
999 | } |
1000 | ||
2ca993e8 | 1001 | MeasureUnit *MeasureUnit::createKelvin(UErrorCode &status) { |
0f5d89e8 | 1002 | return MeasureUnit::create(18, 3, status); |
b331163b A |
1003 | } |
1004 | ||
1005 | MeasureUnit *MeasureUnit::createAcreFoot(UErrorCode &status) { | |
0f5d89e8 | 1006 | return MeasureUnit::create(19, 0, status); |
b331163b A |
1007 | } |
1008 | ||
1009 | MeasureUnit *MeasureUnit::createBushel(UErrorCode &status) { | |
0f5d89e8 | 1010 | return MeasureUnit::create(19, 1, status); |
b331163b A |
1011 | } |
1012 | ||
1013 | MeasureUnit *MeasureUnit::createCentiliter(UErrorCode &status) { | |
0f5d89e8 | 1014 | return MeasureUnit::create(19, 2, status); |
b331163b A |
1015 | } |
1016 | ||
1017 | MeasureUnit *MeasureUnit::createCubicCentimeter(UErrorCode &status) { | |
0f5d89e8 | 1018 | return MeasureUnit::create(19, 3, status); |
b331163b A |
1019 | } |
1020 | ||
1021 | MeasureUnit *MeasureUnit::createCubicFoot(UErrorCode &status) { | |
0f5d89e8 | 1022 | return MeasureUnit::create(19, 4, status); |
b331163b A |
1023 | } |
1024 | ||
1025 | MeasureUnit *MeasureUnit::createCubicInch(UErrorCode &status) { | |
0f5d89e8 | 1026 | return MeasureUnit::create(19, 5, status); |
57a6839d A |
1027 | } |
1028 | ||
1029 | MeasureUnit *MeasureUnit::createCubicKilometer(UErrorCode &status) { | |
0f5d89e8 | 1030 | return MeasureUnit::create(19, 6, status); |
b331163b A |
1031 | } |
1032 | ||
1033 | MeasureUnit *MeasureUnit::createCubicMeter(UErrorCode &status) { | |
0f5d89e8 | 1034 | return MeasureUnit::create(19, 7, status); |
57a6839d A |
1035 | } |
1036 | ||
1037 | MeasureUnit *MeasureUnit::createCubicMile(UErrorCode &status) { | |
0f5d89e8 | 1038 | return MeasureUnit::create(19, 8, status); |
b331163b A |
1039 | } |
1040 | ||
1041 | MeasureUnit *MeasureUnit::createCubicYard(UErrorCode &status) { | |
0f5d89e8 | 1042 | return MeasureUnit::create(19, 9, status); |
b331163b A |
1043 | } |
1044 | ||
1045 | MeasureUnit *MeasureUnit::createCup(UErrorCode &status) { | |
0f5d89e8 | 1046 | return MeasureUnit::create(19, 10, status); |
b331163b A |
1047 | } |
1048 | ||
2ca993e8 | 1049 | MeasureUnit *MeasureUnit::createCupMetric(UErrorCode &status) { |
0f5d89e8 | 1050 | return MeasureUnit::create(19, 11, status); |
b331163b A |
1051 | } |
1052 | ||
2ca993e8 | 1053 | MeasureUnit *MeasureUnit::createDeciliter(UErrorCode &status) { |
0f5d89e8 | 1054 | return MeasureUnit::create(19, 12, status); |
b331163b A |
1055 | } |
1056 | ||
2ca993e8 | 1057 | MeasureUnit *MeasureUnit::createFluidOunce(UErrorCode &status) { |
0f5d89e8 | 1058 | return MeasureUnit::create(19, 13, status); |
b331163b A |
1059 | } |
1060 | ||
2ca993e8 | 1061 | MeasureUnit *MeasureUnit::createGallon(UErrorCode &status) { |
0f5d89e8 | 1062 | return MeasureUnit::create(19, 14, status); |
57a6839d A |
1063 | } |
1064 | ||
2ca993e8 | 1065 | MeasureUnit *MeasureUnit::createGallonImperial(UErrorCode &status) { |
0f5d89e8 | 1066 | return MeasureUnit::create(19, 15, status); |
57a6839d A |
1067 | } |
1068 | ||
2ca993e8 | 1069 | MeasureUnit *MeasureUnit::createHectoliter(UErrorCode &status) { |
0f5d89e8 | 1070 | return MeasureUnit::create(19, 16, status); |
57a6839d A |
1071 | } |
1072 | ||
2ca993e8 | 1073 | MeasureUnit *MeasureUnit::createLiter(UErrorCode &status) { |
0f5d89e8 | 1074 | return MeasureUnit::create(19, 17, status); |
57a6839d A |
1075 | } |
1076 | ||
2ca993e8 | 1077 | MeasureUnit *MeasureUnit::createMegaliter(UErrorCode &status) { |
0f5d89e8 | 1078 | return MeasureUnit::create(19, 18, status); |
57a6839d A |
1079 | } |
1080 | ||
2ca993e8 | 1081 | MeasureUnit *MeasureUnit::createMilliliter(UErrorCode &status) { |
0f5d89e8 | 1082 | return MeasureUnit::create(19, 19, status); |
57a6839d A |
1083 | } |
1084 | ||
2ca993e8 | 1085 | MeasureUnit *MeasureUnit::createPint(UErrorCode &status) { |
0f5d89e8 | 1086 | return MeasureUnit::create(19, 20, status); |
b331163b A |
1087 | } |
1088 | ||
2ca993e8 | 1089 | MeasureUnit *MeasureUnit::createPintMetric(UErrorCode &status) { |
0f5d89e8 | 1090 | return MeasureUnit::create(19, 21, status); |
57a6839d A |
1091 | } |
1092 | ||
2ca993e8 | 1093 | MeasureUnit *MeasureUnit::createQuart(UErrorCode &status) { |
0f5d89e8 | 1094 | return MeasureUnit::create(19, 22, status); |
2ca993e8 A |
1095 | } |
1096 | ||
1097 | MeasureUnit *MeasureUnit::createTablespoon(UErrorCode &status) { | |
0f5d89e8 | 1098 | return MeasureUnit::create(19, 23, status); |
2ca993e8 A |
1099 | } |
1100 | ||
1101 | MeasureUnit *MeasureUnit::createTeaspoon(UErrorCode &status) { | |
0f5d89e8 | 1102 | return MeasureUnit::create(19, 24, status); |
2ca993e8 A |
1103 | } |
1104 | ||
b331163b | 1105 | // End generated code |
57a6839d A |
1106 | |
1107 | static int32_t binarySearch( | |
1108 | const char * const * array, int32_t start, int32_t end, const char * key) { | |
1109 | while (start < end) { | |
1110 | int32_t mid = (start + end) / 2; | |
1111 | int32_t cmp = uprv_strcmp(array[mid], key); | |
1112 | if (cmp < 0) { | |
1113 | start = mid + 1; | |
1114 | continue; | |
1115 | } | |
1116 | if (cmp == 0) { | |
1117 | return mid; | |
1118 | } | |
1119 | end = mid; | |
1120 | } | |
1121 | return -1; | |
1122 | } | |
0f5d89e8 A |
1123 | |
1124 | MeasureUnit::MeasureUnit() { | |
1125 | fCurrency[0] = 0; | |
1126 | fTypeId = kBaseTypeIdx; | |
1127 | fSubTypeId = kBaseSubTypeIdx; | |
1128 | } | |
1129 | ||
57a6839d A |
1130 | MeasureUnit::MeasureUnit(const MeasureUnit &other) |
1131 | : fTypeId(other.fTypeId), fSubTypeId(other.fSubTypeId) { | |
1132 | uprv_strcpy(fCurrency, other.fCurrency); | |
1133 | } | |
1134 | ||
1135 | MeasureUnit &MeasureUnit::operator=(const MeasureUnit &other) { | |
1136 | if (this == &other) { | |
1137 | return *this; | |
1138 | } | |
1139 | fTypeId = other.fTypeId; | |
1140 | fSubTypeId = other.fSubTypeId; | |
1141 | uprv_strcpy(fCurrency, other.fCurrency); | |
1142 | return *this; | |
1143 | } | |
1144 | ||
1145 | UObject *MeasureUnit::clone() const { | |
1146 | return new MeasureUnit(*this); | |
1147 | } | |
1148 | ||
1149 | MeasureUnit::~MeasureUnit() { | |
1150 | } | |
1151 | ||
1152 | const char *MeasureUnit::getType() const { | |
1153 | return gTypes[fTypeId]; | |
1154 | } | |
1155 | ||
1156 | const char *MeasureUnit::getSubtype() const { | |
1157 | return fCurrency[0] == 0 ? gSubTypes[getOffset()] : fCurrency; | |
1158 | } | |
1159 | ||
1160 | UBool MeasureUnit::operator==(const UObject& other) const { | |
1161 | if (this == &other) { // Same object, equal | |
1162 | return TRUE; | |
1163 | } | |
1164 | if (typeid(*this) != typeid(other)) { // Different types, not equal | |
1165 | return FALSE; | |
1166 | } | |
1167 | const MeasureUnit &rhs = static_cast<const MeasureUnit&>(other); | |
1168 | return ( | |
1169 | fTypeId == rhs.fTypeId | |
1170 | && fSubTypeId == rhs.fSubTypeId | |
1171 | && uprv_strcmp(fCurrency, rhs.fCurrency) == 0); | |
1172 | } | |
1173 | ||
1174 | int32_t MeasureUnit::getIndex() const { | |
1175 | return gIndexes[fTypeId] + fSubTypeId; | |
1176 | } | |
1177 | ||
1178 | int32_t MeasureUnit::getAvailable( | |
1179 | MeasureUnit *dest, | |
1180 | int32_t destCapacity, | |
1181 | UErrorCode &errorCode) { | |
1182 | if (U_FAILURE(errorCode)) { | |
1183 | return 0; | |
1184 | } | |
b331163b | 1185 | if (destCapacity < UPRV_LENGTHOF(gSubTypes)) { |
57a6839d | 1186 | errorCode = U_BUFFER_OVERFLOW_ERROR; |
b331163b | 1187 | return UPRV_LENGTHOF(gSubTypes); |
57a6839d A |
1188 | } |
1189 | int32_t idx = 0; | |
b331163b | 1190 | for (int32_t typeIdx = 0; typeIdx < UPRV_LENGTHOF(gTypes); ++typeIdx) { |
57a6839d A |
1191 | int32_t len = gOffsets[typeIdx + 1] - gOffsets[typeIdx]; |
1192 | for (int32_t subTypeIdx = 0; subTypeIdx < len; ++subTypeIdx) { | |
1193 | dest[idx].setTo(typeIdx, subTypeIdx); | |
1194 | ++idx; | |
1195 | } | |
1196 | } | |
b331163b A |
1197 | U_ASSERT(idx == UPRV_LENGTHOF(gSubTypes)); |
1198 | return UPRV_LENGTHOF(gSubTypes); | |
57a6839d A |
1199 | } |
1200 | ||
1201 | int32_t MeasureUnit::getAvailable( | |
1202 | const char *type, | |
1203 | MeasureUnit *dest, | |
1204 | int32_t destCapacity, | |
1205 | UErrorCode &errorCode) { | |
1206 | if (U_FAILURE(errorCode)) { | |
1207 | return 0; | |
1208 | } | |
b331163b | 1209 | int32_t typeIdx = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type); |
57a6839d | 1210 | if (typeIdx == -1) { |
b331163b | 1211 | return 0; |
57a6839d A |
1212 | } |
1213 | int32_t len = gOffsets[typeIdx + 1] - gOffsets[typeIdx]; | |
1214 | if (destCapacity < len) { | |
1215 | errorCode = U_BUFFER_OVERFLOW_ERROR; | |
1216 | return len; | |
1217 | } | |
1218 | for (int subTypeIdx = 0; subTypeIdx < len; ++subTypeIdx) { | |
1219 | dest[subTypeIdx].setTo(typeIdx, subTypeIdx); | |
1220 | } | |
1221 | return len; | |
1222 | } | |
1223 | ||
1224 | StringEnumeration* MeasureUnit::getAvailableTypes(UErrorCode &errorCode) { | |
1225 | UEnumeration *uenum = uenum_openCharStringsEnumeration( | |
b331163b | 1226 | gTypes, UPRV_LENGTHOF(gTypes), &errorCode); |
57a6839d A |
1227 | if (U_FAILURE(errorCode)) { |
1228 | uenum_close(uenum); | |
1229 | return NULL; | |
1230 | } | |
1231 | StringEnumeration *result = new UStringEnumeration(uenum); | |
1232 | if (result == NULL) { | |
1233 | errorCode = U_MEMORY_ALLOCATION_ERROR; | |
1234 | uenum_close(uenum); | |
1235 | return NULL; | |
1236 | } | |
1237 | return result; | |
1238 | } | |
1239 | ||
1240 | int32_t MeasureUnit::getIndexCount() { | |
b331163b A |
1241 | return gIndexes[UPRV_LENGTHOF(gIndexes) - 1]; |
1242 | } | |
1243 | ||
2ca993e8 A |
1244 | int32_t MeasureUnit::internalGetIndexForTypeAndSubtype(const char *type, const char *subtype) { |
1245 | int32_t t = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type); | |
1246 | if (t < 0) { | |
1247 | return t; | |
1248 | } | |
1249 | int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype); | |
1250 | if (st < 0) { | |
1251 | return st; | |
1252 | } | |
1253 | return gIndexes[t] + st - gOffsets[t]; | |
1254 | } | |
1255 | ||
0f5d89e8 A |
1256 | MeasureUnit MeasureUnit::resolveUnitPerUnit( |
1257 | const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved) { | |
b331163b A |
1258 | int32_t unitOffset = unit.getOffset(); |
1259 | int32_t perUnitOffset = perUnit.getOffset(); | |
1260 | ||
1261 | // binary search for (unitOffset, perUnitOffset) | |
1262 | int32_t start = 0; | |
1263 | int32_t end = UPRV_LENGTHOF(unitPerUnitToSingleUnit); | |
1264 | while (start < end) { | |
1265 | int32_t mid = (start + end) / 2; | |
1266 | int32_t *midRow = unitPerUnitToSingleUnit[mid]; | |
1267 | if (unitOffset < midRow[0]) { | |
1268 | end = mid; | |
1269 | } else if (unitOffset > midRow[0]) { | |
1270 | start = mid + 1; | |
1271 | } else if (perUnitOffset < midRow[1]) { | |
1272 | end = mid; | |
1273 | } else if (perUnitOffset > midRow[1]) { | |
1274 | start = mid + 1; | |
1275 | } else { | |
1276 | // We found a resolution for our unit / per-unit combo | |
1277 | // return it. | |
0f5d89e8 A |
1278 | *isResolved = true; |
1279 | return MeasureUnit(midRow[2], midRow[3]); | |
b331163b A |
1280 | } |
1281 | } | |
0f5d89e8 A |
1282 | |
1283 | *isResolved = false; | |
1284 | return MeasureUnit(); | |
57a6839d A |
1285 | } |
1286 | ||
1287 | MeasureUnit *MeasureUnit::create(int typeId, int subTypeId, UErrorCode &status) { | |
1288 | if (U_FAILURE(status)) { | |
1289 | return NULL; | |
1290 | } | |
1291 | MeasureUnit *result = new MeasureUnit(typeId, subTypeId); | |
1292 | if (result == NULL) { | |
1293 | status = U_MEMORY_ALLOCATION_ERROR; | |
1294 | } | |
1295 | return result; | |
1296 | } | |
1297 | ||
1298 | void MeasureUnit::initTime(const char *timeId) { | |
b331163b | 1299 | int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "duration"); |
57a6839d A |
1300 | U_ASSERT(result != -1); |
1301 | fTypeId = result; | |
1302 | result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], timeId); | |
1303 | U_ASSERT(result != -1); | |
1304 | fSubTypeId = result - gOffsets[fTypeId]; | |
1305 | } | |
1306 | ||
1307 | void MeasureUnit::initCurrency(const char *isoCurrency) { | |
b331163b | 1308 | int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "currency"); |
57a6839d A |
1309 | U_ASSERT(result != -1); |
1310 | fTypeId = result; | |
1311 | result = binarySearch( | |
1312 | gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], isoCurrency); | |
1313 | if (result != -1) { | |
1314 | fSubTypeId = result - gOffsets[fTypeId]; | |
1315 | } else { | |
b331163b | 1316 | uprv_strncpy(fCurrency, isoCurrency, UPRV_LENGTHOF(fCurrency)); |
2ca993e8 | 1317 | fCurrency[3] = 0; |
57a6839d A |
1318 | } |
1319 | } | |
1320 | ||
0f5d89e8 A |
1321 | void MeasureUnit::initNoUnit(const char *subtype) { |
1322 | int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "none"); | |
1323 | U_ASSERT(result != -1); | |
1324 | fTypeId = result; | |
1325 | result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], subtype); | |
1326 | U_ASSERT(result != -1); | |
1327 | fSubTypeId = result - gOffsets[fTypeId]; | |
1328 | } | |
1329 | ||
57a6839d A |
1330 | void MeasureUnit::setTo(int32_t typeId, int32_t subTypeId) { |
1331 | fTypeId = typeId; | |
1332 | fSubTypeId = subTypeId; | |
1333 | fCurrency[0] = 0; | |
1334 | } | |
1335 | ||
1336 | int32_t MeasureUnit::getOffset() const { | |
1337 | return gOffsets[fTypeId] + fSubTypeId; | |
1338 | } | |
1339 | ||
1340 | U_NAMESPACE_END | |
1341 | ||
1342 | #endif /* !UNCONFIG_NO_FORMATTING */ |