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