mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-11016 add support for minimum grouping digits (technology preview, not using CLDR data yet)
X-SVN-Rev: 37946
This commit is contained in:
parent
39f698cbc3
commit
69543d559e
5 changed files with 79 additions and 14 deletions
|
@ -2738,6 +2738,22 @@ DecimalFormat::setSecondaryGroupingSize(int32_t newValue)
|
|||
fImpl->setSecondaryGroupingSize(newValue);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int32_t
|
||||
DecimalFormat::getMinimumGroupingDigits() const
|
||||
{
|
||||
return fImpl->getMinimumGroupingDigits();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
DecimalFormat::setMinimumGroupingDigits(int32_t newValue)
|
||||
{
|
||||
fImpl->setMinimumGroupingDigits(newValue);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Checks if to show the decimal separator.
|
||||
|
||||
|
@ -3138,6 +3154,11 @@ DecimalFormat& DecimalFormat::setAttribute( UNumberFormatAttribute attr,
|
|||
|
||||
case UNUM_CURRENCY_USAGE:
|
||||
setCurrencyUsage((UCurrencyUsage)newValue, &status);
|
||||
break;
|
||||
|
||||
case UNUM_MINIMUM_GROUPING_DIGITS:
|
||||
setMinimumGroupingDigits(newValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
status = U_UNSUPPORTED_ERROR;
|
||||
|
@ -3221,6 +3242,9 @@ int32_t DecimalFormat::getAttribute( UNumberFormatAttribute attr,
|
|||
case UNUM_CURRENCY_USAGE:
|
||||
return fImpl->getCurrencyUsage();
|
||||
|
||||
case UNUM_MINIMUM_GROUPING_DIGITS:
|
||||
return getMinimumGroupingDigits();
|
||||
|
||||
default:
|
||||
status = U_UNSUPPORTED_ERROR;
|
||||
break;
|
||||
|
|
|
@ -1647,6 +1647,43 @@ public:
|
|||
*/
|
||||
virtual void setSecondaryGroupingSize(int32_t newValue);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
||||
/**
|
||||
* Returns the minimum number of grouping digits.
|
||||
* Grouping separators are output if there are at least this many
|
||||
* digits to the left of the first (rightmost) grouping separator,
|
||||
* that is, there are at least (minimum grouping + grouping size) integer digits.
|
||||
* (Subject to isGroupingUsed().)
|
||||
*
|
||||
* For example, if this value is 2, and the grouping size is 3, then
|
||||
* 9999 -> "9999" and 10000 -> "10,000"
|
||||
*
|
||||
* This is a technology preview. This API may change behavior or may be removed.
|
||||
*
|
||||
* The default value for this attribute is 0.
|
||||
* A value of 1, 0, or lower, means that the use of grouping separators
|
||||
* only depends on the grouping size (and on isGroupingUsed()).
|
||||
* Currently, the corresponding CLDR data is not used; this is likely to change.
|
||||
*
|
||||
* @see setMinimumGroupingDigits
|
||||
* @see getGroupingSize
|
||||
* @internal technology preview
|
||||
*/
|
||||
int32_t getMinimumGroupingDigits() const;
|
||||
|
||||
/**
|
||||
* Sets the minimum grouping digits. Setting to a value less than or
|
||||
* equal to 1 turns off minimum grouping digits.
|
||||
*
|
||||
* @param newValue the new value of minimum grouping digits.
|
||||
* @see getMinimumGroupingDigits
|
||||
* @internal technology preview
|
||||
*/
|
||||
virtual void setMinimumGroupingDigits(int32_t newValue);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allows you to get the behavior of the decimal separator with integers.
|
||||
* (The decimal separator will always appear with decimals.)
|
||||
|
|
|
@ -932,7 +932,7 @@ typedef enum UNumberFormatAttribute {
|
|||
* This is an internal ICU API. Do not use.
|
||||
* @internal
|
||||
*/
|
||||
UNUM_PARSE_ALL_INPUT = UNUM_LENIENT_PARSE + 1,
|
||||
UNUM_PARSE_ALL_INPUT = 20,
|
||||
#endif
|
||||
/**
|
||||
* Scale, which adjusts the position of the
|
||||
|
@ -943,12 +943,16 @@ typedef enum UNumberFormatAttribute {
|
|||
* <p>Example: setting the scale to -4, 123 formats as "0.0123"
|
||||
*
|
||||
* @stable ICU 51 */
|
||||
UNUM_SCALE = UNUM_LENIENT_PARSE + 2,
|
||||
|
||||
UNUM_SCALE = 21,
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/** Count of "regular" numeric attributes.
|
||||
* @internal */
|
||||
UNUM_NUMERIC_ATTRIBUTE_COUNT = UNUM_LENIENT_PARSE + 3,
|
||||
/**
|
||||
* Minimum grouping digits, technology preview.
|
||||
* See DecimalFormat::getMinimumGroupingDigits().
|
||||
*
|
||||
* @internal technology preview
|
||||
*/
|
||||
UNUM_MINIMUM_GROUPING_DIGITS = 22,
|
||||
/* TODO: test C API when it becomes @draft */
|
||||
#endif /* U_HIDE_INTERNAL_API */
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
@ -958,7 +962,7 @@ typedef enum UNumberFormatAttribute {
|
|||
* Default: 0 (UNUM_CURRENCY_STANDARD purpose)
|
||||
* @draft ICU 54
|
||||
*/
|
||||
UNUM_CURRENCY_USAGE = UNUM_LENIENT_PARSE + 4,
|
||||
UNUM_CURRENCY_USAGE = 23,
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
|
||||
|
@ -990,13 +994,13 @@ typedef enum UNumberFormatAttribute {
|
|||
* Default: 0 (unset)
|
||||
* @draft ICU 54
|
||||
*/
|
||||
UNUM_PARSE_DECIMAL_MARK_REQUIRED = UNUM_PARSE_NO_EXPONENT+1,
|
||||
UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002,
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
/* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
|
||||
/** Limit of boolean attributes.
|
||||
* @internal */
|
||||
UNUM_LIMIT_BOOLEAN_ATTRIBUTE = UNUM_PARSE_NO_EXPONENT+2
|
||||
UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003
|
||||
} UNumberFormatAttribute;
|
||||
|
||||
/**
|
||||
|
@ -1007,7 +1011,7 @@ typedef enum UNumberFormatAttribute {
|
|||
* UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
|
||||
* UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
|
||||
* UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
|
||||
* UNUM_SCALE.
|
||||
* UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
|
||||
* @return The value of attr.
|
||||
* @see unum_setAttribute
|
||||
* @see unum_getDoubleAttribute
|
||||
|
@ -1030,7 +1034,7 @@ unum_getAttribute(const UNumberFormat* fmt,
|
|||
* UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
|
||||
* UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
|
||||
* UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
|
||||
* UNUM_LENIENT_PARSE, or UNUM_SCALE.
|
||||
* UNUM_LENIENT_PARSE, UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
|
||||
* @param newValue The new value of attr.
|
||||
* @see unum_getAttribute
|
||||
* @see unum_getDoubleAttribute
|
||||
|
|
|
@ -132,7 +132,7 @@ static void adjustDecimalFormat(
|
|||
}
|
||||
}
|
||||
if (tuple.minGroupingDigitsFlag) {
|
||||
// Oops, not supported
|
||||
fmt.setMinimumGroupingDigits(tuple.minGroupingDigits);
|
||||
}
|
||||
if (tuple.useSigDigitsFlag) {
|
||||
fmt.setSignificantDigitsUsed(tuple.useSigDigits != 0);
|
||||
|
|
|
@ -202,7 +202,7 @@ begin
|
|||
format output breaks
|
||||
// min grouping digits not supported in any existing implementation
|
||||
// but could be easily added to the new DecimalFormat C code.
|
||||
1000 1000 CJK
|
||||
1000 1000 JK
|
||||
10000 10,000
|
||||
100000 100,000
|
||||
1000000 1,000,000
|
||||
|
@ -359,7 +359,7 @@ output grouping breaks grouping2 minGroupingDigits
|
|||
1,23,45,6789 4 K 2
|
||||
1,23,45,6789 4 K 2 2
|
||||
123,456789 6 K 6 3
|
||||
123456789 6 CJK 6 4
|
||||
123456789 6 JK 6 4
|
||||
|
||||
test multiplier setters
|
||||
set locale en_US
|
||||
|
|
Loading…
Add table
Reference in a new issue