ICU-21540 Fix FormattedList test and behavior regression

This commit is contained in:
Shane F. Carr 2021-04-06 12:22:26 -05:00 committed by Shane F. Carr
parent 928febc705
commit 7fd2844d10
2 changed files with 9 additions and 5 deletions

View file

@ -154,7 +154,10 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition&
if (i > fString.fZero && prevIsSpan) {
int64_t si = cfpos.getInt64IterationContext() - 1;
U_ASSERT(si >= 0);
if (_field == Field(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD)) {
int32_t previ = i - spanIndices[si].length;
U_ASSERT(previ >= fString.fZero);
Field prevField = fString.getFieldPtr()[previ];
if (prevField == Field(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD)) {
// Special handling for ULISTFMT_ELEMENT_FIELD
if (cfpos.matchesField(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD)) {
fieldStart = i - fString.fZero - spanIndices[si].length;
@ -165,12 +168,13 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition&
fieldStart,
end);
return true;
} else {
prevIsSpan = false;
}
} else {
// Re-wind, since there may be multiple fields in the span.
i -= spanIndices[si].length;
U_ASSERT(i >= fString.fZero);
_field = fString.getFieldPtr()[i];
i = previ;
_field = prevField;
}
}
// Special case: coalesce the INTEGER if we are pointing at the end of the INTEGER.

View file

@ -242,7 +242,7 @@ void IntlTestWithFieldPosition::checkMixedFormattedValue(
// Check nextPosition constrained over each category one at a time
for (int32_t category=0; category<UFIELD_CATEGORY_COUNT+1; category++) {
if (category == UFIELD_CATEGORY_COUNT+1) {
if (category == UFIELD_CATEGORY_COUNT) {
category = UFIELD_CATEGORY_LIST_SPAN;
}
cfpos.reset();