Skip to content

Commit b94b977

Browse files
committed
Fix bug in :test:function selection
1 parent 51f75ae commit b94b977

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

icu4c/source/i18n/messageformat2_function_registry.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,23 +1470,29 @@ void StandardFunctions::TestFunctionValue::selectKeys(const UnicodeString* keys,
14701470
return;
14711471
}
14721472

1473+
prefsLen = 0;
1474+
1475+
if (input != 1) {
1476+
return;
1477+
}
1478+
14731479
// If the Input is 1 and DecimalPlaces is 1, the method will return some slice
14741480
// of the list « '1.0', '1' », depending on whether those values are included in keys.
1475-
bool include1point0 = false;
1476-
bool include1 = false;
14771481
if (input == 1 && decimalPlaces == 1) {
1478-
include1point0 = true;
1479-
include1 = true;
1480-
} else if (input == 1 && decimalPlaces == 0) {
1481-
include1 = true;
1482+
// 1.0 must come first, so search the keys for 1.0 and then 1
1483+
for (int32_t i = 0; i < keysLen; i++) {
1484+
if (keys[i] == u"1.0") {
1485+
prefs[0] = i;
1486+
prefsLen++;
1487+
}
1488+
}
14821489
}
14831490

14841491
// If the Input is 1 and DecimalPlaces is 0, the method will return the list « '1' » if
14851492
// keys includes '1', or an empty list otherwise.
14861493
// If the Input is any other value, the method will return an empty list.
14871494
for (int32_t i = 0; i < keysLen; i++) {
1488-
if ((keys[i] == u"1" && include1)
1489-
|| (keys[i] == u"1.0" && include1point0)) {
1495+
if (keys[i] == u"1") {
14901496
prefs[prefsLen] = i;
14911497
prefsLen++;
14921498
}

0 commit comments

Comments
 (0)