mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-21076 Delete unneeded MeasureUnit data & code
This commit is contained in:
parent
863582c2a4
commit
6b595d1c01
3 changed files with 39 additions and 69 deletions
|
@ -34,8 +34,9 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureUnit)
|
|||
// http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit
|
||||
//
|
||||
// Start generated code
|
||||
// TODO(ICU-21076): improve how this generated code is produced.
|
||||
|
||||
|
||||
// Maps from Type ID to offset in gSubTypes.
|
||||
static const int32_t gOffsets[] = {
|
||||
0,
|
||||
2,
|
||||
|
@ -63,32 +64,36 @@ static const int32_t gOffsets[] = {
|
|||
474
|
||||
};
|
||||
|
||||
static const int32_t gIndexes[] = {
|
||||
0,
|
||||
2,
|
||||
7,
|
||||
17,
|
||||
25,
|
||||
29,
|
||||
29,
|
||||
40,
|
||||
56,
|
||||
60,
|
||||
69,
|
||||
71,
|
||||
75,
|
||||
82,
|
||||
103,
|
||||
105,
|
||||
119,
|
||||
122,
|
||||
128,
|
||||
138,
|
||||
142,
|
||||
146,
|
||||
148,
|
||||
175
|
||||
};
|
||||
// TODO: FIX CODE GENERATION - leaving this here but commented-out to make it
|
||||
// clear that we no longer want this array. We needed it for only one thing: efficient checking of "currency".
|
||||
//
|
||||
// static const int32_t gIndexes[] = {
|
||||
// 0,
|
||||
// 2,
|
||||
// 7,
|
||||
// 17,
|
||||
// 25,
|
||||
// 29,
|
||||
// 29,
|
||||
// 40,
|
||||
// 56,
|
||||
// 60,
|
||||
// 69,
|
||||
// 71,
|
||||
// 75,
|
||||
// 82,
|
||||
// 103,
|
||||
// 105,
|
||||
// 119,
|
||||
// 122,
|
||||
// 128,
|
||||
// 138,
|
||||
// 142,
|
||||
// 146,
|
||||
// 148,
|
||||
// 175
|
||||
// };
|
||||
static const int32_t kCurrencyOffset = 5;
|
||||
|
||||
// Must be sorted alphabetically.
|
||||
static const char * const gTypes[] = {
|
||||
|
@ -2107,10 +2112,6 @@ UBool MeasureUnit::operator==(const UObject& other) const {
|
|||
return uprv_strcmp(getIdentifier(), rhs.getIdentifier()) == 0;
|
||||
}
|
||||
|
||||
int32_t MeasureUnit::getIndex() const {
|
||||
return gIndexes[fTypeId] + fSubTypeId;
|
||||
}
|
||||
|
||||
int32_t MeasureUnit::getAvailable(
|
||||
MeasureUnit *dest,
|
||||
int32_t destCapacity,
|
||||
|
@ -2173,26 +2174,12 @@ StringEnumeration* MeasureUnit::getAvailableTypes(UErrorCode &errorCode) {
|
|||
return result;
|
||||
}
|
||||
|
||||
int32_t MeasureUnit::getIndexCount() {
|
||||
return gIndexes[UPRV_LENGTHOF(gIndexes) - 1];
|
||||
}
|
||||
|
||||
int32_t MeasureUnit::internalGetIndexForTypeAndSubtype(const char *type, const char *subtype) {
|
||||
int32_t t = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type);
|
||||
if (t < 0) {
|
||||
return t;
|
||||
}
|
||||
int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype);
|
||||
if (st < 0) {
|
||||
return st;
|
||||
}
|
||||
return gIndexes[t] + st - gOffsets[t];
|
||||
}
|
||||
|
||||
bool MeasureUnit::findBySubType(StringPiece subType, MeasureUnit* output) {
|
||||
for (int32_t t = 0; t < UPRV_LENGTHOF(gOffsets) - 1; t++) {
|
||||
// Ensure kCurrencyOffset is set correctly
|
||||
U_ASSERT(uprv_strcmp(gTypes[kCurrencyOffset], "currency") == 0);
|
||||
// Skip currency units
|
||||
if (gIndexes[t] == gIndexes[t + 1]) {
|
||||
if (t == kCurrencyOffset) {
|
||||
continue;
|
||||
}
|
||||
int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subType);
|
||||
|
|
|
@ -540,26 +540,10 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* ICU use only.
|
||||
* Returns associated array index for this measure unit. Only valid for
|
||||
* non-currency measure units.
|
||||
* Returns associated array index for this measure unit.
|
||||
* @internal
|
||||
*/
|
||||
int32_t getIndex() const;
|
||||
|
||||
/**
|
||||
* ICU use only.
|
||||
* Returns maximum value from getIndex plus 1.
|
||||
* @internal
|
||||
*/
|
||||
static int32_t getIndexCount();
|
||||
|
||||
/**
|
||||
* ICU use only.
|
||||
* @return the unit.getIndex() of the unit which has this unit.getType() and unit.getSubtype(),
|
||||
* or a negative value if there is no such unit
|
||||
* @internal
|
||||
*/
|
||||
static int32_t internalGetIndexForTypeAndSubtype(const char *type, const char *subtype);
|
||||
int32_t getOffset() const;
|
||||
|
||||
/**
|
||||
* ICU use only.
|
||||
|
@ -3393,7 +3377,6 @@ private:
|
|||
MeasureUnit(int32_t typeId, int32_t subTypeId);
|
||||
MeasureUnit(MeasureUnitImpl&& impl);
|
||||
void setTo(int32_t typeId, int32_t subTypeId);
|
||||
int32_t getOffset() const;
|
||||
static MeasureUnit *create(int typeId, int subTypeId, UErrorCode &status);
|
||||
|
||||
/**
|
||||
|
|
|
@ -2270,12 +2270,12 @@ void NumberFormatTest::TestCurrencyUnit(void){
|
|||
}
|
||||
CurrencyUnit bad(BAD, ec);
|
||||
assertSuccess("CurrencyUnit", ec);
|
||||
if (cu.getIndex() == bad.getIndex()) {
|
||||
if (cu.getOffset() == bad.getOffset()) {
|
||||
errln("Indexes of different currencies should differ.");
|
||||
}
|
||||
CurrencyUnit bad2(BAD2, ec);
|
||||
assertSuccess("CurrencyUnit", ec);
|
||||
if (bad2.getIndex() != bad.getIndex()) {
|
||||
if (bad2.getOffset() != bad.getOffset()) {
|
||||
errln("Indexes of unrecognized currencies should be the same.");
|
||||
}
|
||||
if (bad == bad2) {
|
||||
|
|
Loading…
Add table
Reference in a new issue