From 2e3c881a95cda64213d76eff1f76b7a551a4fa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 16 Nov 2021 17:02:57 +0000 Subject: [PATCH] Bug 1738422 - Part 9: Add a separate UNumberFormatFields constant for the approximately sign. r=platform-i18n-reviewers,dminor Our previous heuristic no longer works, so we now have to patch ICU directly to support detecting the approximately sign. Depends on D129930 Differential Revision: https://phabricator.services.mozilla.com/D129931 --- .../bug-1738422-approximately-sign.diff | 56 +++++++++++++++++++ intl/icu/source/i18n/number_affixutils.cpp | 2 +- intl/icu/source/i18n/unicode/unum.h | 4 +- intl/update-icu.sh | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 intl/icu-patches/bug-1738422-approximately-sign.diff diff --git a/intl/icu-patches/bug-1738422-approximately-sign.diff b/intl/icu-patches/bug-1738422-approximately-sign.diff new file mode 100644 index 000000000000..20b88980e62e --- /dev/null +++ b/intl/icu-patches/bug-1738422-approximately-sign.diff @@ -0,0 +1,56 @@ +# Add a new UNumberFormatFields constant for the approximately sign. +# +# https://unicode-org.atlassian.net/browse/ICU-21765 + + +diff --git a/intl/icu/source/i18n/number_affixutils.cpp b/intl/icu/source/i18n/number_affixutils.cpp +--- a/intl/icu/source/i18n/number_affixutils.cpp ++++ b/intl/icu/source/i18n/number_affixutils.cpp +@@ -131,17 +131,17 @@ UnicodeString AffixUtils::escape(const U + Field AffixUtils::getFieldForType(AffixPatternType type) { + switch (type) { + case TYPE_MINUS_SIGN: + return {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD}; + case TYPE_PLUS_SIGN: + return {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD}; + case TYPE_APPROXIMATELY_SIGN: + // TODO: Introduce a new field for the approximately sign? +- return {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD}; ++ return {UFIELD_CATEGORY_NUMBER, UNUM_APPROXIMATELY_SIGN_FIELD}; + case TYPE_PERCENT: + return {UFIELD_CATEGORY_NUMBER, UNUM_PERCENT_FIELD}; + case TYPE_PERMILLE: + return {UFIELD_CATEGORY_NUMBER, UNUM_PERMILL_FIELD}; + case TYPE_CURRENCY_SINGLE: + return {UFIELD_CATEGORY_NUMBER, UNUM_CURRENCY_FIELD}; + case TYPE_CURRENCY_DOUBLE: + return {UFIELD_CATEGORY_NUMBER, UNUM_CURRENCY_FIELD}; +diff --git a/intl/icu/source/i18n/unicode/unum.h b/intl/icu/source/i18n/unicode/unum.h +--- a/intl/icu/source/i18n/unicode/unum.h ++++ b/intl/icu/source/i18n/unicode/unum.h +@@ -397,22 +397,24 @@ typedef enum UNumberFormatFields { + UNUM_PERMILL_FIELD, + /** @stable ICU 49 */ + UNUM_SIGN_FIELD, + /** @stable ICU 64 */ + UNUM_MEASURE_UNIT_FIELD, + /** @stable ICU 64 */ + UNUM_COMPACT_FIELD, + ++ UNUM_APPROXIMATELY_SIGN_FIELD, ++ + #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 ++ UNUM_FIELD_COUNT = UNUM_SIGN_FIELD + 4 + #endif /* U_HIDE_DEPRECATED_API */ + } UNumberFormatFields; + + + /** + * Selectors with special numeric values to use locale default minimum grouping + * digits for the DecimalFormat/UNumberFormat setMinimumGroupingDigits method. + * Do not use these constants with the [U]NumberFormatter API. diff --git a/intl/icu/source/i18n/number_affixutils.cpp b/intl/icu/source/i18n/number_affixutils.cpp index f9c154c885cd..19b0e0c9cc0f 100644 --- a/intl/icu/source/i18n/number_affixutils.cpp +++ b/intl/icu/source/i18n/number_affixutils.cpp @@ -136,7 +136,7 @@ Field AffixUtils::getFieldForType(AffixPatternType type) { return {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD}; case TYPE_APPROXIMATELY_SIGN: // TODO: Introduce a new field for the approximately sign? - return {UFIELD_CATEGORY_NUMBER, UNUM_SIGN_FIELD}; + return {UFIELD_CATEGORY_NUMBER, UNUM_APPROXIMATELY_SIGN_FIELD}; case TYPE_PERCENT: return {UFIELD_CATEGORY_NUMBER, UNUM_PERCENT_FIELD}; case TYPE_PERMILLE: diff --git a/intl/icu/source/i18n/unicode/unum.h b/intl/icu/source/i18n/unicode/unum.h index 14f76168b61b..9ca9722b9a50 100644 --- a/intl/icu/source/i18n/unicode/unum.h +++ b/intl/icu/source/i18n/unicode/unum.h @@ -402,12 +402,14 @@ typedef enum UNumberFormatFields { /** @stable ICU 64 */ UNUM_COMPACT_FIELD, + UNUM_APPROXIMATELY_SIGN_FIELD, + #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 + UNUM_FIELD_COUNT = UNUM_SIGN_FIELD + 4 #endif /* U_HIDE_DEPRECATED_API */ } UNumberFormatFields; diff --git a/intl/update-icu.sh b/intl/update-icu.sh index 4cdd07fdff2c..216aa93f28a8 100755 --- a/intl/update-icu.sh +++ b/intl/update-icu.sh @@ -57,6 +57,7 @@ for patch in \ bug-1636984-display-name-fractional-seconds.diff \ bug-1636984-append-item-dayperiod-fractional-seconds.diff \ bug-1706949-wasi-workaround.diff \ + bug-1738422-approximately-sign.diff \ ; do echo "Applying local patch $patch" patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch