ICU-13662 Replying to code review feedback.

X-SVN-Rev: 41365
This commit is contained in:
Shane Carr 2018-05-09 02:00:22 +00:00
parent 03f6b1cf92
commit fb94a3eb76
4 changed files with 30 additions and 26 deletions

View file

@ -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);

View file

@ -1791,8 +1791,8 @@ class U_I18N_API NumberFormatterSettings {
* numbering system.
*
* <p>
* <strong>Note:</strong> The instance of DecimalFormatSymbols will be copied: changes made to the symbols object
* after passing it into the fluent chain will not be seen.
* <strong>Note:</strong> Calling this method will override any previously specified DecimalFormatSymbols
* or NumberingSystem.
*
* <p>
* <strong>Note:</strong> Calling this method will override the NumberingSystem previously specified in
@ -1838,8 +1838,8 @@ class U_I18N_API NumberFormatterSettings {
* </pre>
*
* <p>
* <strong>Note:</strong> Calling this method will override the DecimalFormatSymbols previously specified in
* {@link #symbols(DecimalFormatSymbols)}.
* <strong>Note:</strong> Calling this method will override any previously specified DecimalFormatSymbols
* or NumberingSystem.
*
* <p>
* 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 {
* </pre>
*
* 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 <em>fields</em>, 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.

View file

@ -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:
* <p>
*
* <pre>
* FieldPosition fpos = new FieldPosition(NumberFormat.Field.GROUPING_SEPARATOR);
* while (formattedNumber.nextFieldPosition(fpos, status)) {
* // do something with fpos.
* // do something with fpos.
* }
* </pre>
* <p>
* 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 <em>fields</em>, such as the integer part,
* fraction part, and sign.
* <p>
* 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.

View file

@ -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);