2 **********************************************************************
3 * Copyright (c) 2004-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: April 26, 2004
9 **********************************************************************
11 #include "utypeinfo.h" // for 'typeid' to work
13 #include "unicode/measunit.h"
15 #if !UCONFIG_NO_FORMATTING
17 #include "unicode/uenum.h"
24 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureUnit
)
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
32 // Start generated code
34 static const int32_t gOffsets
[] = {
57 static const int32_t gIndexes
[] = {
80 // Must be sorted alphabetically.
81 static const char * const gTypes
[] = {
103 // Must be grouped by type and sorted alphabetically within each type.
104 static const char * const gSubTypes
[] = {
106 "meter-per-second-squared",
120 "liter-per-kilometer",
455 "millimeter-of-mercury",
456 "pound-per-square-inch",
458 "kilometer-per-hour",
489 // Must be sorted by first value and then second value.
490 static int32_t unitPerUnitToSingleUnit
[][4] = {
499 MeasureUnit
*MeasureUnit::createGForce(UErrorCode
&status
) {
500 return MeasureUnit::create(0, 0, status
);
503 MeasureUnit
*MeasureUnit::createMeterPerSecondSquared(UErrorCode
&status
) {
504 return MeasureUnit::create(0, 1, status
);
507 MeasureUnit
*MeasureUnit::createArcMinute(UErrorCode
&status
) {
508 return MeasureUnit::create(1, 0, status
);
511 MeasureUnit
*MeasureUnit::createArcSecond(UErrorCode
&status
) {
512 return MeasureUnit::create(1, 1, status
);
515 MeasureUnit
*MeasureUnit::createDegree(UErrorCode
&status
) {
516 return MeasureUnit::create(1, 2, status
);
519 MeasureUnit
*MeasureUnit::createRadian(UErrorCode
&status
) {
520 return MeasureUnit::create(1, 3, status
);
523 MeasureUnit
*MeasureUnit::createAcre(UErrorCode
&status
) {
524 return MeasureUnit::create(2, 0, status
);
527 MeasureUnit
*MeasureUnit::createHectare(UErrorCode
&status
) {
528 return MeasureUnit::create(2, 1, status
);
531 MeasureUnit
*MeasureUnit::createSquareCentimeter(UErrorCode
&status
) {
532 return MeasureUnit::create(2, 2, status
);
535 MeasureUnit
*MeasureUnit::createSquareFoot(UErrorCode
&status
) {
536 return MeasureUnit::create(2, 3, status
);
539 MeasureUnit
*MeasureUnit::createSquareInch(UErrorCode
&status
) {
540 return MeasureUnit::create(2, 4, status
);
543 MeasureUnit
*MeasureUnit::createSquareKilometer(UErrorCode
&status
) {
544 return MeasureUnit::create(2, 5, status
);
547 MeasureUnit
*MeasureUnit::createSquareMeter(UErrorCode
&status
) {
548 return MeasureUnit::create(2, 6, status
);
551 MeasureUnit
*MeasureUnit::createSquareMile(UErrorCode
&status
) {
552 return MeasureUnit::create(2, 7, status
);
555 MeasureUnit
*MeasureUnit::createSquareYard(UErrorCode
&status
) {
556 return MeasureUnit::create(2, 8, status
);
559 MeasureUnit
*MeasureUnit::createLiterPerKilometer(UErrorCode
&status
) {
560 return MeasureUnit::create(3, 0, status
);
563 MeasureUnit
*MeasureUnit::createMilePerGallon(UErrorCode
&status
) {
564 return MeasureUnit::create(3, 1, status
);
567 MeasureUnit
*MeasureUnit::createBit(UErrorCode
&status
) {
568 return MeasureUnit::create(5, 0, status
);
571 MeasureUnit
*MeasureUnit::createByte(UErrorCode
&status
) {
572 return MeasureUnit::create(5, 1, status
);
575 MeasureUnit
*MeasureUnit::createGigabit(UErrorCode
&status
) {
576 return MeasureUnit::create(5, 2, status
);
579 MeasureUnit
*MeasureUnit::createGigabyte(UErrorCode
&status
) {
580 return MeasureUnit::create(5, 3, status
);
583 MeasureUnit
*MeasureUnit::createKilobit(UErrorCode
&status
) {
584 return MeasureUnit::create(5, 4, status
);
587 MeasureUnit
*MeasureUnit::createKilobyte(UErrorCode
&status
) {
588 return MeasureUnit::create(5, 5, status
);
591 MeasureUnit
*MeasureUnit::createMegabit(UErrorCode
&status
) {
592 return MeasureUnit::create(5, 6, status
);
595 MeasureUnit
*MeasureUnit::createMegabyte(UErrorCode
&status
) {
596 return MeasureUnit::create(5, 7, status
);
599 MeasureUnit
*MeasureUnit::createTerabit(UErrorCode
&status
) {
600 return MeasureUnit::create(5, 8, status
);
603 MeasureUnit
*MeasureUnit::createTerabyte(UErrorCode
&status
) {
604 return MeasureUnit::create(5, 9, status
);
607 MeasureUnit
*MeasureUnit::createDay(UErrorCode
&status
) {
608 return MeasureUnit::create(6, 0, status
);
611 MeasureUnit
*MeasureUnit::createHour(UErrorCode
&status
) {
612 return MeasureUnit::create(6, 1, status
);
615 MeasureUnit
*MeasureUnit::createMicrosecond(UErrorCode
&status
) {
616 return MeasureUnit::create(6, 2, status
);
619 MeasureUnit
*MeasureUnit::createMillisecond(UErrorCode
&status
) {
620 return MeasureUnit::create(6, 3, status
);
623 MeasureUnit
*MeasureUnit::createMinute(UErrorCode
&status
) {
624 return MeasureUnit::create(6, 4, status
);
627 MeasureUnit
*MeasureUnit::createMonth(UErrorCode
&status
) {
628 return MeasureUnit::create(6, 5, status
);
631 MeasureUnit
*MeasureUnit::createNanosecond(UErrorCode
&status
) {
632 return MeasureUnit::create(6, 6, status
);
635 MeasureUnit
*MeasureUnit::createSecond(UErrorCode
&status
) {
636 return MeasureUnit::create(6, 7, status
);
639 MeasureUnit
*MeasureUnit::createWeek(UErrorCode
&status
) {
640 return MeasureUnit::create(6, 8, status
);
643 MeasureUnit
*MeasureUnit::createYear(UErrorCode
&status
) {
644 return MeasureUnit::create(6, 9, status
);
647 MeasureUnit
*MeasureUnit::createAmpere(UErrorCode
&status
) {
648 return MeasureUnit::create(7, 0, status
);
651 MeasureUnit
*MeasureUnit::createMilliampere(UErrorCode
&status
) {
652 return MeasureUnit::create(7, 1, status
);
655 MeasureUnit
*MeasureUnit::createOhm(UErrorCode
&status
) {
656 return MeasureUnit::create(7, 2, status
);
659 MeasureUnit
*MeasureUnit::createVolt(UErrorCode
&status
) {
660 return MeasureUnit::create(7, 3, status
);
663 MeasureUnit
*MeasureUnit::createCalorie(UErrorCode
&status
) {
664 return MeasureUnit::create(8, 0, status
);
667 MeasureUnit
*MeasureUnit::createFoodcalorie(UErrorCode
&status
) {
668 return MeasureUnit::create(8, 1, status
);
671 MeasureUnit
*MeasureUnit::createJoule(UErrorCode
&status
) {
672 return MeasureUnit::create(8, 2, status
);
675 MeasureUnit
*MeasureUnit::createKilocalorie(UErrorCode
&status
) {
676 return MeasureUnit::create(8, 3, status
);
679 MeasureUnit
*MeasureUnit::createKilojoule(UErrorCode
&status
) {
680 return MeasureUnit::create(8, 4, status
);
683 MeasureUnit
*MeasureUnit::createKilowattHour(UErrorCode
&status
) {
684 return MeasureUnit::create(8, 5, status
);
687 MeasureUnit
*MeasureUnit::createGigahertz(UErrorCode
&status
) {
688 return MeasureUnit::create(9, 0, status
);
691 MeasureUnit
*MeasureUnit::createHertz(UErrorCode
&status
) {
692 return MeasureUnit::create(9, 1, status
);
695 MeasureUnit
*MeasureUnit::createKilohertz(UErrorCode
&status
) {
696 return MeasureUnit::create(9, 2, status
);
699 MeasureUnit
*MeasureUnit::createMegahertz(UErrorCode
&status
) {
700 return MeasureUnit::create(9, 3, status
);
703 MeasureUnit
*MeasureUnit::createAstronomicalUnit(UErrorCode
&status
) {
704 return MeasureUnit::create(10, 0, status
);
707 MeasureUnit
*MeasureUnit::createCentimeter(UErrorCode
&status
) {
708 return MeasureUnit::create(10, 1, status
);
711 MeasureUnit
*MeasureUnit::createDecimeter(UErrorCode
&status
) {
712 return MeasureUnit::create(10, 2, status
);
715 MeasureUnit
*MeasureUnit::createFathom(UErrorCode
&status
) {
716 return MeasureUnit::create(10, 3, status
);
719 MeasureUnit
*MeasureUnit::createFoot(UErrorCode
&status
) {
720 return MeasureUnit::create(10, 4, status
);
723 MeasureUnit
*MeasureUnit::createFurlong(UErrorCode
&status
) {
724 return MeasureUnit::create(10, 5, status
);
727 MeasureUnit
*MeasureUnit::createInch(UErrorCode
&status
) {
728 return MeasureUnit::create(10, 6, status
);
731 MeasureUnit
*MeasureUnit::createKilometer(UErrorCode
&status
) {
732 return MeasureUnit::create(10, 7, status
);
735 MeasureUnit
*MeasureUnit::createLightYear(UErrorCode
&status
) {
736 return MeasureUnit::create(10, 8, status
);
739 MeasureUnit
*MeasureUnit::createMeter(UErrorCode
&status
) {
740 return MeasureUnit::create(10, 9, status
);
743 MeasureUnit
*MeasureUnit::createMicrometer(UErrorCode
&status
) {
744 return MeasureUnit::create(10, 10, status
);
747 MeasureUnit
*MeasureUnit::createMile(UErrorCode
&status
) {
748 return MeasureUnit::create(10, 11, status
);
751 MeasureUnit
*MeasureUnit::createMillimeter(UErrorCode
&status
) {
752 return MeasureUnit::create(10, 12, status
);
755 MeasureUnit
*MeasureUnit::createNanometer(UErrorCode
&status
) {
756 return MeasureUnit::create(10, 13, status
);
759 MeasureUnit
*MeasureUnit::createNauticalMile(UErrorCode
&status
) {
760 return MeasureUnit::create(10, 14, status
);
763 MeasureUnit
*MeasureUnit::createParsec(UErrorCode
&status
) {
764 return MeasureUnit::create(10, 15, status
);
767 MeasureUnit
*MeasureUnit::createPicometer(UErrorCode
&status
) {
768 return MeasureUnit::create(10, 16, status
);
771 MeasureUnit
*MeasureUnit::createYard(UErrorCode
&status
) {
772 return MeasureUnit::create(10, 17, status
);
775 MeasureUnit
*MeasureUnit::createLux(UErrorCode
&status
) {
776 return MeasureUnit::create(11, 0, status
);
779 MeasureUnit
*MeasureUnit::createCarat(UErrorCode
&status
) {
780 return MeasureUnit::create(12, 0, status
);
783 MeasureUnit
*MeasureUnit::createGram(UErrorCode
&status
) {
784 return MeasureUnit::create(12, 1, status
);
787 MeasureUnit
*MeasureUnit::createKilogram(UErrorCode
&status
) {
788 return MeasureUnit::create(12, 2, status
);
791 MeasureUnit
*MeasureUnit::createMetricTon(UErrorCode
&status
) {
792 return MeasureUnit::create(12, 3, status
);
795 MeasureUnit
*MeasureUnit::createMicrogram(UErrorCode
&status
) {
796 return MeasureUnit::create(12, 4, status
);
799 MeasureUnit
*MeasureUnit::createMilligram(UErrorCode
&status
) {
800 return MeasureUnit::create(12, 5, status
);
803 MeasureUnit
*MeasureUnit::createOunce(UErrorCode
&status
) {
804 return MeasureUnit::create(12, 6, status
);
807 MeasureUnit
*MeasureUnit::createOunceTroy(UErrorCode
&status
) {
808 return MeasureUnit::create(12, 7, status
);
811 MeasureUnit
*MeasureUnit::createPound(UErrorCode
&status
) {
812 return MeasureUnit::create(12, 8, status
);
815 MeasureUnit
*MeasureUnit::createStone(UErrorCode
&status
) {
816 return MeasureUnit::create(12, 9, status
);
819 MeasureUnit
*MeasureUnit::createTon(UErrorCode
&status
) {
820 return MeasureUnit::create(12, 10, status
);
823 MeasureUnit
*MeasureUnit::createGigawatt(UErrorCode
&status
) {
824 return MeasureUnit::create(13, 0, status
);
827 MeasureUnit
*MeasureUnit::createHorsepower(UErrorCode
&status
) {
828 return MeasureUnit::create(13, 1, status
);
831 MeasureUnit
*MeasureUnit::createKilowatt(UErrorCode
&status
) {
832 return MeasureUnit::create(13, 2, status
);
835 MeasureUnit
*MeasureUnit::createMegawatt(UErrorCode
&status
) {
836 return MeasureUnit::create(13, 3, status
);
839 MeasureUnit
*MeasureUnit::createMilliwatt(UErrorCode
&status
) {
840 return MeasureUnit::create(13, 4, status
);
843 MeasureUnit
*MeasureUnit::createWatt(UErrorCode
&status
) {
844 return MeasureUnit::create(13, 5, status
);
847 MeasureUnit
*MeasureUnit::createHectopascal(UErrorCode
&status
) {
848 return MeasureUnit::create(14, 0, status
);
851 MeasureUnit
*MeasureUnit::createInchHg(UErrorCode
&status
) {
852 return MeasureUnit::create(14, 1, status
);
855 MeasureUnit
*MeasureUnit::createMillibar(UErrorCode
&status
) {
856 return MeasureUnit::create(14, 2, status
);
859 MeasureUnit
*MeasureUnit::createMillimeterOfMercury(UErrorCode
&status
) {
860 return MeasureUnit::create(14, 3, status
);
863 MeasureUnit
*MeasureUnit::createPoundPerSquareInch(UErrorCode
&status
) {
864 return MeasureUnit::create(14, 4, status
);
867 MeasureUnit
*MeasureUnit::createKarat(UErrorCode
&status
) {
868 return MeasureUnit::create(15, 0, status
);
871 MeasureUnit
*MeasureUnit::createKilometerPerHour(UErrorCode
&status
) {
872 return MeasureUnit::create(16, 0, status
);
875 MeasureUnit
*MeasureUnit::createMeterPerSecond(UErrorCode
&status
) {
876 return MeasureUnit::create(16, 1, status
);
879 MeasureUnit
*MeasureUnit::createMilePerHour(UErrorCode
&status
) {
880 return MeasureUnit::create(16, 2, status
);
883 MeasureUnit
*MeasureUnit::createCelsius(UErrorCode
&status
) {
884 return MeasureUnit::create(17, 0, status
);
887 MeasureUnit
*MeasureUnit::createFahrenheit(UErrorCode
&status
) {
888 return MeasureUnit::create(17, 1, status
);
891 MeasureUnit
*MeasureUnit::createKelvin(UErrorCode
&status
) {
892 return MeasureUnit::create(17, 2, status
);
895 // Apple-specific for now
896 MeasureUnit
*MeasureUnit::createGenericTemperature(UErrorCode
&status
) {
897 return MeasureUnit::create(17, 3, status
);
900 MeasureUnit
*MeasureUnit::createAcreFoot(UErrorCode
&status
) {
901 return MeasureUnit::create(18, 0, status
);
904 MeasureUnit
*MeasureUnit::createBushel(UErrorCode
&status
) {
905 return MeasureUnit::create(18, 1, status
);
908 MeasureUnit
*MeasureUnit::createCentiliter(UErrorCode
&status
) {
909 return MeasureUnit::create(18, 2, status
);
912 MeasureUnit
*MeasureUnit::createCubicCentimeter(UErrorCode
&status
) {
913 return MeasureUnit::create(18, 3, status
);
916 MeasureUnit
*MeasureUnit::createCubicFoot(UErrorCode
&status
) {
917 return MeasureUnit::create(18, 4, status
);
920 MeasureUnit
*MeasureUnit::createCubicInch(UErrorCode
&status
) {
921 return MeasureUnit::create(18, 5, status
);
924 MeasureUnit
*MeasureUnit::createCubicKilometer(UErrorCode
&status
) {
925 return MeasureUnit::create(18, 6, status
);
928 MeasureUnit
*MeasureUnit::createCubicMeter(UErrorCode
&status
) {
929 return MeasureUnit::create(18, 7, status
);
932 MeasureUnit
*MeasureUnit::createCubicMile(UErrorCode
&status
) {
933 return MeasureUnit::create(18, 8, status
);
936 MeasureUnit
*MeasureUnit::createCubicYard(UErrorCode
&status
) {
937 return MeasureUnit::create(18, 9, status
);
940 MeasureUnit
*MeasureUnit::createCup(UErrorCode
&status
) {
941 return MeasureUnit::create(18, 10, status
);
944 MeasureUnit
*MeasureUnit::createDeciliter(UErrorCode
&status
) {
945 return MeasureUnit::create(18, 11, status
);
948 MeasureUnit
*MeasureUnit::createFluidOunce(UErrorCode
&status
) {
949 return MeasureUnit::create(18, 12, status
);
952 MeasureUnit
*MeasureUnit::createGallon(UErrorCode
&status
) {
953 return MeasureUnit::create(18, 13, status
);
956 MeasureUnit
*MeasureUnit::createHectoliter(UErrorCode
&status
) {
957 return MeasureUnit::create(18, 14, status
);
960 MeasureUnit
*MeasureUnit::createLiter(UErrorCode
&status
) {
961 return MeasureUnit::create(18, 15, status
);
964 MeasureUnit
*MeasureUnit::createMegaliter(UErrorCode
&status
) {
965 return MeasureUnit::create(18, 16, status
);
968 MeasureUnit
*MeasureUnit::createMilliliter(UErrorCode
&status
) {
969 return MeasureUnit::create(18, 17, status
);
972 MeasureUnit
*MeasureUnit::createPint(UErrorCode
&status
) {
973 return MeasureUnit::create(18, 18, status
);
976 MeasureUnit
*MeasureUnit::createQuart(UErrorCode
&status
) {
977 return MeasureUnit::create(18, 19, status
);
980 MeasureUnit
*MeasureUnit::createTablespoon(UErrorCode
&status
) {
981 return MeasureUnit::create(18, 20, status
);
984 MeasureUnit
*MeasureUnit::createTeaspoon(UErrorCode
&status
) {
985 return MeasureUnit::create(18, 21, status
);
988 // End generated code
990 static int32_t binarySearch(
991 const char * const * array
, int32_t start
, int32_t end
, const char * key
) {
992 while (start
< end
) {
993 int32_t mid
= (start
+ end
) / 2;
994 int32_t cmp
= uprv_strcmp(array
[mid
], key
);
1007 MeasureUnit::MeasureUnit(const MeasureUnit
&other
)
1008 : fTypeId(other
.fTypeId
), fSubTypeId(other
.fSubTypeId
) {
1009 uprv_strcpy(fCurrency
, other
.fCurrency
);
1012 MeasureUnit
&MeasureUnit::operator=(const MeasureUnit
&other
) {
1013 if (this == &other
) {
1016 fTypeId
= other
.fTypeId
;
1017 fSubTypeId
= other
.fSubTypeId
;
1018 uprv_strcpy(fCurrency
, other
.fCurrency
);
1022 UObject
*MeasureUnit::clone() const {
1023 return new MeasureUnit(*this);
1026 MeasureUnit::~MeasureUnit() {
1029 const char *MeasureUnit::getType() const {
1030 return gTypes
[fTypeId
];
1033 const char *MeasureUnit::getSubtype() const {
1034 return fCurrency
[0] == 0 ? gSubTypes
[getOffset()] : fCurrency
;
1037 UBool
MeasureUnit::operator==(const UObject
& other
) const {
1038 if (this == &other
) { // Same object, equal
1041 if (typeid(*this) != typeid(other
)) { // Different types, not equal
1044 const MeasureUnit
&rhs
= static_cast<const MeasureUnit
&>(other
);
1046 fTypeId
== rhs
.fTypeId
1047 && fSubTypeId
== rhs
.fSubTypeId
1048 && uprv_strcmp(fCurrency
, rhs
.fCurrency
) == 0);
1051 int32_t MeasureUnit::getIndex() const {
1052 return gIndexes
[fTypeId
] + fSubTypeId
;
1055 int32_t MeasureUnit::getAvailable(
1057 int32_t destCapacity
,
1058 UErrorCode
&errorCode
) {
1059 if (U_FAILURE(errorCode
)) {
1062 if (destCapacity
< UPRV_LENGTHOF(gSubTypes
)) {
1063 errorCode
= U_BUFFER_OVERFLOW_ERROR
;
1064 return UPRV_LENGTHOF(gSubTypes
);
1067 for (int32_t typeIdx
= 0; typeIdx
< UPRV_LENGTHOF(gTypes
); ++typeIdx
) {
1068 int32_t len
= gOffsets
[typeIdx
+ 1] - gOffsets
[typeIdx
];
1069 for (int32_t subTypeIdx
= 0; subTypeIdx
< len
; ++subTypeIdx
) {
1070 dest
[idx
].setTo(typeIdx
, subTypeIdx
);
1074 U_ASSERT(idx
== UPRV_LENGTHOF(gSubTypes
));
1075 return UPRV_LENGTHOF(gSubTypes
);
1078 int32_t MeasureUnit::getAvailable(
1081 int32_t destCapacity
,
1082 UErrorCode
&errorCode
) {
1083 if (U_FAILURE(errorCode
)) {
1086 int32_t typeIdx
= binarySearch(gTypes
, 0, UPRV_LENGTHOF(gTypes
), type
);
1087 if (typeIdx
== -1) {
1090 int32_t len
= gOffsets
[typeIdx
+ 1] - gOffsets
[typeIdx
];
1091 if (destCapacity
< len
) {
1092 errorCode
= U_BUFFER_OVERFLOW_ERROR
;
1095 for (int subTypeIdx
= 0; subTypeIdx
< len
; ++subTypeIdx
) {
1096 dest
[subTypeIdx
].setTo(typeIdx
, subTypeIdx
);
1101 StringEnumeration
* MeasureUnit::getAvailableTypes(UErrorCode
&errorCode
) {
1102 UEnumeration
*uenum
= uenum_openCharStringsEnumeration(
1103 gTypes
, UPRV_LENGTHOF(gTypes
), &errorCode
);
1104 if (U_FAILURE(errorCode
)) {
1108 StringEnumeration
*result
= new UStringEnumeration(uenum
);
1109 if (result
== NULL
) {
1110 errorCode
= U_MEMORY_ALLOCATION_ERROR
;
1117 int32_t MeasureUnit::getIndexCount() {
1118 return gIndexes
[UPRV_LENGTHOF(gIndexes
) - 1];
1121 MeasureUnit
*MeasureUnit::resolveUnitPerUnit(
1122 const MeasureUnit
&unit
, const MeasureUnit
&perUnit
) {
1123 int32_t unitOffset
= unit
.getOffset();
1124 int32_t perUnitOffset
= perUnit
.getOffset();
1126 // binary search for (unitOffset, perUnitOffset)
1128 int32_t end
= UPRV_LENGTHOF(unitPerUnitToSingleUnit
);
1129 while (start
< end
) {
1130 int32_t mid
= (start
+ end
) / 2;
1131 int32_t *midRow
= unitPerUnitToSingleUnit
[mid
];
1132 if (unitOffset
< midRow
[0]) {
1134 } else if (unitOffset
> midRow
[0]) {
1136 } else if (perUnitOffset
< midRow
[1]) {
1138 } else if (perUnitOffset
> midRow
[1]) {
1141 // We found a resolution for our unit / per-unit combo
1143 return new MeasureUnit(midRow
[2], midRow
[3]);
1149 MeasureUnit
*MeasureUnit::create(int typeId
, int subTypeId
, UErrorCode
&status
) {
1150 if (U_FAILURE(status
)) {
1153 MeasureUnit
*result
= new MeasureUnit(typeId
, subTypeId
);
1154 if (result
== NULL
) {
1155 status
= U_MEMORY_ALLOCATION_ERROR
;
1160 void MeasureUnit::initTime(const char *timeId
) {
1161 int32_t result
= binarySearch(gTypes
, 0, UPRV_LENGTHOF(gTypes
), "duration");
1162 U_ASSERT(result
!= -1);
1164 result
= binarySearch(gSubTypes
, gOffsets
[fTypeId
], gOffsets
[fTypeId
+ 1], timeId
);
1165 U_ASSERT(result
!= -1);
1166 fSubTypeId
= result
- gOffsets
[fTypeId
];
1169 void MeasureUnit::initCurrency(const char *isoCurrency
) {
1170 int32_t result
= binarySearch(gTypes
, 0, UPRV_LENGTHOF(gTypes
), "currency");
1171 U_ASSERT(result
!= -1);
1173 result
= binarySearch(
1174 gSubTypes
, gOffsets
[fTypeId
], gOffsets
[fTypeId
+ 1], isoCurrency
);
1176 fSubTypeId
= result
- gOffsets
[fTypeId
];
1178 uprv_strncpy(fCurrency
, isoCurrency
, UPRV_LENGTHOF(fCurrency
));
1182 void MeasureUnit::setTo(int32_t typeId
, int32_t subTypeId
) {
1184 fSubTypeId
= subTypeId
;
1188 int32_t MeasureUnit::getOffset() const {
1189 return gOffsets
[fTypeId
] + fSubTypeId
;
1194 #endif /* !UNCONFIG_NO_FORMATTING */