Skip to content

Commit 25499e3

Browse files
committed
ICU-23265 Tried to address build failures and code review comments.
1 parent ccde962 commit 25499e3

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

icu4c/source/test/depstest/dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ group: units_extra
11351135
group: units
11361136
measunit.o currunit.o
11371137
deps
1138-
stringenumeration errorcode
1138+
stringenumeration errorcode units_extra
11391139

11401140
group: unitsformatter
11411141
units_data.o units_converter.o units_complexconverter.o units_router.o

icu4j/main/core/src/main/java/com/ibm/icu/number/NumberSkeletonImpl.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,20 +1094,11 @@ private static void parseMeasureUnitOption(StringSegment segment, MacroProps mac
10941094
}
10951095
String type = segment.subSequence(0, firstHyphen).toString();
10961096
String subType = segment.subSequence(firstHyphen + 1, segment.length()).toString();
1097-
MeasureUnit unit = MeasureUnit.getUnit(type, subType);
1097+
MeasureUnit unit = MeasureUnit.validateAndGet(type, subType);
10981098
if (unit != null) {
10991099
macros.unit = unit;
11001100
return;
11011101
}
1102-
try {
1103-
unit = MeasureUnit.forIdentifier(subType);
1104-
if (unit.getType().equals(type)) {
1105-
macros.unit = unit;
1106-
return;
1107-
}
1108-
} catch (IllegalArgumentException e) {
1109-
// handled below
1110-
}
11111102

11121103
throw new SkeletonSyntaxException("Unknown measure unit", segment);
11131104
}

icu4j/main/core/src/main/java/com/ibm/icu/util/MeasureUnit.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,23 @@ public static MeasureUnit getUnit(String type, String subtype) {
889889
Map<String, MeasureUnit> units = cache.get(type);
890890
return units != null ? units.get(subtype) : null;
891891
}
892+
893+
@Deprecated
894+
public static MeasureUnit validateAndGet(String type, String subtype) {
895+
MeasureUnit result = MeasureUnit.getUnit(type, subtype);
896+
897+
if (result == null) {
898+
try {
899+
result = MeasureUnit.forIdentifier(subtype);
900+
if (!result.getType().equals(type)) {
901+
result = null;
902+
}
903+
} catch (IllegalArgumentException e) {
904+
// leave result as null
905+
}
906+
}
907+
return result;
908+
}
892909

893910
static final UnicodeSet ASCII = new UnicodeSet('a', 'z').freeze();
894911
static final UnicodeSet ASCII_HYPHEN_DIGITS =

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/number/NumberSkeletonTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,22 +555,23 @@ public void unitAliases() {
555555
class TestCase {
556556
String skeleton;
557557
String expectedResult;
558+
558559
TestCase(String skeleton, String expectedResult) {
559560
this.skeleton = skeleton;
560561
this.expectedResult = expectedResult;
561562
}
562563
}
563564

564565
TestCase[] testCases =
565-
new TestCase[] {
566-
new TestCase("measure-unit/concentr-part-per-1e6", "3.14 ppm"),
567-
new TestCase("measure-unit/concentr-part-per-million", "3.14 ppm"),
568-
new TestCase("measure-unit/concentr-permillion", "3.14 ppm"),
569-
new TestCase("measure-unit/concentr-milligram-ofglucose-per-deciliter", "3.14 mg/dL"),
570-
new TestCase("measure-unit/concentr-milligram-per-deciliter", "3.14 mg/dL"),
571-
new TestCase("measure-unit/mass-tonne", "3.14 t"),
572-
new TestCase("measure-unit/mass-metric-ton", "3.14 t"),
573-
};
566+
new TestCase[] {
567+
new TestCase("measure-unit/concentr-part-per-1e6", "3.14 ppm"),
568+
new TestCase("measure-unit/concentr-part-per-million", "3.14 ppm"),
569+
new TestCase("measure-unit/concentr-permillion", "3.14 ppm"),
570+
new TestCase("measure-unit/concentr-milligram-ofglucose-per-deciliter", "3.14 mg/dL"),
571+
new TestCase("measure-unit/concentr-milligram-per-deciliter", "3.14 mg/dL"),
572+
new TestCase("measure-unit/mass-tonne", "3.14 t"),
573+
new TestCase("measure-unit/mass-metric-ton", "3.14 t"),
574+
};
574575

575576
for (TestCase testCase : testCases) {
576577
try {

0 commit comments

Comments
 (0)