From: Shane Carr Date: Wed, 9 May 2018 02:00:22 +0000 (+0000) Subject: ICU-13662 Replying to code review feedback. X-Git-Tag: release-62-rc~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb94a3eb7642ac9eca72ca228f040f4768888d44;p=icu ICU-13662 Replying to code review feedback. X-SVN-Rev: 41365 --- diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index 16412535a85..161861d7326 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -1232,7 +1232,9 @@ const numparse::impl::NumberParserImpl* DecimalFormat::getCurrencyParser(UErrorC void DecimalFormat::fieldPositionHelper(const number::FormattedNumber& formatted, FieldPosition& fieldPosition, int32_t offset, UErrorCode& status) { - fieldPosition.setEndIndex(0); // always return first occurrence + // always return first occurrence: + fieldPosition.setBeginIndex(0); + fieldPosition.setEndIndex(0); bool found = formatted.nextFieldPosition(fieldPosition, status); if (found && offset != 0) { fieldPosition.setBeginIndex(fieldPosition.getBeginIndex() + offset); diff --git a/icu4c/source/i18n/unicode/numberformatter.h b/icu4c/source/i18n/unicode/numberformatter.h index c325ff345a3..8904a308191 100644 --- a/icu4c/source/i18n/unicode/numberformatter.h +++ b/icu4c/source/i18n/unicode/numberformatter.h @@ -1791,8 +1791,8 @@ class U_I18N_API NumberFormatterSettings { * numbering system. * *

- * Note: The instance of DecimalFormatSymbols will be copied: changes made to the symbols object - * after passing it into the fluent chain will not be seen. + * Note: Calling this method will override any previously specified DecimalFormatSymbols + * or NumberingSystem. * *

* Note: Calling this method will override the NumberingSystem previously specified in @@ -1838,8 +1838,8 @@ class U_I18N_API NumberFormatterSettings { * * *

- * Note: Calling this method will override the DecimalFormatSymbols previously specified in - * {@link #symbols(DecimalFormatSymbols)}. + * Note: Calling this method will override any previously specified DecimalFormatSymbols + * or NumberingSystem. * *

* The default is to choose the best numbering system for the locale. @@ -1927,7 +1927,6 @@ class U_I18N_API NumberFormatterSettings { * The sign display strategy to use when rendering numbers. * @return The fluent chain * @see UNumberSignDisplay - * @provisional This API might change or be removed in a future release. * @draft ICU 60 */ Derived sign(UNumberSignDisplay style) const &; @@ -1966,7 +1965,6 @@ class U_I18N_API NumberFormatterSettings { * The decimal separator display strategy to use when rendering numbers. * @return The fluent chain * @see UNumberDecimalSeparatorDisplay - * @provisional This API might change or be removed in a future release. * @draft ICU 60 */ Derived decimal(UNumberDecimalSeparatorDisplay style) const &; @@ -2423,7 +2421,7 @@ class U_I18N_API FormattedNumber : public UMemory { * The FieldPosition to populate with the start and end indices of the desired field. * @param status * Set if an error occurs while populating the FieldPosition. - * @deprecated ICU 62 Use {@link #toCharacterIterator} instead. This method will be removed in a future + * @deprecated ICU 62 Use {@link #nextFieldPosition} instead. This method will be removed in a future * release. See http://bugs.icu-project.org/trac/ticket/13746 * @see UNumberFormatFields */ @@ -2445,15 +2443,15 @@ class U_I18N_API FormattedNumber : public UMemory { * * * This method is useful if you know which field to query. If you want all available field position - * information, use #getAllFields(). + * information, use #getAllFieldPositions(). * * @param fieldPosition - * Input+output variable. On input, the "field" property determines which field to look up, - * and the "endIndex" property determines where to begin the search. On output, the - * "beginIndex" field is set to the beginning of the first occurrence of the field after the - * input "endIndex", and "endIndex" is set to the end of that occurrence of the field - * (exclusive index). If a field position is not found, the FieldPosition is not changed and - * the method returns FALSE. + * Input+output variable. On input, the "field" property determines which field to look + * up, and the "beginIndex" and "endIndex" properties determine where to begin the search. + * On output, the "beginIndex" is set to the beginning of the first occurrence of the + * field with either begin or end indices after the input indices, "endIndex" is set to + * the end of that occurrence of the field (exclusive index). If a field position is not + * found, the method returns FALSE and the FieldPosition may or may not be changed. * @param status * Set if an error occurs while populating the FieldPosition. * @return TRUE if a new occurrence of the field was found; FALSE otherwise. @@ -2483,7 +2481,7 @@ class U_I18N_API FormattedNumber : public UMemory { * Export the formatted number to a FieldPositionIterator. This allows you to determine which characters in * the output string correspond to which fields, such as the integer part, fraction part, and sign. * - * If information on only one field is needed, use #nextFieldPosition(). + * If information on only one field is needed, use #nextFieldPosition() instead. * * @param iterator * The FieldPositionIterator to populate with all of the fields present in the formatted number. diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/FormattedNumber.java b/icu4j/main/classes/core/src/com/ibm/icu/number/FormattedNumber.java index 72acb399bec..965f5629b5e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/number/FormattedNumber.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/number/FormattedNumber.java @@ -93,6 +93,7 @@ public class FormattedNumber { @Deprecated public void populateFieldPosition(FieldPosition fieldPosition) { // in case any users were depending on the old behavior: + fieldPosition.setBeginIndex(0); fieldPosition.setEndIndex(0); nextFieldPosition(fieldPosition); } @@ -105,23 +106,24 @@ public class FormattedNumber { * If a field occurs just once, calling this method will find that occurrence and return it. If a * field occurs multiple times, this method may be called repeatedly with the following pattern: *

+ * *

      * FieldPosition fpos = new FieldPosition(NumberFormat.Field.GROUPING_SEPARATOR);
      * while (formattedNumber.nextFieldPosition(fpos, status)) {
-     *   // do something with fpos.
+     *     // do something with fpos.
      * }
      * 
*

* This method is useful if you know which field to query. If you want all available field position - * information, use #getAllFields(). + * information, use {@link #toCharacterIterator()}. * * @param fieldPosition - * Input+output variable. On input, the "field" property determines which field to look up, - * and the "endIndex" property determines where to begin the search. On output, the - * "beginIndex" field is set to the beginning of the first occurrence of the field after the - * input "endIndex", and "endIndex" is set to the end of that occurrence of the field - * (exclusive index). If a field position is not found, the FieldPosition is not changed and - * the method returns false. + * Input+output variable. On input, the "field" property determines which field to look + * up, and the "beginIndex" and "endIndex" properties determine where to begin the search. + * On output, the "beginIndex" is set to the beginning of the first occurrence of the + * field with either begin or end indices after the input indices, "endIndex" is set to + * the end of that occurrence of the field (exclusive index). If a field position is not + * found, the method returns FALSE and the FieldPosition may or may not be changed. * @return true if a new occurrence of the field was found; false otherwise. * @draft ICU 62 * @provisional This API might change or be removed in a future release. @@ -158,7 +160,7 @@ public class FormattedNumber { * characters in the output string correspond to which fields, such as the integer part, * fraction part, and sign. *

- * If information on only one field is needed, consider using populateFieldPosition() instead. + * If information on only one field is needed, use {@link #nextFieldPosition(FieldPosition)} instead. * * @return An AttributedCharacterIterator, containing information on the field attributes of the * number string. diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java index 7bf58f9273f..f23154074cc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java @@ -2567,7 +2567,9 @@ public class DecimalFormat extends NumberFormat { } static void fieldPositionHelper(FormattedNumber formatted, FieldPosition fieldPosition, int offset) { - fieldPosition.setEndIndex(0); // always return first occurrence + // always return first occurrence: + fieldPosition.setBeginIndex(0); + fieldPosition.setEndIndex(0); boolean found = formatted.nextFieldPosition(fieldPosition); if (found && offset != 0) { fieldPosition.setBeginIndex(fieldPosition.getBeginIndex() + offset);