UNUM_MEASURE_UNIT_FIELD,
/** @stable ICU 64 */
UNUM_COMPACT_FIELD,
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Approximately sign. In ICU 70, this was categorized under the generic SIGN field.
+ * @draft ICU 71
+ */
+ UNUM_APPROXIMATELY_SIGN_FIELD,
+#endif // U_HIDE_DRAFT_API
#ifndef U_HIDE_DEPRECATED_API
/**
* One more than the highest normal UNumberFormatFields value.
* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
*/
- UNUM_FIELD_COUNT = UNUM_SIGN_FIELD + 3
+#ifndef U_HIDE_DRAFT_API
+ UNUM_FIELD_COUNT = UNUM_COMPACT_FIELD + 2
+#else // U_HIDE_DRAFT_API (for UNUM_APPROXIMATELY_SIGN_FIELD)
+ UNUM_FIELD_COUNT = UNUM_COMPACT_FIELD + 1
+#endif // U_HIDE_DRAFT_API (for UNUM_APPROXIMATELY_SIGN_FIELD)
#endif /* U_HIDE_DEPRECATED_API */
} UNumberFormatFields;
expectedFieldPositions,
UPRV_LENGTHOF(expectedFieldPositions));
}
+
+ {
+ const char16_t* message = u"Field position with approximately sign";
+ const char16_t* expectedString = u"~-100";
+ FormattedNumberRange result = assertFormattedRangeEquals(
+ message,
+ NumberRangeFormatter::withLocale("en-us"),
+ -100,
+ -100,
+ expectedString);
+ static const UFieldPositionWithCategory expectedFieldPositions[] = {
+ // category, field, begin index, end index
+ {UFIELD_CATEGORY_NUMBER, UNUM_APPROXIMATELY_SIGN_FIELD, 0, 1},
+ {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD, 1, 2},
+ {UFIELD_CATEGORY_NUMBER, UNUM_INTEGER_FIELD, 2, 5}};
+ checkMixedFormattedValue(
+ message,
+ result,
+ expectedString,
+ expectedFieldPositions,
+ UPRV_LENGTHOF(expectedFieldPositions));
+ }
}
void NumberRangeFormatterTest::testCopyMove() {
FormattedNumberRange result4 = lnf.formatRange(Double.NaN, 0);
FormattedNumberRange result5 = lnf.formatRange(0, Double.NaN);
FormattedNumberRange result6 = lnf.formatRange(Double.NaN, Double.NaN);
-
+
assertEquals("0 - inf", "-∞ – 0", result1.toString());
assertEquals("-inf - 0", "0–∞", result2.toString());
assertEquals("-inf - inf", "-∞ – ∞", result3.toString());
{NumberFormat.Field.INTEGER, 11, 21}};
FormattedValueTest.checkFormattedValue(message, fmtd, expectedString, expectedFieldPositions);
}
+
+ {
+ String message = "Field position with approximately sign";
+ String expectedString = "~-100";
+ FormattedNumberRange fmtd = assertFormattedRangeEquals(
+ message,
+ NumberRangeFormatter.withLocale(ULocale.US),
+ -100,
+ -100,
+ expectedString);
+ Object[][] expectedFieldPositions = new Object[][]{
+ {NumberFormat.Field.APPROXIMATELY_SIGN, 0, 1},
+ {NumberFormat.Field.SIGN, 1, 2},
+ {NumberFormat.Field.INTEGER, 2, 5}};
+ FormattedValueTest.checkFormattedValue(message, fmtd, expectedString, expectedFieldPositions);
+ }
}
static final String[] allNSNames = NumberingSystem.getAvailableNames();
"CHF 4’999.00–5’001.00",
"CHF≈5’000.00",
"CHF 5’000.00–5’000’000.00");
-
+
// TODO(CLDR-13044): Move the sign to the inside of the number
assertFormatRange(
"Approximately sign position with currency spacing",
"CHF 4,999.00–5,001.00",
"~CHF 5,000.00",
"CHF 5,000.00–5,000,000.00");
-
+
{
LocalizedNumberRangeFormatter lnrf = NumberRangeFormatter
.withLocale(ULocale.forLanguageTag("de-CH"));
String actual = lnrf.formatRange(-2, 3).toString();
assertEquals("Negative to positive range", "-2 – 3", actual);
}
-
+
{
LocalizedNumberRangeFormatter lnrf = NumberRangeFormatter
.withLocale(ULocale.forLanguageTag("de-CH"))
String actual = lnrf.formatRange(-2, 3).toString();
assertEquals("Negative to positive percent", "-2% – 3%", actual);
}
-
+
{
// TODO(CLDR-14111): Add spacing between range separator and sign
LocalizedNumberRangeFormatter lnrf = NumberRangeFormatter
String actual = lnrf.formatRange(2, -3).toString();
assertEquals("Positive to negative range", "2–-3", actual);
}
-
+
{
LocalizedNumberRangeFormatter lnrf = NumberRangeFormatter
.withLocale(ULocale.forLanguageTag("de-CH"))