mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-13780 Removing DecimalFormat_ICU58 (finally).
This commit is contained in:
parent
527ff9f7ac
commit
afab3f992c
7 changed files with 404 additions and 7834 deletions
|
@ -10,7 +10,6 @@
|
|||
// per line.
|
||||
//
|
||||
// Field names:
|
||||
// H = ICU4J 58 (archive)
|
||||
// J = ICU4J (current)
|
||||
// K = JDK (ignored if not OpenJDK 1.8)
|
||||
// C = ICU4C (current)
|
||||
|
@ -25,7 +24,7 @@ set locale ar-EG
|
|||
set pattern +0;-#
|
||||
begin
|
||||
format output breaks
|
||||
6 \u061C+\u0666 HK
|
||||
6 \u061C+\u0666 K
|
||||
-6 \u061C-\u0666 K
|
||||
|
||||
test basic patterns
|
||||
|
@ -188,7 +187,7 @@ pattern format output breaks
|
|||
// JDK gives 12,3001E3
|
||||
##0.000#E0 12300.1 12,30E3 K
|
||||
##0.000#E0 12301 12,301E3
|
||||
0.05E0 12301.2 1,25E4 HK
|
||||
0.05E0 12301.2 1,25E4 K
|
||||
##0.000#E0 0.17 170,0E-3
|
||||
// JDK doesn't support significant digits in exponents
|
||||
@@@E0 6.235 6,24E0 K
|
||||
|
@ -270,17 +269,16 @@ $**####,##0 1234 $***1\u202f234 K
|
|||
####,##0$*x;n#'*' -1234 n1\u202f234*xx K
|
||||
*y%4.2###### 4.33 yyyy%432,6 K
|
||||
// In J ICU adds padding as if 'EUR' is only 2 chars (2 * 0xa4)
|
||||
\u00a4\u00a4 **####0.00 433.0 EUR *433,00 HK
|
||||
// In H ICU adds padding as if 'EUR' is only 2 chars (2 * 0xa4)
|
||||
\u00a4\u00a4 **####0.00 433.0 EUR *433,00 K
|
||||
// P fails this one because the test code bypasses CurrencyUsage
|
||||
\u00a4\u00a4 **#######0 433.0 EUR *433,00 HKP
|
||||
\u00a4\u00a4 **#######0 433.0 EUR *433,00 KP
|
||||
|
||||
test padding and currencies
|
||||
begin
|
||||
locale currency pattern format output breaks
|
||||
// In J, JPY is considered 2 char (2 * 0xa4) even though padding is done
|
||||
// after prefix. In C this test works.
|
||||
fr JPY \u00a4\u00a4 **#######0 433.22 JPY ****433 HK
|
||||
fr JPY \u00a4\u00a4 **#######0 433.22 JPY ****433 K
|
||||
// JDK doesn't correct rounding for currency, shows USD (433
|
||||
en USD \u00a4\u00a4 **#######0;\u00a4\u00a4 (#) -433.22 USD (433.22) K
|
||||
|
||||
|
@ -310,9 +308,7 @@ set pattern #,##0
|
|||
set minGroupingDigits 2
|
||||
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 HK
|
||||
1000 1000 K
|
||||
10000 10,000
|
||||
100000 100,000
|
||||
1000000 1,000,000
|
||||
|
@ -351,7 +347,7 @@ minIntegerDigits maxIntegerDigits minFractionDigits maxFractionDigits output bre
|
|||
// JDK gives E0 instead of allowing for unlimited precision
|
||||
0 0 0 0 2.99792458E8 K
|
||||
// J gives 2.9979E8
|
||||
0 1 0 5 2.99792E8 HK
|
||||
0 1 0 5 2.99792E8 K
|
||||
// JDK gives 300E6
|
||||
0 3 0 0 299.792458E6 K
|
||||
// JDK gives 299.8E6 (maybe maxInt + maxFrac instead of minInt + maxFrac)?
|
||||
|
@ -368,7 +364,7 @@ minIntegerDigits maxIntegerDigits minFractionDigits maxFractionDigits output bre
|
|||
// JDK gives E0
|
||||
0 0 1 0 2.99792458E8 K
|
||||
// J gives 2.998E8
|
||||
0 0 0 4 .29979E9 HK
|
||||
0 0 0 4 .29979E9 K
|
||||
// According to the spec, if maxInt>minInt and minInt>1, then set
|
||||
// Context: #13289
|
||||
2 8 1 6 2.9979246E8 K
|
||||
|
@ -423,7 +419,7 @@ begin
|
|||
format maxIntegerDigits output breaks
|
||||
123 1 3
|
||||
// C obeys maxIntegerDigits and prints after the decimal place
|
||||
0 0 .0 HKP
|
||||
0 0 .0 KP
|
||||
// CJP ignore max integer if it is less than zero and prints "123"
|
||||
123 -2147483648 0 CJP
|
||||
12345 1 5
|
||||
|
@ -516,7 +512,7 @@ begin
|
|||
output grouping grouping2 minGroupingDigits breaks
|
||||
1,23,45,6789 4 2 2 K
|
||||
123,456789 6 6 3
|
||||
123456789 6 6 4 HK
|
||||
123456789 6 6 4 K
|
||||
|
||||
test multiplier setters
|
||||
set locale en_US
|
||||
|
@ -524,10 +520,10 @@ begin
|
|||
format multiplier output breaks
|
||||
23 -12 -276
|
||||
23 -1 -23
|
||||
// H (ICU4J 58) and J (current ICU4J) throw exception on zero multiplier.
|
||||
// J (current ICU4J) throws exception on zero multiplier.
|
||||
// ICU4C prints 23.
|
||||
// Q multiplies by zero and prints 0.
|
||||
23 0 0 CHJ
|
||||
23 0 0 CJ
|
||||
23 1 23
|
||||
23 12 276
|
||||
-23 12 -276
|
||||
|
@ -599,12 +595,12 @@ begin
|
|||
currency currencyUsage toPattern breaks
|
||||
// These work in J, but it prepends an extra hash sign to the pattern.
|
||||
// K does not support this feature.
|
||||
USD standard 0.00 HK
|
||||
CHF standard 0.00 HK
|
||||
CZK standard 0.00 HK
|
||||
USD cash 0.00 HK
|
||||
CHF cash 0.05 HK
|
||||
CZK cash 0 HK
|
||||
USD standard 0.00 K
|
||||
CHF standard 0.00 K
|
||||
CZK standard 0.00 K
|
||||
USD cash 0.00 K
|
||||
CHF cash 0.05 K
|
||||
CZK cash 0 K
|
||||
|
||||
test currency rounding
|
||||
set locale en
|
||||
|
@ -688,7 +684,7 @@ Inf [\u221e]
|
|||
-Inf (\u221e) K
|
||||
// J does not print the affixes
|
||||
// K prints \uFFFD
|
||||
NaN [NaN] HK
|
||||
NaN [NaN] K
|
||||
|
||||
test nan and infinity with multiplication
|
||||
set locale en
|
||||
|
@ -711,10 +707,10 @@ Inf beforeSuffix $$$\u221e $ K
|
|||
Inf afterSuffix $$$\u221e$ K
|
||||
// J does not print the affixes
|
||||
// K prints \uFFFD
|
||||
NaN beforePrefix $$$NaN$ HK
|
||||
NaN afterPrefix $$$ NaN$ HK
|
||||
NaN beforeSuffix $$$NaN $ HK
|
||||
NaN afterSuffix $$$NaN$ HK
|
||||
NaN beforePrefix $$$NaN$ K
|
||||
NaN afterPrefix $$$ NaN$ K
|
||||
NaN beforeSuffix $$$NaN $ K
|
||||
NaN afterSuffix $$$NaN$ K
|
||||
|
||||
test apply formerly localized patterns
|
||||
begin
|
||||
|
@ -742,8 +738,7 @@ begin
|
|||
pattern toPattern breaks
|
||||
// All of the C and S failures in this section are because of functionally equivalent patterns
|
||||
// JDK doesn't support any patterns with padding or both negative prefix and suffix
|
||||
// Breaks ICU4J See ticket 11671
|
||||
**0,000 **0,000 HK
|
||||
**0,000 **0,000 K
|
||||
**##0,000 **##0,000 K
|
||||
**###0,000 **###0,000 K
|
||||
**####0,000 **#,##0,000 CJKP
|
||||
|
@ -783,25 +778,24 @@ parse output breaks
|
|||
+5347,,, 5347
|
||||
+5347,,,d8 5347
|
||||
(5,347.25) -5347.25
|
||||
// H requires prefix and suffix for lenient parsing, but C doesn't
|
||||
5,347.25 5347.25 HK
|
||||
(5,347.25 -5347.25 H
|
||||
5,347.25 5347.25 K
|
||||
(5,347.25 -5347.25
|
||||
// S is successful at parsing this as -5347.25 in lenient mode
|
||||
-5,347.25 -5347.25 HK
|
||||
-5,347.25 -5347.25 K
|
||||
+3.52E4 35200
|
||||
(34.8E-3) -0.0348
|
||||
// JDK stops parsing at the spaces. JDK doesn't see space as a grouping separator
|
||||
(34 25E-1) -342.5 K
|
||||
(34,,25E-1) -342.5
|
||||
// Trailing grouping separators are not OK.
|
||||
// H fails; C/J/P stop at the offending separator.
|
||||
// C/J/P stop at the offending separator.
|
||||
(34,,25,E-1) fail CJKP
|
||||
(34,,25,E-1) -3425 HK
|
||||
(34 25 E-1) -342.5 HK
|
||||
(34,,25 E-1) -342.5 HK
|
||||
(34,,25,E-1) -3425 K
|
||||
(34 25 E-1) -342.5 K
|
||||
(34,,25 E-1) -342.5 K
|
||||
// Spaces are not allowed after exponent symbol
|
||||
// C parses up to the E but H bails
|
||||
(34 25E -1) -3425 HK
|
||||
// C parses up to the E
|
||||
(34 25E -1) -3425 K
|
||||
+3.52EE4 3.52
|
||||
+1,234,567.8901 1234567.8901
|
||||
+1,23,4567.8901 1234567.8901
|
||||
|
@ -818,29 +812,21 @@ parse output breaks
|
|||
+ 79 79 K
|
||||
+,79,,20,33 792033
|
||||
+7920d3 7920
|
||||
// Whitespace immediately after prefix doesn't count as digit separator
|
||||
// in C but is does in H
|
||||
+ ,79,,20,33 792033 HK
|
||||
// Whitespace immediately after prefix doesn't count as digit separator in C
|
||||
+ ,79,,20,33 792033 K
|
||||
( 19 45) -1945 K
|
||||
// C allows trailing separators when there is a prefix and suffix.
|
||||
// H allows trailing separators only when there is just a prefix.
|
||||
// In this case, H just bails
|
||||
( 19 45 ) -1945 HK
|
||||
( 19 45 ) -1945 K
|
||||
(,,19,45) -1945
|
||||
// C parses to the space, but H bails
|
||||
(,,19 45) -19 H
|
||||
// H bails b/c comma different separator than space. C doesn't treat leading spaces
|
||||
// as a separator.
|
||||
( 19,45) -1945 HK
|
||||
// H bails. Doesn't allow trailing separators when there is prefix and suffix.
|
||||
(,,19,45,) -1945 H
|
||||
// H bails on next 4 because H doesn't allow letters inside prefix and suffix.
|
||||
// C parses to the spaces
|
||||
(,,19 45) -19
|
||||
( 19,45) -1945 K
|
||||
(,,19,45,) -1945
|
||||
// C will parse up to the letter.
|
||||
(,,19,45,d1) -1945 H
|
||||
(,,19,45d1) -1945 H
|
||||
( 19 45 d1) -1945 HK
|
||||
( 19 45d1) -1945 HK
|
||||
// H does allow trailing separator before a decimal point
|
||||
(,,19,45,d1) -1945
|
||||
(,,19,45d1) -1945
|
||||
( 19 45 d1) -1945 K
|
||||
( 19 45d1) -1945 K
|
||||
(19,45,.25) -1945.25
|
||||
// 2nd decimal points are ignored
|
||||
+4.12.926 4.12
|
||||
|
@ -851,18 +837,16 @@ set pattern #,##0.0###+;#-
|
|||
begin
|
||||
parse output breaks
|
||||
// J and K just bail.
|
||||
3426 3426 HK
|
||||
3426 3426 K
|
||||
3426+ 3426
|
||||
// J bails; K sees -34
|
||||
34 d1+ 34 HK
|
||||
34 d1+ 34 K
|
||||
// JDK sees this as -1234 for some reason
|
||||
// H bails b/c of trailing separators
|
||||
1,234,,,+ 1234 HK
|
||||
1,234,,,+ 1234 K
|
||||
1,234- -1234
|
||||
// H, C, and P bail because of trailing separators
|
||||
1,234,- -1234 CHJP
|
||||
// J bails here too
|
||||
1234 - -1234 H
|
||||
// C and P bail because of trailing separators
|
||||
1,234,- -1234 CJP
|
||||
1234 - -1234
|
||||
|
||||
|
||||
|
||||
|
@ -888,8 +872,7 @@ parse output breaks
|
|||
(3425E-1) -342.5
|
||||
// Strict doesn't allow separators in sci notation.
|
||||
(63,425) -63425
|
||||
// H does not allow grouping separators in scientific notation.
|
||||
(63,425E-1) -6342.5 H
|
||||
(63,425E-1) -6342.5
|
||||
// Both prefix and suffix needed for strict.
|
||||
// JDK accepts this and parses as -342.5
|
||||
(3425E-1 fail K
|
||||
|
@ -913,8 +896,7 @@ parse output breaks
|
|||
+1,234.5 1234.5
|
||||
// Comma after decimal means parse to a comma
|
||||
+1,23,456.78,9 123456.78
|
||||
// H fails upon seeing the second decimal point
|
||||
+1,23,456.78.9 123456.78 H
|
||||
+1,23,456.78.9 123456.78
|
||||
+79 79
|
||||
+79 79
|
||||
+ 79 fail
|
||||
|
@ -952,8 +934,7 @@ set parseIntegerOnly 1
|
|||
begin
|
||||
parse output breaks
|
||||
35 35
|
||||
// S accepts leading plus signs
|
||||
+35 35 HK
|
||||
+35 35 K
|
||||
-35 -35
|
||||
2.63 2
|
||||
-39.99 -39
|
||||
|
@ -967,8 +948,8 @@ parseNoExponent parse output breaks
|
|||
0 5e2 500 K
|
||||
0 5.3E2 530
|
||||
// See ticket 11725
|
||||
1 5e2 5 H
|
||||
1 5.3E2 5.3 HK
|
||||
1 5e2 5
|
||||
1 5.3E2 5.3 K
|
||||
|
||||
test parse currency fail
|
||||
set pattern 0
|
||||
|
@ -1006,8 +987,8 @@ begin
|
|||
parse output breaks
|
||||
// A non-greedy parse is required to pass these cases.
|
||||
// All of the implementations being tested are greedy.
|
||||
6549K 654 CHJKP
|
||||
6549N -654 CHJKP
|
||||
6549K 654 CJKP
|
||||
6549N -654 CJKP
|
||||
|
||||
test really strange prefix
|
||||
set locale en
|
||||
|
@ -1076,41 +1057,41 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
US Dollars (53.45) -53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
US Dollars (53.45) -53.45 USD
|
||||
(53.45) US Dollars -53.45 USD
|
||||
(53.45) Euros -53.45 EUR
|
||||
US Dollar (53.45) -53.45 USD H
|
||||
US Dollar (53.45) -53.45 USD
|
||||
(53.45) US Dollar -53.45 USD
|
||||
US Dollars(53.45) -53.45 USD H
|
||||
(53.45)US Dollars -53.45 USD H
|
||||
US Dollar(53.45) -53.45 USD H
|
||||
US Dollars(53.45) -53.45 USD
|
||||
(53.45)US Dollars -53.45 USD
|
||||
US Dollar(53.45) -53.45 USD
|
||||
US Dollat(53.45) fail USD
|
||||
(53.45)US Dollar -53.45 USD H
|
||||
(53.45)US Dollar -53.45 USD
|
||||
|
||||
|
||||
test parse currency ISO negative
|
||||
|
@ -1123,27 +1104,27 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
-7.92 USD -7.92 USD
|
||||
-7.92 GBP -7.92 GBP
|
||||
-7.926 USD -7.926 USD
|
||||
USD -7.926 -7.926 USD H
|
||||
-7.92USD -7.92 USD H
|
||||
USD-7.92 -7.92 USD H
|
||||
USD -7.926 -7.926 USD
|
||||
-7.92USD -7.92 USD
|
||||
USD-7.92 -7.92 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency long
|
||||
|
@ -1151,38 +1132,36 @@ set pattern 0.00 \u00a4\u00a4\u00a4;(#) \u00a4\u00a4\u00a4
|
|||
set locale en_GB
|
||||
begin
|
||||
parse output outputCurrency breaks
|
||||
// H throws a NullPointerException on the first case
|
||||
53.45 fail GBP
|
||||
£53.45 53.45 GBP
|
||||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
// H throws a NullPointerException on the next case
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency short
|
||||
|
@ -1195,31 +1174,31 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency short prefix
|
||||
|
@ -1232,31 +1211,31 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
// C and P fail these because '(' is an incomplete prefix.
|
||||
(7.92) USD -7.92 USD CHJP
|
||||
(7.92) GBP -7.92 GBP CHJP
|
||||
(7.926) USD -7.926 USD CHJP
|
||||
(7.926 USD) -7.926 USD CHJP
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD CHJP
|
||||
USD (7.92) -7.92 USD CHJP
|
||||
(7.92)USD -7.92 USD CHJP
|
||||
USD(7.92) -7.92 USD CHJP
|
||||
(8) USD -8 USD CHJP
|
||||
(7.92) USD -7.92 USD CJP
|
||||
(7.92) GBP -7.92 GBP CJP
|
||||
(7.926) USD -7.926 USD CJP
|
||||
(7.926 USD) -7.926 USD CJP
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD CJP
|
||||
USD (7.92) -7.92 USD CJP
|
||||
(7.92)USD -7.92 USD CJP
|
||||
USD(7.92) -7.92 USD CJP
|
||||
(8) USD -8 USD CJP
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
test format foreign currency
|
||||
set locale fa_IR
|
||||
|
@ -1371,7 +1350,7 @@ USD (7.92) fail USD
|
|||
(7.92)USD fail USD
|
||||
USD(7.92) fail USD
|
||||
(8) USD -8 USD
|
||||
-8 USD fail USD H
|
||||
-8 USD fail USD
|
||||
67 USD 67 USD
|
||||
53.45$ fail USD
|
||||
US Dollars 53.45 fail USD
|
||||
|
@ -1400,7 +1379,7 @@ set minFractionDigits 0
|
|||
set maxFractionDigits 0
|
||||
begin
|
||||
format output breaks
|
||||
-0.99 -0 HK
|
||||
-0.99 -0 K
|
||||
|
||||
test parse decimalPatternMatchRequired
|
||||
set locale en
|
||||
|
@ -1409,11 +1388,11 @@ begin
|
|||
pattern parse output breaks
|
||||
// K doesn't support this feature.
|
||||
0 123 123
|
||||
0 123. fail HK
|
||||
0 1.23 fail HK
|
||||
0 123. fail K
|
||||
0 1.23 fail K
|
||||
0 -513 -513
|
||||
0 -513. fail HK
|
||||
0 -5.13 fail HK
|
||||
0 -513. fail K
|
||||
0 -5.13 fail K
|
||||
0.0 123 fail K
|
||||
0.0 123. 123
|
||||
0.0 1.23 1.23
|
||||
|
@ -1427,13 +1406,13 @@ set pattern #
|
|||
begin
|
||||
pattern parse output breaks
|
||||
# -123 -123
|
||||
# - 123 -123 HK
|
||||
# -123 -123 HK
|
||||
# - 123 -123 HK
|
||||
# - 123 -123 K
|
||||
# -123 -123 K
|
||||
# - 123 -123 K
|
||||
# 123- 123
|
||||
# 123 - 123
|
||||
#;#- 123- -123
|
||||
#;#- 123 - -123 HK
|
||||
#;#- 123 - -123 K
|
||||
|
||||
test parse case sensitive
|
||||
set locale en
|
||||
|
@ -1444,19 +1423,18 @@ parse parseCaseSensitive output breaks
|
|||
Aa1.23 1 1.23
|
||||
Aa1.23 0 1.23
|
||||
AA1.23 1 fail
|
||||
// H and K do not support case-insensitive parsing for prefix/suffix.
|
||||
// H supports it for the exponent separator, but not K.
|
||||
AA1.23 0 1.23 HK
|
||||
// K does not support case-insensitive parsing for prefix/suffix.
|
||||
AA1.23 0 1.23 K
|
||||
aa1.23 1 fail
|
||||
aa1.23 0 1.23 HK
|
||||
aa1.23 0 1.23 K
|
||||
Aa1.23E3 1 1230
|
||||
Aa1.23E3 0 1230
|
||||
Aa1.23e3 1 1.23 H
|
||||
Aa1.23e3 1 1.23
|
||||
Aa1.23e3 0 1230 K
|
||||
NaN 1 NaN K
|
||||
NaN 0 NaN K
|
||||
nan 1 fail
|
||||
nan 0 NaN HK
|
||||
nan 0 NaN K
|
||||
|
||||
test parse infinity and scientific notation overflow
|
||||
set locale en
|
||||
|
@ -1472,13 +1450,13 @@ NaN NaN K
|
|||
-1E-99999999999999 -0.0
|
||||
1E2147483648 Inf K
|
||||
1E2147483647 Inf K
|
||||
// H, J and K get Infinity
|
||||
1E2147483646 1E+2147483646 HJK
|
||||
// J and K get Infinity
|
||||
1E2147483646 1E+2147483646 JK
|
||||
1E-2147483649 0
|
||||
1E-2147483648 0
|
||||
// H and K return zero here
|
||||
1E-2147483647 1E-2147483647 HJK
|
||||
1E-2147483646 1E-2147483646 HJK
|
||||
// K returns zero here
|
||||
1E-2147483647 1E-2147483647 JK
|
||||
1E-2147483646 1E-2147483646 JK
|
||||
|
||||
test format push limits
|
||||
set locale en
|
||||
|
@ -1506,13 +1484,13 @@ begin
|
|||
pattern lenient parse output breaks
|
||||
// Groups after the first group need 2 digits to be accepted.
|
||||
// JDK does not see space as grouping and parses most of these as 9.
|
||||
#,##0 1 9 9 9 H
|
||||
#,##0 1 9 9 9
|
||||
#,##0 1 9 99 999 K
|
||||
#,##0 1 9 999 9999 K
|
||||
#,##0 1 9 9 9 9 H
|
||||
#,##0 1 9 9 9 9
|
||||
#,##0 1 ,9 9
|
||||
#,##0 1 99,.0 99
|
||||
#,##0 1 9 9. 9 H
|
||||
#,##0 1 9 9. 9
|
||||
#,##0 1 9 99. 999 K
|
||||
0 1 9 9 9
|
||||
0 1 9 99 9
|
||||
|
@ -1559,36 +1537,36 @@ parse output breaks
|
|||
x ab56c df 56
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 HK
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 K
|
||||
x ab56 56 HK
|
||||
x a b56 56 HK
|
||||
56cdf 56 HK
|
||||
56c df 56 HK
|
||||
56cd f 56 HK
|
||||
56cdf 56 HK
|
||||
56cdf 56 HK
|
||||
56c df 56 HK
|
||||
56c df 56 HK
|
||||
x ab56 56 K
|
||||
x a b56 56 K
|
||||
56cdf 56 K
|
||||
56c df 56 K
|
||||
56cd f 56 K
|
||||
56cdf 56 K
|
||||
56cdf 56 K
|
||||
56c df 56 K
|
||||
56c df 56 K
|
||||
y gh56i jk -56
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 HK
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 K
|
||||
y gh56 -56 HK
|
||||
y g h56 -56 HK
|
||||
y gh56 -56 K
|
||||
y g h56 -56 K
|
||||
// S stops parsing after the 'i' for these and returns -56
|
||||
// C stops before the 'i' and gets 56
|
||||
56ijk -56 HK
|
||||
56i jk -56 HK
|
||||
56ij k -56 HK
|
||||
56ijk -56 HK
|
||||
56ijk -56 HK
|
||||
56i jk -56 HK
|
||||
56i jk -56 HK
|
||||
// S and C get 56 (accepts ' ' gs grouping); H and K get null
|
||||
56ijk -56 K
|
||||
56i jk -56 K
|
||||
56ij k -56 K
|
||||
56ijk -56 K
|
||||
56ijk -56 K
|
||||
56i jk -56 K
|
||||
56i jk -56 K
|
||||
// S and C get 56 (accepts ' ' gs grouping); K gets null
|
||||
5 6 fail CJP
|
||||
56 5 HK
|
||||
56 5 K
|
||||
|
||||
test parse spaces in grouping
|
||||
// This test gives the ideal behavior of these cases, which
|
||||
|
@ -1598,7 +1576,7 @@ set locale en
|
|||
set pattern #,##0
|
||||
begin
|
||||
parse output breaks
|
||||
1 2 1 H
|
||||
1 2 1
|
||||
1 23 123 K
|
||||
// K gets 1 here; doesn't pick up the grouping separator
|
||||
1 234 1234 K
|
||||
|
@ -1614,7 +1592,7 @@ format output breaks
|
|||
// C and J get "1"
|
||||
// P gets "1.0"
|
||||
// K gets "1.1" (??)
|
||||
0.975 0.98 CHJKP
|
||||
0.975 0.98 CJKP
|
||||
|
||||
test lenient parse currency match
|
||||
// This test is for #13112
|
||||
|
@ -1622,8 +1600,8 @@ set locale en
|
|||
set pattern ¤#,##0.00
|
||||
begin
|
||||
parse output breaks
|
||||
// H and K get null
|
||||
1.23!@#$%^ 1.23 HK
|
||||
// K gets null
|
||||
1.23!@#$%^ 1.23 K
|
||||
|
||||
test percentage parsing multiplier
|
||||
// This test is for #13114
|
||||
|
@ -1632,9 +1610,9 @@ set pattern 0%
|
|||
begin
|
||||
parse output breaks
|
||||
55% 0.55
|
||||
// H and K get null
|
||||
// K gets null
|
||||
// C and P scale by 100 even if the percent sign is not present
|
||||
55 0.55 HK
|
||||
55 0.55 K
|
||||
|
||||
test trailing grouping separators in pattern
|
||||
// This test is for #13115
|
||||
|
@ -1653,8 +1631,8 @@ begin
|
|||
pattern format output breaks
|
||||
0 -15 -15
|
||||
0; -15 -15
|
||||
// H and K still prepend a '-' even though the pattern says otherwise
|
||||
0;0 -15 15 HK
|
||||
// K still prepends a '-' even though the pattern says otherwise
|
||||
0;0 -15 15 K
|
||||
|
||||
test percentage multiplier parsing
|
||||
// This test is for #13129
|
||||
|
@ -1670,9 +1648,9 @@ set pattern 0
|
|||
set signAlwaysShown 1
|
||||
begin
|
||||
format output breaks
|
||||
// H and K do not support this feature
|
||||
42 +42 HK
|
||||
0 +0 HK
|
||||
// K does not support this feature
|
||||
42 +42 K
|
||||
0 +0 K
|
||||
-42 -42
|
||||
|
||||
test parse strict with plus sign
|
||||
|
@ -1683,14 +1661,14 @@ begin
|
|||
lenient parse output breaks
|
||||
1 42 42
|
||||
1 -42 -42
|
||||
1 +42 42 HK
|
||||
1 +42 42 K
|
||||
1 0 0
|
||||
1 +0 0 HK
|
||||
0 42 fail HK
|
||||
1 +0 0 K
|
||||
0 42 fail K
|
||||
0 -42 -42
|
||||
0 +42 42 HK
|
||||
0 0 fail HK
|
||||
0 +0 0 HK
|
||||
0 +42 42 K
|
||||
0 0 fail K
|
||||
0 +0 0 K
|
||||
|
||||
test parse with scientific-separator-affix overlap
|
||||
set locale en
|
||||
|
@ -1708,13 +1686,13 @@ set currency USD
|
|||
begin
|
||||
parse output breaks
|
||||
USD123 123
|
||||
USD 123 123 HK
|
||||
USD 123 123 K
|
||||
usd123 123 K
|
||||
usd 123 123 HK
|
||||
usd 123 123 K
|
||||
Usd123 123 K
|
||||
Usd 123 123 HK
|
||||
Usd 123 123 K
|
||||
// US$ is not used for US dollars in en-US
|
||||
US$123 fail H
|
||||
US$123 fail
|
||||
us$123 fail
|
||||
Us$123 fail
|
||||
123 US dollars 123 K
|
||||
|
@ -1733,11 +1711,11 @@ set currency USD
|
|||
begin
|
||||
parse output outputCurrency breaks
|
||||
USD123 123 USD
|
||||
USD 123 123 USD H
|
||||
USD 123 123 USD
|
||||
usd123 123 USD
|
||||
usd 123 123 USD H
|
||||
usd 123 123 USD
|
||||
Usd123 123 USD
|
||||
Usd 123 123 USD H
|
||||
Usd 123 123 USD
|
||||
US$123 123 USD C
|
||||
us$123 fail fail
|
||||
Us$123 fail fail
|
||||
|
@ -1746,16 +1724,16 @@ Us$123 fail fail
|
|||
123 us dollars 123 USD
|
||||
GBP123 123 GBP
|
||||
gbp123 123 GBP C
|
||||
British pounds 123 123 GBP H
|
||||
british POUNDS 123 123 GBP H
|
||||
British pounds 123 123 GBP
|
||||
british POUNDS 123 123 GBP
|
||||
|
||||
test parse scientific with bidi marks
|
||||
begin
|
||||
locale parse output breaks
|
||||
en 4E\u200E+02 400 HK
|
||||
en 4E\u200E+02 400 K
|
||||
en 4E+02 400 K
|
||||
he 4E\u200E+02 400 K
|
||||
he 4E+02 400 HK
|
||||
he 4E+02 400 K
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
// per line.
|
||||
//
|
||||
// Field names:
|
||||
// H = ICU4J 58 (archive)
|
||||
// J = ICU4J (current)
|
||||
// K = JDK (ignored if not OpenJDK 1.8)
|
||||
// C = ICU4C (current)
|
||||
|
@ -25,7 +24,7 @@ set locale ar-EG
|
|||
set pattern +0;-#
|
||||
begin
|
||||
format output breaks
|
||||
6 \u061C+\u0666 HK
|
||||
6 \u061C+\u0666 K
|
||||
-6 \u061C-\u0666 K
|
||||
|
||||
test basic patterns
|
||||
|
@ -188,7 +187,7 @@ pattern format output breaks
|
|||
// JDK gives 12,3001E3
|
||||
##0.000#E0 12300.1 12,30E3 K
|
||||
##0.000#E0 12301 12,301E3
|
||||
0.05E0 12301.2 1,25E4 HK
|
||||
0.05E0 12301.2 1,25E4 K
|
||||
##0.000#E0 0.17 170,0E-3
|
||||
// JDK doesn't support significant digits in exponents
|
||||
@@@E0 6.235 6,24E0 K
|
||||
|
@ -270,17 +269,16 @@ $**####,##0 1234 $***1\u202f234 K
|
|||
####,##0$*x;n#'*' -1234 n1\u202f234*xx K
|
||||
*y%4.2###### 4.33 yyyy%432,6 K
|
||||
// In J ICU adds padding as if 'EUR' is only 2 chars (2 * 0xa4)
|
||||
\u00a4\u00a4 **####0.00 433.0 EUR *433,00 HK
|
||||
// In H ICU adds padding as if 'EUR' is only 2 chars (2 * 0xa4)
|
||||
\u00a4\u00a4 **####0.00 433.0 EUR *433,00 K
|
||||
// P fails this one because the test code bypasses CurrencyUsage
|
||||
\u00a4\u00a4 **#######0 433.0 EUR *433,00 HKP
|
||||
\u00a4\u00a4 **#######0 433.0 EUR *433,00 KP
|
||||
|
||||
test padding and currencies
|
||||
begin
|
||||
locale currency pattern format output breaks
|
||||
// In J, JPY is considered 2 char (2 * 0xa4) even though padding is done
|
||||
// after prefix. In C this test works.
|
||||
fr JPY \u00a4\u00a4 **#######0 433.22 JPY ****433 HK
|
||||
fr JPY \u00a4\u00a4 **#######0 433.22 JPY ****433 K
|
||||
// JDK doesn't correct rounding for currency, shows USD (433
|
||||
en USD \u00a4\u00a4 **#######0;\u00a4\u00a4 (#) -433.22 USD (433.22) K
|
||||
|
||||
|
@ -310,9 +308,7 @@ set pattern #,##0
|
|||
set minGroupingDigits 2
|
||||
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 HK
|
||||
1000 1000 K
|
||||
10000 10,000
|
||||
100000 100,000
|
||||
1000000 1,000,000
|
||||
|
@ -351,7 +347,7 @@ minIntegerDigits maxIntegerDigits minFractionDigits maxFractionDigits output bre
|
|||
// JDK gives E0 instead of allowing for unlimited precision
|
||||
0 0 0 0 2.99792458E8 K
|
||||
// J gives 2.9979E8
|
||||
0 1 0 5 2.99792E8 HK
|
||||
0 1 0 5 2.99792E8 K
|
||||
// JDK gives 300E6
|
||||
0 3 0 0 299.792458E6 K
|
||||
// JDK gives 299.8E6 (maybe maxInt + maxFrac instead of minInt + maxFrac)?
|
||||
|
@ -368,7 +364,7 @@ minIntegerDigits maxIntegerDigits minFractionDigits maxFractionDigits output bre
|
|||
// JDK gives E0
|
||||
0 0 1 0 2.99792458E8 K
|
||||
// J gives 2.998E8
|
||||
0 0 0 4 .29979E9 HK
|
||||
0 0 0 4 .29979E9 K
|
||||
// According to the spec, if maxInt>minInt and minInt>1, then set
|
||||
// Context: #13289
|
||||
2 8 1 6 2.9979246E8 K
|
||||
|
@ -423,7 +419,7 @@ begin
|
|||
format maxIntegerDigits output breaks
|
||||
123 1 3
|
||||
// C obeys maxIntegerDigits and prints after the decimal place
|
||||
0 0 .0 HKP
|
||||
0 0 .0 KP
|
||||
// CJP ignore max integer if it is less than zero and prints "123"
|
||||
123 -2147483648 0 CJP
|
||||
12345 1 5
|
||||
|
@ -516,7 +512,7 @@ begin
|
|||
output grouping grouping2 minGroupingDigits breaks
|
||||
1,23,45,6789 4 2 2 K
|
||||
123,456789 6 6 3
|
||||
123456789 6 6 4 HK
|
||||
123456789 6 6 4 K
|
||||
|
||||
test multiplier setters
|
||||
set locale en_US
|
||||
|
@ -524,10 +520,10 @@ begin
|
|||
format multiplier output breaks
|
||||
23 -12 -276
|
||||
23 -1 -23
|
||||
// H (ICU4J 58) and J (current ICU4J) throw exception on zero multiplier.
|
||||
// J (current ICU4J) throws exception on zero multiplier.
|
||||
// ICU4C prints 23.
|
||||
// Q multiplies by zero and prints 0.
|
||||
23 0 0 CHJ
|
||||
23 0 0 CJ
|
||||
23 1 23
|
||||
23 12 276
|
||||
-23 12 -276
|
||||
|
@ -599,12 +595,12 @@ begin
|
|||
currency currencyUsage toPattern breaks
|
||||
// These work in J, but it prepends an extra hash sign to the pattern.
|
||||
// K does not support this feature.
|
||||
USD standard 0.00 HK
|
||||
CHF standard 0.00 HK
|
||||
CZK standard 0.00 HK
|
||||
USD cash 0.00 HK
|
||||
CHF cash 0.05 HK
|
||||
CZK cash 0 HK
|
||||
USD standard 0.00 K
|
||||
CHF standard 0.00 K
|
||||
CZK standard 0.00 K
|
||||
USD cash 0.00 K
|
||||
CHF cash 0.05 K
|
||||
CZK cash 0 K
|
||||
|
||||
test currency rounding
|
||||
set locale en
|
||||
|
@ -688,7 +684,7 @@ Inf [\u221e]
|
|||
-Inf (\u221e) K
|
||||
// J does not print the affixes
|
||||
// K prints \uFFFD
|
||||
NaN [NaN] HK
|
||||
NaN [NaN] K
|
||||
|
||||
test nan and infinity with multiplication
|
||||
set locale en
|
||||
|
@ -711,10 +707,10 @@ Inf beforeSuffix $$$\u221e $ K
|
|||
Inf afterSuffix $$$\u221e$ K
|
||||
// J does not print the affixes
|
||||
// K prints \uFFFD
|
||||
NaN beforePrefix $$$NaN$ HK
|
||||
NaN afterPrefix $$$ NaN$ HK
|
||||
NaN beforeSuffix $$$NaN $ HK
|
||||
NaN afterSuffix $$$NaN$ HK
|
||||
NaN beforePrefix $$$NaN$ K
|
||||
NaN afterPrefix $$$ NaN$ K
|
||||
NaN beforeSuffix $$$NaN $ K
|
||||
NaN afterSuffix $$$NaN$ K
|
||||
|
||||
test apply formerly localized patterns
|
||||
begin
|
||||
|
@ -742,8 +738,7 @@ begin
|
|||
pattern toPattern breaks
|
||||
// All of the C and S failures in this section are because of functionally equivalent patterns
|
||||
// JDK doesn't support any patterns with padding or both negative prefix and suffix
|
||||
// Breaks ICU4J See ticket 11671
|
||||
**0,000 **0,000 HK
|
||||
**0,000 **0,000 K
|
||||
**##0,000 **##0,000 K
|
||||
**###0,000 **###0,000 K
|
||||
**####0,000 **#,##0,000 CJKP
|
||||
|
@ -783,25 +778,24 @@ parse output breaks
|
|||
+5347,,, 5347
|
||||
+5347,,,d8 5347
|
||||
(5,347.25) -5347.25
|
||||
// H requires prefix and suffix for lenient parsing, but C doesn't
|
||||
5,347.25 5347.25 HK
|
||||
(5,347.25 -5347.25 H
|
||||
5,347.25 5347.25 K
|
||||
(5,347.25 -5347.25
|
||||
// S is successful at parsing this as -5347.25 in lenient mode
|
||||
-5,347.25 -5347.25 HK
|
||||
-5,347.25 -5347.25 K
|
||||
+3.52E4 35200
|
||||
(34.8E-3) -0.0348
|
||||
// JDK stops parsing at the spaces. JDK doesn't see space as a grouping separator
|
||||
(34 25E-1) -342.5 K
|
||||
(34,,25E-1) -342.5
|
||||
// Trailing grouping separators are not OK.
|
||||
// H fails; C/J/P stop at the offending separator.
|
||||
// C/J/P stop at the offending separator.
|
||||
(34,,25,E-1) fail CJKP
|
||||
(34,,25,E-1) -3425 HK
|
||||
(34 25 E-1) -342.5 HK
|
||||
(34,,25 E-1) -342.5 HK
|
||||
(34,,25,E-1) -3425 K
|
||||
(34 25 E-1) -342.5 K
|
||||
(34,,25 E-1) -342.5 K
|
||||
// Spaces are not allowed after exponent symbol
|
||||
// C parses up to the E but H bails
|
||||
(34 25E -1) -3425 HK
|
||||
// C parses up to the E
|
||||
(34 25E -1) -3425 K
|
||||
+3.52EE4 3.52
|
||||
+1,234,567.8901 1234567.8901
|
||||
+1,23,4567.8901 1234567.8901
|
||||
|
@ -818,29 +812,21 @@ parse output breaks
|
|||
+ 79 79 K
|
||||
+,79,,20,33 792033
|
||||
+7920d3 7920
|
||||
// Whitespace immediately after prefix doesn't count as digit separator
|
||||
// in C but is does in H
|
||||
+ ,79,,20,33 792033 HK
|
||||
// Whitespace immediately after prefix doesn't count as digit separator in C
|
||||
+ ,79,,20,33 792033 K
|
||||
( 19 45) -1945 K
|
||||
// C allows trailing separators when there is a prefix and suffix.
|
||||
// H allows trailing separators only when there is just a prefix.
|
||||
// In this case, H just bails
|
||||
( 19 45 ) -1945 HK
|
||||
( 19 45 ) -1945 K
|
||||
(,,19,45) -1945
|
||||
// C parses to the space, but H bails
|
||||
(,,19 45) -19 H
|
||||
// H bails b/c comma different separator than space. C doesn't treat leading spaces
|
||||
// as a separator.
|
||||
( 19,45) -1945 HK
|
||||
// H bails. Doesn't allow trailing separators when there is prefix and suffix.
|
||||
(,,19,45,) -1945 H
|
||||
// H bails on next 4 because H doesn't allow letters inside prefix and suffix.
|
||||
// C parses to the spaces
|
||||
(,,19 45) -19
|
||||
( 19,45) -1945 K
|
||||
(,,19,45,) -1945
|
||||
// C will parse up to the letter.
|
||||
(,,19,45,d1) -1945 H
|
||||
(,,19,45d1) -1945 H
|
||||
( 19 45 d1) -1945 HK
|
||||
( 19 45d1) -1945 HK
|
||||
// H does allow trailing separator before a decimal point
|
||||
(,,19,45,d1) -1945
|
||||
(,,19,45d1) -1945
|
||||
( 19 45 d1) -1945 K
|
||||
( 19 45d1) -1945 K
|
||||
(19,45,.25) -1945.25
|
||||
// 2nd decimal points are ignored
|
||||
+4.12.926 4.12
|
||||
|
@ -851,18 +837,16 @@ set pattern #,##0.0###+;#-
|
|||
begin
|
||||
parse output breaks
|
||||
// J and K just bail.
|
||||
3426 3426 HK
|
||||
3426 3426 K
|
||||
3426+ 3426
|
||||
// J bails; K sees -34
|
||||
34 d1+ 34 HK
|
||||
34 d1+ 34 K
|
||||
// JDK sees this as -1234 for some reason
|
||||
// H bails b/c of trailing separators
|
||||
1,234,,,+ 1234 HK
|
||||
1,234,,,+ 1234 K
|
||||
1,234- -1234
|
||||
// H, C, and P bail because of trailing separators
|
||||
1,234,- -1234 CHJP
|
||||
// J bails here too
|
||||
1234 - -1234 H
|
||||
// C and P bail because of trailing separators
|
||||
1,234,- -1234 CJP
|
||||
1234 - -1234
|
||||
|
||||
|
||||
|
||||
|
@ -888,8 +872,7 @@ parse output breaks
|
|||
(3425E-1) -342.5
|
||||
// Strict doesn't allow separators in sci notation.
|
||||
(63,425) -63425
|
||||
// H does not allow grouping separators in scientific notation.
|
||||
(63,425E-1) -6342.5 H
|
||||
(63,425E-1) -6342.5
|
||||
// Both prefix and suffix needed for strict.
|
||||
// JDK accepts this and parses as -342.5
|
||||
(3425E-1 fail K
|
||||
|
@ -913,8 +896,7 @@ parse output breaks
|
|||
+1,234.5 1234.5
|
||||
// Comma after decimal means parse to a comma
|
||||
+1,23,456.78,9 123456.78
|
||||
// H fails upon seeing the second decimal point
|
||||
+1,23,456.78.9 123456.78 H
|
||||
+1,23,456.78.9 123456.78
|
||||
+79 79
|
||||
+79 79
|
||||
+ 79 fail
|
||||
|
@ -952,8 +934,7 @@ set parseIntegerOnly 1
|
|||
begin
|
||||
parse output breaks
|
||||
35 35
|
||||
// S accepts leading plus signs
|
||||
+35 35 HK
|
||||
+35 35 K
|
||||
-35 -35
|
||||
2.63 2
|
||||
-39.99 -39
|
||||
|
@ -967,8 +948,8 @@ parseNoExponent parse output breaks
|
|||
0 5e2 500 K
|
||||
0 5.3E2 530
|
||||
// See ticket 11725
|
||||
1 5e2 5 H
|
||||
1 5.3E2 5.3 HK
|
||||
1 5e2 5
|
||||
1 5.3E2 5.3 K
|
||||
|
||||
test parse currency fail
|
||||
set pattern 0
|
||||
|
@ -1006,8 +987,8 @@ begin
|
|||
parse output breaks
|
||||
// A non-greedy parse is required to pass these cases.
|
||||
// All of the implementations being tested are greedy.
|
||||
6549K 654 CHJKP
|
||||
6549N -654 CHJKP
|
||||
6549K 654 CJKP
|
||||
6549N -654 CJKP
|
||||
|
||||
test really strange prefix
|
||||
set locale en
|
||||
|
@ -1076,41 +1057,41 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
US Dollars (53.45) -53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
US Dollars (53.45) -53.45 USD
|
||||
(53.45) US Dollars -53.45 USD
|
||||
(53.45) Euros -53.45 EUR
|
||||
US Dollar (53.45) -53.45 USD H
|
||||
US Dollar (53.45) -53.45 USD
|
||||
(53.45) US Dollar -53.45 USD
|
||||
US Dollars(53.45) -53.45 USD H
|
||||
(53.45)US Dollars -53.45 USD H
|
||||
US Dollar(53.45) -53.45 USD H
|
||||
US Dollars(53.45) -53.45 USD
|
||||
(53.45)US Dollars -53.45 USD
|
||||
US Dollar(53.45) -53.45 USD
|
||||
US Dollat(53.45) fail USD
|
||||
(53.45)US Dollar -53.45 USD H
|
||||
(53.45)US Dollar -53.45 USD
|
||||
|
||||
|
||||
test parse currency ISO negative
|
||||
|
@ -1123,27 +1104,27 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
-7.92 USD -7.92 USD
|
||||
-7.92 GBP -7.92 GBP
|
||||
-7.926 USD -7.926 USD
|
||||
USD -7.926 -7.926 USD H
|
||||
-7.92USD -7.92 USD H
|
||||
USD-7.92 -7.92 USD H
|
||||
USD -7.926 -7.926 USD
|
||||
-7.92USD -7.92 USD
|
||||
USD-7.92 -7.92 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency long
|
||||
|
@ -1151,38 +1132,36 @@ set pattern 0.00 \u00a4\u00a4\u00a4;(#) \u00a4\u00a4\u00a4
|
|||
set locale en_GB
|
||||
begin
|
||||
parse output outputCurrency breaks
|
||||
// H throws a NullPointerException on the first case
|
||||
53.45 fail GBP
|
||||
£53.45 53.45 GBP
|
||||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
// H throws a NullPointerException on the next case
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency short
|
||||
|
@ -1195,31 +1174,31 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
(7.92) USD -7.92 USD
|
||||
(7.92) GBP -7.92 GBP
|
||||
(7.926) USD -7.926 USD
|
||||
(7.926 USD) -7.926 USD H
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD H
|
||||
USD (7.92) -7.92 USD H
|
||||
(7.92)USD -7.92 USD H
|
||||
USD(7.92) -7.92 USD H
|
||||
(7.926 USD) -7.926 USD
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD
|
||||
USD (7.92) -7.92 USD
|
||||
(7.92)USD -7.92 USD
|
||||
USD(7.92) -7.92 USD
|
||||
(8) USD -8 USD
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
US Dollat53.45 fail USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
|
||||
test parse currency short prefix
|
||||
|
@ -1232,31 +1211,31 @@ parse output outputCurrency breaks
|
|||
$53.45 53.45 USD C
|
||||
53.45 USD 53.45 USD
|
||||
53.45 GBP 53.45 GBP
|
||||
USD 53.45 53.45 USD H
|
||||
53.45USD 53.45 USD H
|
||||
USD 53.45 53.45 USD
|
||||
53.45USD 53.45 USD
|
||||
USD53.45 53.45 USD
|
||||
// C and P fail these because '(' is an incomplete prefix.
|
||||
(7.92) USD -7.92 USD CHJP
|
||||
(7.92) GBP -7.92 GBP CHJP
|
||||
(7.926) USD -7.926 USD CHJP
|
||||
(7.926 USD) -7.926 USD CHJP
|
||||
(USD 7.926) -7.926 USD H
|
||||
USD (7.926) -7.926 USD CHJP
|
||||
USD (7.92) -7.92 USD CHJP
|
||||
(7.92)USD -7.92 USD CHJP
|
||||
USD(7.92) -7.92 USD CHJP
|
||||
(8) USD -8 USD CHJP
|
||||
(7.92) USD -7.92 USD CJP
|
||||
(7.92) GBP -7.92 GBP CJP
|
||||
(7.926) USD -7.926 USD CJP
|
||||
(7.926 USD) -7.926 USD CJP
|
||||
(USD 7.926) -7.926 USD
|
||||
USD (7.926) -7.926 USD CJP
|
||||
USD (7.92) -7.92 USD CJP
|
||||
(7.92)USD -7.92 USD CJP
|
||||
USD(7.92) -7.92 USD CJP
|
||||
(8) USD -8 USD CJP
|
||||
-8 USD -8 USD
|
||||
67 USD 67 USD
|
||||
53.45$ 53.45 USD CH
|
||||
US Dollars 53.45 53.45 USD H
|
||||
53.45$ 53.45 USD C
|
||||
US Dollars 53.45 53.45 USD
|
||||
53.45 US Dollars 53.45 USD
|
||||
US Dollar 53.45 53.45 USD H
|
||||
US Dollar 53.45 53.45 USD
|
||||
53.45 US Dollar 53.45 USD
|
||||
US Dollars53.45 53.45 USD
|
||||
53.45US Dollars 53.45 USD H
|
||||
53.45US Dollars 53.45 USD
|
||||
US Dollar53.45 53.45 USD
|
||||
53.45US Dollar 53.45 USD H
|
||||
53.45US Dollar 53.45 USD
|
||||
|
||||
test format foreign currency
|
||||
set locale fa_IR
|
||||
|
@ -1371,7 +1350,7 @@ USD (7.92) fail USD
|
|||
(7.92)USD fail USD
|
||||
USD(7.92) fail USD
|
||||
(8) USD -8 USD
|
||||
-8 USD fail USD H
|
||||
-8 USD fail USD
|
||||
67 USD 67 USD
|
||||
53.45$ fail USD
|
||||
US Dollars 53.45 fail USD
|
||||
|
@ -1400,7 +1379,7 @@ set minFractionDigits 0
|
|||
set maxFractionDigits 0
|
||||
begin
|
||||
format output breaks
|
||||
-0.99 -0 HK
|
||||
-0.99 -0 K
|
||||
|
||||
test parse decimalPatternMatchRequired
|
||||
set locale en
|
||||
|
@ -1409,11 +1388,11 @@ begin
|
|||
pattern parse output breaks
|
||||
// K doesn't support this feature.
|
||||
0 123 123
|
||||
0 123. fail HK
|
||||
0 1.23 fail HK
|
||||
0 123. fail K
|
||||
0 1.23 fail K
|
||||
0 -513 -513
|
||||
0 -513. fail HK
|
||||
0 -5.13 fail HK
|
||||
0 -513. fail K
|
||||
0 -5.13 fail K
|
||||
0.0 123 fail K
|
||||
0.0 123. 123
|
||||
0.0 1.23 1.23
|
||||
|
@ -1427,13 +1406,13 @@ set pattern #
|
|||
begin
|
||||
pattern parse output breaks
|
||||
# -123 -123
|
||||
# - 123 -123 HK
|
||||
# -123 -123 HK
|
||||
# - 123 -123 HK
|
||||
# - 123 -123 K
|
||||
# -123 -123 K
|
||||
# - 123 -123 K
|
||||
# 123- 123
|
||||
# 123 - 123
|
||||
#;#- 123- -123
|
||||
#;#- 123 - -123 HK
|
||||
#;#- 123 - -123 K
|
||||
|
||||
test parse case sensitive
|
||||
set locale en
|
||||
|
@ -1444,19 +1423,18 @@ parse parseCaseSensitive output breaks
|
|||
Aa1.23 1 1.23
|
||||
Aa1.23 0 1.23
|
||||
AA1.23 1 fail
|
||||
// H and K do not support case-insensitive parsing for prefix/suffix.
|
||||
// H supports it for the exponent separator, but not K.
|
||||
AA1.23 0 1.23 HK
|
||||
// K does not support case-insensitive parsing for prefix/suffix.
|
||||
AA1.23 0 1.23 K
|
||||
aa1.23 1 fail
|
||||
aa1.23 0 1.23 HK
|
||||
aa1.23 0 1.23 K
|
||||
Aa1.23E3 1 1230
|
||||
Aa1.23E3 0 1230
|
||||
Aa1.23e3 1 1.23 H
|
||||
Aa1.23e3 1 1.23
|
||||
Aa1.23e3 0 1230 K
|
||||
NaN 1 NaN K
|
||||
NaN 0 NaN K
|
||||
nan 1 fail
|
||||
nan 0 NaN HK
|
||||
nan 0 NaN K
|
||||
|
||||
test parse infinity and scientific notation overflow
|
||||
set locale en
|
||||
|
@ -1472,13 +1450,13 @@ NaN NaN K
|
|||
-1E-99999999999999 -0.0
|
||||
1E2147483648 Inf K
|
||||
1E2147483647 Inf K
|
||||
// H, J and K get Infinity
|
||||
1E2147483646 1E+2147483646 HJK
|
||||
// J and K get Infinity
|
||||
1E2147483646 1E+2147483646 JK
|
||||
1E-2147483649 0
|
||||
1E-2147483648 0
|
||||
// H and K return zero here
|
||||
1E-2147483647 1E-2147483647 HJK
|
||||
1E-2147483646 1E-2147483646 HJK
|
||||
// K returns zero here
|
||||
1E-2147483647 1E-2147483647 JK
|
||||
1E-2147483646 1E-2147483646 JK
|
||||
|
||||
test format push limits
|
||||
set locale en
|
||||
|
@ -1506,13 +1484,13 @@ begin
|
|||
pattern lenient parse output breaks
|
||||
// Groups after the first group need 2 digits to be accepted.
|
||||
// JDK does not see space as grouping and parses most of these as 9.
|
||||
#,##0 1 9 9 9 H
|
||||
#,##0 1 9 9 9
|
||||
#,##0 1 9 99 999 K
|
||||
#,##0 1 9 999 9999 K
|
||||
#,##0 1 9 9 9 9 H
|
||||
#,##0 1 9 9 9 9
|
||||
#,##0 1 ,9 9
|
||||
#,##0 1 99,.0 99
|
||||
#,##0 1 9 9. 9 H
|
||||
#,##0 1 9 9. 9
|
||||
#,##0 1 9 99. 999 K
|
||||
0 1 9 9 9
|
||||
0 1 9 99 9
|
||||
|
@ -1559,36 +1537,36 @@ parse output breaks
|
|||
x ab56c df 56
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 HK
|
||||
x ab56c df 56 K
|
||||
x ab56c df 56 K
|
||||
x ab56 56 HK
|
||||
x a b56 56 HK
|
||||
56cdf 56 HK
|
||||
56c df 56 HK
|
||||
56cd f 56 HK
|
||||
56cdf 56 HK
|
||||
56cdf 56 HK
|
||||
56c df 56 HK
|
||||
56c df 56 HK
|
||||
x ab56 56 K
|
||||
x a b56 56 K
|
||||
56cdf 56 K
|
||||
56c df 56 K
|
||||
56cd f 56 K
|
||||
56cdf 56 K
|
||||
56cdf 56 K
|
||||
56c df 56 K
|
||||
56c df 56 K
|
||||
y gh56i jk -56
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 HK
|
||||
y gh56i jk -56 K
|
||||
y gh56i jk -56 K
|
||||
y gh56 -56 HK
|
||||
y g h56 -56 HK
|
||||
y gh56 -56 K
|
||||
y g h56 -56 K
|
||||
// S stops parsing after the 'i' for these and returns -56
|
||||
// C stops before the 'i' and gets 56
|
||||
56ijk -56 HK
|
||||
56i jk -56 HK
|
||||
56ij k -56 HK
|
||||
56ijk -56 HK
|
||||
56ijk -56 HK
|
||||
56i jk -56 HK
|
||||
56i jk -56 HK
|
||||
// S and C get 56 (accepts ' ' gs grouping); H and K get null
|
||||
56ijk -56 K
|
||||
56i jk -56 K
|
||||
56ij k -56 K
|
||||
56ijk -56 K
|
||||
56ijk -56 K
|
||||
56i jk -56 K
|
||||
56i jk -56 K
|
||||
// S and C get 56 (accepts ' ' gs grouping); K gets null
|
||||
5 6 fail CJP
|
||||
56 5 HK
|
||||
56 5 K
|
||||
|
||||
test parse spaces in grouping
|
||||
// This test gives the ideal behavior of these cases, which
|
||||
|
@ -1598,7 +1576,7 @@ set locale en
|
|||
set pattern #,##0
|
||||
begin
|
||||
parse output breaks
|
||||
1 2 1 H
|
||||
1 2 1
|
||||
1 23 123 K
|
||||
// K gets 1 here; doesn't pick up the grouping separator
|
||||
1 234 1234 K
|
||||
|
@ -1614,7 +1592,7 @@ format output breaks
|
|||
// C and J get "1"
|
||||
// P gets "1.0"
|
||||
// K gets "1.1" (??)
|
||||
0.975 0.98 CHJKP
|
||||
0.975 0.98 CJKP
|
||||
|
||||
test lenient parse currency match
|
||||
// This test is for #13112
|
||||
|
@ -1622,8 +1600,8 @@ set locale en
|
|||
set pattern ¤#,##0.00
|
||||
begin
|
||||
parse output breaks
|
||||
// H and K get null
|
||||
1.23!@#$%^ 1.23 HK
|
||||
// K gets null
|
||||
1.23!@#$%^ 1.23 K
|
||||
|
||||
test percentage parsing multiplier
|
||||
// This test is for #13114
|
||||
|
@ -1632,9 +1610,9 @@ set pattern 0%
|
|||
begin
|
||||
parse output breaks
|
||||
55% 0.55
|
||||
// H and K get null
|
||||
// K gets null
|
||||
// C and P scale by 100 even if the percent sign is not present
|
||||
55 0.55 HK
|
||||
55 0.55 K
|
||||
|
||||
test trailing grouping separators in pattern
|
||||
// This test is for #13115
|
||||
|
@ -1653,8 +1631,8 @@ begin
|
|||
pattern format output breaks
|
||||
0 -15 -15
|
||||
0; -15 -15
|
||||
// H and K still prepend a '-' even though the pattern says otherwise
|
||||
0;0 -15 15 HK
|
||||
// K still prepends a '-' even though the pattern says otherwise
|
||||
0;0 -15 15 K
|
||||
|
||||
test percentage multiplier parsing
|
||||
// This test is for #13129
|
||||
|
@ -1670,9 +1648,9 @@ set pattern 0
|
|||
set signAlwaysShown 1
|
||||
begin
|
||||
format output breaks
|
||||
// H and K do not support this feature
|
||||
42 +42 HK
|
||||
0 +0 HK
|
||||
// K does not support this feature
|
||||
42 +42 K
|
||||
0 +0 K
|
||||
-42 -42
|
||||
|
||||
test parse strict with plus sign
|
||||
|
@ -1683,14 +1661,14 @@ begin
|
|||
lenient parse output breaks
|
||||
1 42 42
|
||||
1 -42 -42
|
||||
1 +42 42 HK
|
||||
1 +42 42 K
|
||||
1 0 0
|
||||
1 +0 0 HK
|
||||
0 42 fail HK
|
||||
1 +0 0 K
|
||||
0 42 fail K
|
||||
0 -42 -42
|
||||
0 +42 42 HK
|
||||
0 0 fail HK
|
||||
0 +0 0 HK
|
||||
0 +42 42 K
|
||||
0 0 fail K
|
||||
0 +0 0 K
|
||||
|
||||
test parse with scientific-separator-affix overlap
|
||||
set locale en
|
||||
|
@ -1708,13 +1686,13 @@ set currency USD
|
|||
begin
|
||||
parse output breaks
|
||||
USD123 123
|
||||
USD 123 123 HK
|
||||
USD 123 123 K
|
||||
usd123 123 K
|
||||
usd 123 123 HK
|
||||
usd 123 123 K
|
||||
Usd123 123 K
|
||||
Usd 123 123 HK
|
||||
Usd 123 123 K
|
||||
// US$ is not used for US dollars in en-US
|
||||
US$123 fail H
|
||||
US$123 fail
|
||||
us$123 fail
|
||||
Us$123 fail
|
||||
123 US dollars 123 K
|
||||
|
@ -1733,11 +1711,11 @@ set currency USD
|
|||
begin
|
||||
parse output outputCurrency breaks
|
||||
USD123 123 USD
|
||||
USD 123 123 USD H
|
||||
USD 123 123 USD
|
||||
usd123 123 USD
|
||||
usd 123 123 USD H
|
||||
usd 123 123 USD
|
||||
Usd123 123 USD
|
||||
Usd 123 123 USD H
|
||||
Usd 123 123 USD
|
||||
US$123 123 USD C
|
||||
us$123 fail fail
|
||||
Us$123 fail fail
|
||||
|
@ -1746,16 +1724,16 @@ Us$123 fail fail
|
|||
123 us dollars 123 USD
|
||||
GBP123 123 GBP
|
||||
gbp123 123 GBP C
|
||||
British pounds 123 123 GBP H
|
||||
british POUNDS 123 123 GBP H
|
||||
British pounds 123 123 GBP
|
||||
british POUNDS 123 123 GBP
|
||||
|
||||
test parse scientific with bidi marks
|
||||
begin
|
||||
locale parse output breaks
|
||||
en 4E\u200E+02 400 HK
|
||||
en 4E\u200E+02 400 K
|
||||
en 4E+02 400 K
|
||||
he 4E\u200E+02 400 K
|
||||
he 4E+02 400 HK
|
||||
he 4E+02 400 K
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.text.ParsePosition;
|
|||
import org.junit.Test;
|
||||
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import com.ibm.icu.dev.text.DecimalFormat_ICU58;
|
||||
import com.ibm.icu.impl.number.DecimalFormatProperties;
|
||||
import com.ibm.icu.impl.number.DecimalFormatProperties.ParseMode;
|
||||
import com.ibm.icu.impl.number.Padder.PadPosition;
|
||||
|
@ -290,185 +289,6 @@ public class NumberFormatDataDrivenTest {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Backwards-compatibility test: snapshot of DecimalFormat from ICU 58.
|
||||
*/
|
||||
private DataDrivenNumberFormatTestUtility.CodeUnderTest ICU58 = new DataDrivenNumberFormatTestUtility.CodeUnderTest() {
|
||||
@Override
|
||||
public Character Id() {
|
||||
return 'H';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(DataDrivenNumberFormatTestData tuple) {
|
||||
DecimalFormat_ICU58 fmt = createDecimalFormat(tuple);
|
||||
String actual = fmt.format(toNumber(tuple.format));
|
||||
String expected = tuple.output;
|
||||
if (!expected.equals(actual)) {
|
||||
return "Expected " + expected + ", got " + actual;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPattern(DataDrivenNumberFormatTestData tuple) {
|
||||
DecimalFormat_ICU58 fmt = createDecimalFormat(tuple);
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (tuple.toPattern != null) {
|
||||
String expected = tuple.toPattern;
|
||||
String actual = fmt.toPattern();
|
||||
if (!expected.equals(actual)) {
|
||||
result.append("Expected toPattern=" + expected + ", got " + actual);
|
||||
}
|
||||
}
|
||||
if (tuple.toLocalizedPattern != null) {
|
||||
String expected = tuple.toLocalizedPattern;
|
||||
String actual = fmt.toLocalizedPattern();
|
||||
if (!expected.equals(actual)) {
|
||||
result.append("Expected toLocalizedPattern=" + expected + ", got " + actual);
|
||||
}
|
||||
}
|
||||
return result.length() == 0 ? null : result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(DataDrivenNumberFormatTestData tuple) {
|
||||
DecimalFormat_ICU58 fmt = createDecimalFormat(tuple);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
Number actual = fmt.parse(tuple.parse, ppos);
|
||||
return compareParseResult(tuple.output, actual, ppos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseCurrency(DataDrivenNumberFormatTestData tuple) {
|
||||
DecimalFormat_ICU58 fmt = createDecimalFormat(tuple);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
CurrencyAmount actual = fmt.parseCurrency(tuple.parse, ppos);
|
||||
return compareParseCurrencyResult(tuple.output, tuple.outputCurrency, actual, ppos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tuple
|
||||
* @return
|
||||
*/
|
||||
private DecimalFormat_ICU58 createDecimalFormat(DataDrivenNumberFormatTestData tuple) {
|
||||
|
||||
DecimalFormat_ICU58 fmt = new DecimalFormat_ICU58(
|
||||
tuple.pattern == null ? "0" : tuple.pattern,
|
||||
new DecimalFormatSymbols(tuple.locale == null ? EN : tuple.locale));
|
||||
adjustDecimalFormat(tuple, fmt);
|
||||
return fmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tuple
|
||||
* @param fmt
|
||||
*/
|
||||
private void adjustDecimalFormat(DataDrivenNumberFormatTestData tuple, DecimalFormat_ICU58 fmt) {
|
||||
if (tuple.minIntegerDigits != null) {
|
||||
fmt.setMinimumIntegerDigits(tuple.minIntegerDigits);
|
||||
}
|
||||
if (tuple.maxIntegerDigits != null) {
|
||||
fmt.setMaximumIntegerDigits(tuple.maxIntegerDigits);
|
||||
}
|
||||
if (tuple.minFractionDigits != null) {
|
||||
fmt.setMinimumFractionDigits(tuple.minFractionDigits);
|
||||
}
|
||||
if (tuple.maxFractionDigits != null) {
|
||||
fmt.setMaximumFractionDigits(tuple.maxFractionDigits);
|
||||
}
|
||||
if (tuple.currency != null) {
|
||||
fmt.setCurrency(tuple.currency);
|
||||
}
|
||||
if (tuple.minGroupingDigits != null) {
|
||||
// Oops we don't support this.
|
||||
}
|
||||
if (tuple.useSigDigits != null) {
|
||||
fmt.setSignificantDigitsUsed(tuple.useSigDigits != 0);
|
||||
}
|
||||
if (tuple.minSigDigits != null) {
|
||||
fmt.setMinimumSignificantDigits(tuple.minSigDigits);
|
||||
}
|
||||
if (tuple.maxSigDigits != null) {
|
||||
fmt.setMaximumSignificantDigits(tuple.maxSigDigits);
|
||||
}
|
||||
if (tuple.useGrouping != null) {
|
||||
fmt.setGroupingUsed(tuple.useGrouping != 0);
|
||||
}
|
||||
if (tuple.multiplier != null) {
|
||||
fmt.setMultiplier(tuple.multiplier);
|
||||
}
|
||||
if (tuple.roundingIncrement != null) {
|
||||
fmt.setRoundingIncrement(tuple.roundingIncrement.doubleValue());
|
||||
}
|
||||
if (tuple.formatWidth != null) {
|
||||
fmt.setFormatWidth(tuple.formatWidth);
|
||||
}
|
||||
if (tuple.padCharacter != null && tuple.padCharacter.length() > 0) {
|
||||
fmt.setPadCharacter(tuple.padCharacter.charAt(0));
|
||||
}
|
||||
if (tuple.useScientific != null) {
|
||||
fmt.setScientificNotation(tuple.useScientific != 0);
|
||||
}
|
||||
if (tuple.grouping != null) {
|
||||
fmt.setGroupingSize(tuple.grouping);
|
||||
}
|
||||
if (tuple.grouping2 != null) {
|
||||
fmt.setSecondaryGroupingSize(tuple.grouping2);
|
||||
}
|
||||
if (tuple.roundingMode != null) {
|
||||
fmt.setRoundingMode(tuple.roundingMode);
|
||||
}
|
||||
if (tuple.currencyUsage != null) {
|
||||
fmt.setCurrencyUsage(tuple.currencyUsage);
|
||||
}
|
||||
if (tuple.minimumExponentDigits != null) {
|
||||
fmt.setMinimumExponentDigits(tuple.minimumExponentDigits.byteValue());
|
||||
}
|
||||
if (tuple.exponentSignAlwaysShown != null) {
|
||||
fmt.setExponentSignAlwaysShown(tuple.exponentSignAlwaysShown != 0);
|
||||
}
|
||||
if (tuple.decimalSeparatorAlwaysShown != null) {
|
||||
fmt.setDecimalSeparatorAlwaysShown(tuple.decimalSeparatorAlwaysShown != 0);
|
||||
}
|
||||
if (tuple.padPosition != null) {
|
||||
fmt.setPadPosition(tuple.padPosition);
|
||||
}
|
||||
if (tuple.positivePrefix != null) {
|
||||
fmt.setPositivePrefix(tuple.positivePrefix);
|
||||
}
|
||||
if (tuple.positiveSuffix != null) {
|
||||
fmt.setPositiveSuffix(tuple.positiveSuffix);
|
||||
}
|
||||
if (tuple.negativePrefix != null) {
|
||||
fmt.setNegativePrefix(tuple.negativePrefix);
|
||||
}
|
||||
if (tuple.negativeSuffix != null) {
|
||||
fmt.setNegativeSuffix(tuple.negativeSuffix);
|
||||
}
|
||||
if (tuple.signAlwaysShown != null) {
|
||||
// Not supported.
|
||||
}
|
||||
if (tuple.localizedPattern != null) {
|
||||
fmt.applyLocalizedPattern(tuple.localizedPattern);
|
||||
}
|
||||
int lenient = tuple.lenient == null ? 1 : tuple.lenient.intValue();
|
||||
fmt.setParseStrict(lenient == 0);
|
||||
if (tuple.parseIntegerOnly != null) {
|
||||
fmt.setParseIntegerOnly(tuple.parseIntegerOnly != 0);
|
||||
}
|
||||
if (tuple.parseCaseSensitive != null) {
|
||||
// Not supported.
|
||||
}
|
||||
if (tuple.decimalPatternMatchRequired != null) {
|
||||
fmt.setDecimalPatternMatchRequired(tuple.decimalPatternMatchRequired != 0);
|
||||
}
|
||||
if (tuple.parseNoExponent != null) {
|
||||
// Oops, not supported for now
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test of available JDK APIs.
|
||||
*/
|
||||
|
@ -893,16 +713,6 @@ public class NumberFormatDataDrivenTest {
|
|||
.runFormatSuiteIncludingKnownFailures("numberformattestspecification.txt", ICU4J);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestDataDrivenICU58() {
|
||||
// Android can't access DecimalFormat_ICU58 for testing (ticket #13283).
|
||||
if (TestUtil.getJavaVendor() == TestUtil.JavaVendor.Android)
|
||||
return;
|
||||
|
||||
DataDrivenNumberFormatTestUtility
|
||||
.runFormatSuiteIncludingKnownFailures("numberformattestspecification.txt", ICU58);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestDataDrivenJDK() {
|
||||
// #13373: Since not all JDK implementations are the same, test only whitelisted JDKs
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.junit.runners.JUnit4;
|
|||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import com.ibm.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer;
|
||||
import com.ibm.icu.dev.text.DecimalFormat_ICU58;
|
||||
import com.ibm.icu.impl.ICUConfig;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.impl.data.ResourceReader;
|
||||
|
@ -1701,9 +1700,7 @@ public class NumberFormatTest extends TestFmwk {
|
|||
@Test
|
||||
public void TestLocalizedPatternSymbolCoverage() {
|
||||
String[] standardPatterns = { "#,##0.05+%;#,##0.05-%", "* @@@E0‰" };
|
||||
String[] standardPatterns58 = { "#,##0.05+%;#,##0.05-%", "* @@@E0‰;* -@@@E0‰" };
|
||||
String[] localizedPatterns = { "▰⁖▰▰໐⁘໐໕†⁜⁙▰⁖▰▰໐⁘໐໕‡⁜", "⁂ ⁕⁕⁕⁑⁑໐‱" };
|
||||
String[] localizedPatterns58 = { "▰⁖▰▰໐⁘໐໕+⁜⁙▰⁖▰▰໐⁘໐໕‡⁜", "⁂ ⁕⁕⁕⁑⁑໐‱⁙⁂ ‡⁕⁕⁕⁑⁑໐‱" };
|
||||
|
||||
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
|
||||
dfs.setGroupingSeparator('⁖');
|
||||
|
@ -1721,9 +1718,7 @@ public class NumberFormatTest extends TestFmwk {
|
|||
|
||||
for (int i=0; i<2; i++) {
|
||||
String standardPattern = standardPatterns[i];
|
||||
String standardPattern58 = standardPatterns58[i];
|
||||
String localizedPattern = localizedPatterns[i];
|
||||
String localizedPattern58 = localizedPatterns58[i];
|
||||
|
||||
DecimalFormat df1 = new DecimalFormat("#", dfs);
|
||||
df1.applyPattern(standardPattern);
|
||||
|
@ -1735,22 +1730,6 @@ public class NumberFormatTest extends TestFmwk {
|
|||
standardPattern, df2.toPattern());
|
||||
assertEquals("toLocalizedPattern should match on standardPattern instance",
|
||||
localizedPattern, df1.toLocalizedPattern());
|
||||
|
||||
// Android can't access DecimalFormat_ICU58 for testing (ticket #13283).
|
||||
if (TestUtil.getJavaVendor() == TestUtil.JavaVendor.Android) continue;
|
||||
|
||||
// Note: ICU 58 does not support plus signs in patterns
|
||||
// Note: ICU 58 always prints the negative part of scientific notation patterns,
|
||||
// even when the negative part is not necessary
|
||||
DecimalFormat_ICU58 df3 = new DecimalFormat_ICU58("#", dfs);
|
||||
df3.applyPattern(standardPattern); // Reading standardPattern is OK
|
||||
DecimalFormat_ICU58 df4 = new DecimalFormat_ICU58("#", dfs);
|
||||
df4.applyLocalizedPattern(localizedPattern58);
|
||||
// Note: DecimalFormat#equals() is broken on ICU 58
|
||||
assertEquals("toPattern should match on ICU58 localizedPattern instance",
|
||||
standardPattern58, df4.toPattern());
|
||||
assertEquals("toLocalizedPattern should match on ICU58 standardPattern instance",
|
||||
localizedPattern58, df3.toLocalizedPattern());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,842 +0,0 @@
|
|||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html#License
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2015, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.text;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* <code>DigitList</code> handles the transcoding between numeric values and
|
||||
* strings of characters. It only represents non-negative numbers. The
|
||||
* division of labor between <code>DigitList</code> and
|
||||
* <code>DecimalFormat</code> is that <code>DigitList</code> handles the radix
|
||||
* 10 representation issues and numeric conversion, including rounding;
|
||||
* <code>DecimalFormat</code> handles the locale-specific issues such as
|
||||
* positive and negative representation, digit grouping, decimal point,
|
||||
* currency, and so on.
|
||||
*
|
||||
* <p>A <code>DigitList</code> is a representation of a finite numeric value.
|
||||
* <code>DigitList</code> objects do not represent <code>NaN</code> or infinite
|
||||
* values. A <code>DigitList</code> value can be converted to a
|
||||
* <code>BigDecimal</code> without loss of precision. Conversion to other
|
||||
* numeric formats may involve loss of precision, depending on the specific
|
||||
* value.
|
||||
*
|
||||
* <p>The <code>DigitList</code> representation consists of a string of
|
||||
* characters, which are the digits radix 10, from '0' to '9'. It also has a
|
||||
* base 10 exponent associated with it. The value represented by a
|
||||
* <code>DigitList</code> object can be computed by mulitplying the fraction
|
||||
* <em>f</em>, where 0 <= <em>f</em> < 1, derived by placing all the digits of
|
||||
* the list to the right of the decimal point, by 10^exponent.
|
||||
*
|
||||
* @see java.util.Locale
|
||||
* @see java.text.Format
|
||||
* @see NumberFormat
|
||||
* @see DecimalFormat
|
||||
* @see java.text.ChoiceFormat
|
||||
* @see java.text.MessageFormat
|
||||
* @version 1.18 08/12/98
|
||||
* @author Mark Davis, Alan Liu
|
||||
* */
|
||||
public final class DigitList {
|
||||
/**
|
||||
* The maximum number of significant digits in an IEEE 754 double, that
|
||||
* is, in a Java double. This must not be increased, or garbage digits
|
||||
* will be generated, and should not be decreased, or accuracy will be lost.
|
||||
*/
|
||||
public static final int MAX_LONG_DIGITS = 19; // == Long.toString(Long.MAX_VALUE).length()
|
||||
public static final int DBL_DIG = 17;
|
||||
|
||||
/**
|
||||
* These data members are intentionally public and can be set directly.
|
||||
*
|
||||
* The value represented is given by placing the decimal point before
|
||||
* digits[decimalAt]. If decimalAt is < 0, then leading zeros between
|
||||
* the decimal point and the first nonzero digit are implied. If decimalAt
|
||||
* is > count, then trailing zeros between the digits[count-1] and the
|
||||
* decimal point are implied.
|
||||
*
|
||||
* Equivalently, the represented value is given by f * 10^decimalAt. Here
|
||||
* f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
|
||||
* the right of the decimal.
|
||||
*
|
||||
* DigitList is normalized, so if it is non-zero, figits[0] is non-zero. We
|
||||
* don't allow denormalized numbers because our exponent is effectively of
|
||||
* unlimited magnitude. The count value contains the number of significant
|
||||
* digits present in digits[].
|
||||
*
|
||||
* Zero is represented by any DigitList with count == 0 or with each digits[i]
|
||||
* for all i <= count == '0'.
|
||||
*/
|
||||
public int decimalAt = 0;
|
||||
public int count = 0;
|
||||
public byte[] digits = new byte[MAX_LONG_DIGITS];
|
||||
|
||||
private final void ensureCapacity(int digitCapacity, int digitsToCopy) {
|
||||
if (digitCapacity > digits.length) {
|
||||
byte[] newDigits = new byte[digitCapacity * 2];
|
||||
System.arraycopy(digits, 0, newDigits, 0, digitsToCopy);
|
||||
digits = newDigits;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the represented number is zero.
|
||||
*/
|
||||
boolean isZero()
|
||||
{
|
||||
for (int i=0; i<count; ++i) if (digits[i] != '0') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unused as of ICU 2.6 - alan
|
||||
// /**
|
||||
// * Clears out the digits.
|
||||
// * Use before appending them.
|
||||
// * Typically, you set a series of digits with append, then at the point
|
||||
// * you hit the decimal point, you set myDigitList.decimalAt = myDigitList.count;
|
||||
// * then go on appending digits.
|
||||
// */
|
||||
// public void clear () {
|
||||
// decimalAt = 0;
|
||||
// count = 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Appends digits to the list.
|
||||
*/
|
||||
public void append (int digit) {
|
||||
ensureCapacity(count+1, count);
|
||||
digits[count++] = (byte) digit;
|
||||
}
|
||||
|
||||
public byte getDigitValue(int i) {
|
||||
return (byte) (digits[i] - '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility routine to get the value of the digit list
|
||||
* If (count == 0) this throws a NumberFormatException, which
|
||||
* mimics Long.parseLong().
|
||||
*/
|
||||
public final double getDouble() {
|
||||
if (count == 0) return 0.0;
|
||||
StringBuilder temp = new StringBuilder(count);
|
||||
temp.append('.');
|
||||
for (int i = 0; i < count; ++i) temp.append((char)(digits[i]));
|
||||
temp.append('E');
|
||||
temp.append(Integer.toString(decimalAt));
|
||||
return Double.valueOf(temp.toString()).doubleValue();
|
||||
// long value = Long.parseLong(temp.toString());
|
||||
// return (value * Math.pow(10, decimalAt - count));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility routine to get the value of the digit list.
|
||||
* If (count == 0) this returns 0, unlike Long.parseLong().
|
||||
*/
|
||||
public final long getLong() {
|
||||
// for now, simple implementation; later, do proper IEEE native stuff
|
||||
|
||||
if (count == 0) return 0;
|
||||
|
||||
// We have to check for this, because this is the one NEGATIVE value
|
||||
// we represent. If we tried to just pass the digits off to parseLong,
|
||||
// we'd get a parse failure.
|
||||
if (isLongMIN_VALUE()) return Long.MIN_VALUE;
|
||||
|
||||
StringBuilder temp = new StringBuilder(count);
|
||||
for (int i = 0; i < decimalAt; ++i)
|
||||
{
|
||||
temp.append((i < count) ? (char)(digits[i]) : '0');
|
||||
}
|
||||
return Long.parseLong(temp.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a <code>BigInteger</code> representing the value stored in this
|
||||
* <code>DigitList</code>. This method assumes that this object contains
|
||||
* an integral value; if not, it will return an incorrect value.
|
||||
* [bnf]
|
||||
* @param isPositive determines the sign of the returned result
|
||||
* @return the value of this object as a <code>BigInteger</code>
|
||||
*/
|
||||
public BigInteger getBigInteger(boolean isPositive) {
|
||||
if (isZero()) return BigInteger.valueOf(0);
|
||||
//Eclipse stated the following is "dead code"
|
||||
/*if (false) {
|
||||
StringBuilder stringRep = new StringBuilder(count);
|
||||
if (!isPositive) {
|
||||
stringRep.append('-');
|
||||
}
|
||||
for (int i=0; i<count; ++i) {
|
||||
stringRep.append((char) digits[i]);
|
||||
}
|
||||
int d = decimalAt;
|
||||
while (d-- > count) {
|
||||
stringRep.append('0');
|
||||
}
|
||||
return new BigInteger(stringRep.toString());
|
||||
} else*/ {
|
||||
int len = decimalAt > count ? decimalAt : count;
|
||||
if (!isPositive) {
|
||||
len += 1;
|
||||
}
|
||||
char[] text = new char[len];
|
||||
int n = 0;
|
||||
if (!isPositive) {
|
||||
text[0] = '-';
|
||||
for (int i = 0; i < count; ++i) {
|
||||
text[i+1] = (char)digits[i];
|
||||
}
|
||||
n = count+1;
|
||||
} else {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
text[i] = (char)digits[i];
|
||||
}
|
||||
n = count;
|
||||
}
|
||||
for (int i = n; i < text.length; ++i) {
|
||||
text[i] = '0';
|
||||
}
|
||||
return new BigInteger(new String(text));
|
||||
}
|
||||
}
|
||||
|
||||
private String getStringRep(boolean isPositive) {
|
||||
if (isZero()) return "0";
|
||||
StringBuilder stringRep = new StringBuilder(count+1);
|
||||
if (!isPositive) {
|
||||
stringRep.append('-');
|
||||
}
|
||||
int d = decimalAt;
|
||||
if (d < 0) {
|
||||
stringRep.append('.');
|
||||
while (d < 0) {
|
||||
stringRep.append('0');
|
||||
++d;
|
||||
}
|
||||
d = -1;
|
||||
}
|
||||
for (int i=0; i<count; ++i) {
|
||||
if (d == i) {
|
||||
stringRep.append('.');
|
||||
}
|
||||
stringRep.append((char) digits[i]);
|
||||
}
|
||||
while (d-- > count) {
|
||||
stringRep.append('0');
|
||||
}
|
||||
return stringRep.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an <code>ICU BigDecimal</code> representing the value stored in this
|
||||
* <code>DigitList</code>.
|
||||
* [bnf]
|
||||
* @param isPositive determines the sign of the returned result
|
||||
* @return the value of this object as a <code>BigDecimal</code>
|
||||
*/
|
||||
public com.ibm.icu.math.BigDecimal getBigDecimalICU(boolean isPositive) {
|
||||
if (isZero()) {
|
||||
return com.ibm.icu.math.BigDecimal.valueOf(0);
|
||||
}
|
||||
// if exponential notion is negative,
|
||||
// we prefer to use BigDecimal constructor with scale,
|
||||
// because it works better when extremely small value
|
||||
// is used. See #5698.
|
||||
long scale = (long)count - (long)decimalAt;
|
||||
if (scale > 0) {
|
||||
int numDigits = count;
|
||||
if (scale > Integer.MAX_VALUE) {
|
||||
// try to reduce the scale
|
||||
long numShift = scale - Integer.MAX_VALUE;
|
||||
if (numShift < count) {
|
||||
numDigits -= numShift;
|
||||
} else {
|
||||
// fallback to 0
|
||||
return new com.ibm.icu.math.BigDecimal(0);
|
||||
}
|
||||
}
|
||||
StringBuilder significantDigits = new StringBuilder(numDigits + 1);
|
||||
if (!isPositive) {
|
||||
significantDigits.append('-');
|
||||
}
|
||||
for (int i = 0; i < numDigits; i++) {
|
||||
significantDigits.append((char)digits[i]);
|
||||
}
|
||||
BigInteger unscaledVal = new BigInteger(significantDigits.toString());
|
||||
return new com.ibm.icu.math.BigDecimal(unscaledVal, (int)scale);
|
||||
} else {
|
||||
return new com.ibm.icu.math.BigDecimal(getStringRep(isPositive));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not this objects represented value is an integer.
|
||||
* [bnf]
|
||||
* @return true if the represented value of this object is an integer
|
||||
*/
|
||||
boolean isIntegral() {
|
||||
// Trim trailing zeros. This does not change the represented value.
|
||||
while (count > 0 && digits[count - 1] == (byte)'0') --count;
|
||||
return count == 0 || decimalAt >= count;
|
||||
}
|
||||
|
||||
// Unused as of ICU 2.6 - alan
|
||||
// /**
|
||||
// * Return true if the number represented by this object can fit into
|
||||
// * a long.
|
||||
// */
|
||||
// boolean fitsIntoLong(boolean isPositive)
|
||||
// {
|
||||
// // Figure out if the result will fit in a long. We have to
|
||||
// // first look for nonzero digits after the decimal point;
|
||||
// // then check the size. If the digit count is 18 or less, then
|
||||
// // the value can definitely be represented as a long. If it is 19
|
||||
// // then it may be too large.
|
||||
//
|
||||
// // Trim trailing zeros. This does not change the represented value.
|
||||
// while (count > 0 && digits[count - 1] == (byte)'0') --count;
|
||||
//
|
||||
// if (count == 0) {
|
||||
// // Positive zero fits into a long, but negative zero can only
|
||||
// // be represented as a double. - bug 4162852
|
||||
// return isPositive;
|
||||
// }
|
||||
//
|
||||
// if (decimalAt < count || decimalAt > MAX_LONG_DIGITS) return false;
|
||||
//
|
||||
// if (decimalAt < MAX_LONG_DIGITS) return true;
|
||||
//
|
||||
// // At this point we have decimalAt == count, and count == MAX_LONG_DIGITS.
|
||||
// // The number will overflow if it is larger than 9223372036854775807
|
||||
// // or smaller than -9223372036854775808.
|
||||
// for (int i=0; i<count; ++i)
|
||||
// {
|
||||
// byte dig = digits[i], max = LONG_MIN_REP[i];
|
||||
// if (dig > max) return false;
|
||||
// if (dig < max) return true;
|
||||
// }
|
||||
//
|
||||
// // At this point the first count digits match. If decimalAt is less
|
||||
// // than count, then the remaining digits are zero, and we return true.
|
||||
// if (count < decimalAt) return true;
|
||||
//
|
||||
// // Now we have a representation of Long.MIN_VALUE, without the leading
|
||||
// // negative sign. If this represents a positive value, then it does
|
||||
// // not fit; otherwise it fits.
|
||||
// return !isPositive;
|
||||
// }
|
||||
|
||||
// Unused as of ICU 2.6 - alan
|
||||
// /**
|
||||
// * Set the digit list to a representation of the given double value.
|
||||
// * This method supports fixed-point notation.
|
||||
// * @param source Value to be converted; must not be Inf, -Inf, Nan,
|
||||
// * or a value <= 0.
|
||||
// * @param maximumFractionDigits The most fractional digits which should
|
||||
// * be converted.
|
||||
// */
|
||||
// public final void set(double source, int maximumFractionDigits)
|
||||
// {
|
||||
// set(source, maximumFractionDigits, true);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Set the digit list to a representation of the given double value.
|
||||
* This method supports both fixed-point and exponential notation.
|
||||
* @param source Value to be converted; must not be Inf, -Inf, Nan,
|
||||
* or a value <= 0.
|
||||
* @param maximumDigits The most fractional or total digits which should
|
||||
* be converted.
|
||||
* @param fixedPoint If true, then maximumDigits is the maximum
|
||||
* fractional digits to be converted. If false, total digits.
|
||||
*/
|
||||
final void set(double source, int maximumDigits, boolean fixedPoint)
|
||||
{
|
||||
if (source == 0) source = 0;
|
||||
// Generate a representation of the form DDDDD, DDDDD.DDDDD, or
|
||||
// DDDDDE+/-DDDDD.
|
||||
String rep = Double.toString(source);
|
||||
|
||||
didRound = false;
|
||||
|
||||
set(rep, MAX_LONG_DIGITS);
|
||||
|
||||
if (fixedPoint) {
|
||||
// The negative of the exponent represents the number of leading
|
||||
// zeros between the decimal and the first non-zero digit, for
|
||||
// a value < 0.1 (e.g., for 0.00123, -decimalAt == 2). If this
|
||||
// is more than the maximum fraction digits, then we have an underflow
|
||||
// for the printed representation.
|
||||
if (-decimalAt > maximumDigits) {
|
||||
count = 0;
|
||||
return;
|
||||
} else if (-decimalAt == maximumDigits) {
|
||||
if (shouldRoundUp(0)) {
|
||||
count = 1;
|
||||
++decimalAt;
|
||||
digits[0] = (byte)'1';
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// else fall through
|
||||
}
|
||||
|
||||
// Eliminate trailing zeros.
|
||||
while (count > 1 && digits[count - 1] == '0')
|
||||
--count;
|
||||
|
||||
// Eliminate digits beyond maximum digits to be displayed.
|
||||
// Round up if appropriate.
|
||||
round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits == 0 ? -1 : maximumDigits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string representation of the form DDDDD, DDDDD.DDDDD,
|
||||
* or DDDDDE+/-DDDDD, set this object's value to it. Ignore
|
||||
* any leading '-'.
|
||||
*/
|
||||
private void set(String rep, int maxCount) {
|
||||
decimalAt = -1;
|
||||
count = 0;
|
||||
int exponent = 0;
|
||||
// Number of zeros between decimal point and first non-zero digit after
|
||||
// decimal point, for numbers < 1.
|
||||
int leadingZerosAfterDecimal = 0;
|
||||
boolean nonZeroDigitSeen = false;
|
||||
// Skip over leading '-'
|
||||
int i=0;
|
||||
if (rep.charAt(i) == '-') {
|
||||
++i;
|
||||
}
|
||||
for (; i < rep.length(); ++i) {
|
||||
char c = rep.charAt(i);
|
||||
if (c == '.') {
|
||||
decimalAt = count;
|
||||
} else if (c == 'e' || c == 'E') {
|
||||
++i;
|
||||
// Integer.parseInt doesn't handle leading '+' signs
|
||||
if (rep.charAt(i) == '+') {
|
||||
++i;
|
||||
}
|
||||
exponent = Integer.valueOf(rep.substring(i)).intValue();
|
||||
break;
|
||||
} else if (count < maxCount) {
|
||||
if (!nonZeroDigitSeen) {
|
||||
nonZeroDigitSeen = (c != '0');
|
||||
if (!nonZeroDigitSeen && decimalAt != -1) {
|
||||
++leadingZerosAfterDecimal;
|
||||
}
|
||||
}
|
||||
|
||||
if (nonZeroDigitSeen) {
|
||||
ensureCapacity(count+1, count);
|
||||
digits[count++] = (byte)c;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (decimalAt == -1) {
|
||||
decimalAt = count;
|
||||
}
|
||||
decimalAt += exponent - leadingZerosAfterDecimal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if truncating the representation to the given number
|
||||
* of digits will result in an increment to the last digit. This
|
||||
* method implements half-even rounding, the default rounding mode.
|
||||
* [bnf]
|
||||
* @param maximumDigits the number of digits to keep, from 0 to
|
||||
* <code>count-1</code>. If 0, then all digits are rounded away, and
|
||||
* this method returns true if a one should be generated (e.g., formatting
|
||||
* 0.09 with "#.#").
|
||||
* @return true if digit <code>maximumDigits-1</code> should be
|
||||
* incremented
|
||||
*/
|
||||
private boolean shouldRoundUp(int maximumDigits) {
|
||||
// variable not used boolean increment = false;
|
||||
// Implement IEEE half-even rounding
|
||||
/*Bug 4243108
|
||||
format(0.0) gives "0.1" if preceded by parse("99.99") [Richard/GCL]
|
||||
*/
|
||||
if (maximumDigits < count) {
|
||||
if (digits[maximumDigits] > '5') {
|
||||
return true;
|
||||
} else if (digits[maximumDigits] == '5' ) {
|
||||
for (int i=maximumDigits+1; i<count; ++i) {
|
||||
if (digits[i] != '0') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return maximumDigits > 0 && (digits[maximumDigits-1] % 2 != 0);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Round the representation to the given number of digits.
|
||||
* @param maximumDigits The maximum number of digits to be shown.
|
||||
* Upon return, count will be less than or equal to maximumDigits.
|
||||
* This now performs rounding when maximumDigits is 0, formerly it did not.
|
||||
*/
|
||||
public final void round(int maximumDigits) {
|
||||
// Eliminate digits beyond maximum digits to be displayed.
|
||||
// Round up if appropriate.
|
||||
// [bnf] rewritten to fix 4179818
|
||||
if (maximumDigits >= 0 && maximumDigits < count) {
|
||||
if (shouldRoundUp(maximumDigits)) {
|
||||
// Rounding up involves incrementing digits from LSD to MSD.
|
||||
// In most cases this is simple, but in a worst case situation
|
||||
// (9999..99) we have to adjust the decimalAt value.
|
||||
for (;;)
|
||||
{
|
||||
--maximumDigits;
|
||||
if (maximumDigits < 0)
|
||||
{
|
||||
// We have all 9's, so we increment to a single digit
|
||||
// of one and adjust the exponent.
|
||||
digits[0] = (byte) '1';
|
||||
++decimalAt;
|
||||
maximumDigits = 0; // Adjust the count
|
||||
didRound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++digits[maximumDigits];
|
||||
didRound = true;
|
||||
if (digits[maximumDigits] <= '9') break;
|
||||
// digits[maximumDigits] = '0'; // Unnecessary since we'll truncate this
|
||||
}
|
||||
++maximumDigits; // Increment for use as count
|
||||
}
|
||||
count = maximumDigits;
|
||||
}
|
||||
// Bug 4217661 DecimalFormat formats 1.001 to "1.00" instead of "1"
|
||||
// Eliminate trailing zeros. [Richard/GCL]
|
||||
// [dlf] moved outside if block, see ticket #6408
|
||||
while (count > 1 && digits[count-1] == '0') {
|
||||
--count;
|
||||
}
|
||||
}
|
||||
|
||||
// Value to indicate that rounding was done.
|
||||
private boolean didRound = false;
|
||||
|
||||
/**
|
||||
* Indicates if last digit set was rounded or not.
|
||||
* true indicates it was rounded.
|
||||
* false indicates rounding has not been done.
|
||||
*/
|
||||
public boolean wasRounded() {
|
||||
return didRound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility routine to set the value of the digit list from a long
|
||||
*/
|
||||
public final void set(long source)
|
||||
{
|
||||
set(source, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the digit list to a representation of the given long value.
|
||||
* @param source Value to be converted; must be >= 0 or ==
|
||||
* Long.MIN_VALUE.
|
||||
* @param maximumDigits The most digits which should be converted.
|
||||
* If maximumDigits is lower than the number of significant digits
|
||||
* in source, the representation will be rounded. Ignored if <= 0.
|
||||
*/
|
||||
public final void set(long source, int maximumDigits)
|
||||
{
|
||||
// This method does not expect a negative number. However,
|
||||
// "source" can be a Long.MIN_VALUE (-9223372036854775808),
|
||||
// if the number being formatted is a Long.MIN_VALUE. In that
|
||||
// case, it will be formatted as -Long.MIN_VALUE, a number
|
||||
// which is outside the legal range of a long, but which can
|
||||
// be represented by DigitList.
|
||||
// [NEW] Faster implementation
|
||||
didRound = false;
|
||||
|
||||
if (source <= 0) {
|
||||
if (source == Long.MIN_VALUE) {
|
||||
decimalAt = count = MAX_LONG_DIGITS;
|
||||
System.arraycopy(LONG_MIN_REP, 0, digits, 0, count);
|
||||
} else {
|
||||
count = 0;
|
||||
decimalAt = 0;
|
||||
}
|
||||
} else {
|
||||
int left = MAX_LONG_DIGITS;
|
||||
int right;
|
||||
while (source > 0) {
|
||||
digits[--left] = (byte) (('0') + (source % 10));
|
||||
source /= 10;
|
||||
}
|
||||
decimalAt = MAX_LONG_DIGITS-left;
|
||||
// Don't copy trailing zeros
|
||||
// we are guaranteed that there is at least one non-zero digit,
|
||||
// so we don't have to check lower bounds
|
||||
for (right = MAX_LONG_DIGITS - 1; digits[right] == (byte) '0'; --right) {}
|
||||
count = right - left + 1;
|
||||
System.arraycopy(digits, left, digits, 0, count);
|
||||
}
|
||||
if (maximumDigits > 0) round(maximumDigits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the digit list to a representation of the given BigInteger value.
|
||||
* [bnf]
|
||||
* @param source Value to be converted
|
||||
* @param maximumDigits The most digits which should be converted.
|
||||
* If maximumDigits is lower than the number of significant digits
|
||||
* in source, the representation will be rounded. Ignored if <= 0.
|
||||
*/
|
||||
public final void set(BigInteger source, int maximumDigits) {
|
||||
String stringDigits = source.toString();
|
||||
|
||||
count = decimalAt = stringDigits.length();
|
||||
didRound = false;
|
||||
|
||||
// Don't copy trailing zeros
|
||||
while (count > 1 && stringDigits.charAt(count - 1) == '0') --count;
|
||||
|
||||
int offset = 0;
|
||||
if (stringDigits.charAt(0) == '-') {
|
||||
++offset;
|
||||
--count;
|
||||
--decimalAt;
|
||||
}
|
||||
|
||||
ensureCapacity(count, 0);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
digits[i] = (byte) stringDigits.charAt(i + offset);
|
||||
}
|
||||
|
||||
if (maximumDigits > 0) round(maximumDigits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method that sets this digit list to represent the
|
||||
* given value. The value is given as a String of the format
|
||||
* returned by BigDecimal.
|
||||
* @param stringDigits value to be represented with the following
|
||||
* syntax, expressed as a regular expression: -?\d*.?\d*
|
||||
* Must not be an empty string.
|
||||
* @param maximumDigits The most digits which should be converted.
|
||||
* If maximumDigits is lower than the number of significant digits
|
||||
* in source, the representation will be rounded. Ignored if <= 0.
|
||||
* @param fixedPoint If true, then maximumDigits is the maximum
|
||||
* fractional digits to be converted. If false, total digits.
|
||||
*/
|
||||
private void setBigDecimalDigits(String stringDigits,
|
||||
int maximumDigits, boolean fixedPoint) {
|
||||
//| // Find the first non-zero digit, the decimal, and the last non-zero digit.
|
||||
//| int first=-1, last=stringDigits.length()-1, decimal=-1;
|
||||
//| for (int i=0; (first<0 || decimal<0) && i<=last; ++i) {
|
||||
//| char c = stringDigits.charAt(i);
|
||||
//| if (c == '.') {
|
||||
//| decimal = i;
|
||||
//| } else if (first < 0 && (c >= '1' && c <= '9')) {
|
||||
//| first = i;
|
||||
//| }
|
||||
//| }
|
||||
//|
|
||||
//| if (first < 0) {
|
||||
//| clear();
|
||||
//| return;
|
||||
//| }
|
||||
//|
|
||||
//| // At this point we know there is at least one non-zero digit, so the
|
||||
//| // following loop is safe.
|
||||
//| for (;;) {
|
||||
//| char c = stringDigits.charAt(last);
|
||||
//| if (c != '0' && c != '.') {
|
||||
//| break;
|
||||
//| }
|
||||
//| --last;
|
||||
//| }
|
||||
//|
|
||||
//| if (decimal < 0) {
|
||||
//| decimal = stringDigits.length();
|
||||
//| }
|
||||
//|
|
||||
//| count = last - first;
|
||||
//| if (decimal < first || decimal > last) {
|
||||
//| ++count;
|
||||
//| }
|
||||
//| decimalAt = decimal - first;
|
||||
//| if (decimalAt < 0) {
|
||||
//| ++decimalAt;
|
||||
//| }
|
||||
//|
|
||||
//| ensureCapacity(count, 0);
|
||||
//| for (int i = 0; i < count; ++i) {
|
||||
//| digits[i] = (byte) stringDigits.charAt(first++);
|
||||
//| if (first == decimal) {
|
||||
//| ++first;
|
||||
//| }
|
||||
//| }
|
||||
|
||||
didRound = false;
|
||||
|
||||
// The maxDigits here could also be Integer.MAX_VALUE
|
||||
set(stringDigits, stringDigits.length());
|
||||
|
||||
// Eliminate digits beyond maximum digits to be displayed.
|
||||
// Round up if appropriate.
|
||||
// {dlf} Some callers depend on passing '0' to round to mean 'don't round', but
|
||||
// rather than pass that information explicitly, we rely on some magic with maximumDigits
|
||||
// and decimalAt. Unfortunately, this is no good, because there are cases where maximumDigits
|
||||
// is zero and we do want to round, e.g. BigDecimal values -1 < x < 1. So since round
|
||||
// changed to perform rounding when the argument is 0, we now force the argument
|
||||
// to -1 in the situations where it matters.
|
||||
round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits == 0 ? -1 : maximumDigits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the digit list to a representation of the given BigDecimal value.
|
||||
* [bnf]
|
||||
* @param source Value to be converted
|
||||
* @param maximumDigits The most digits which should be converted.
|
||||
* If maximumDigits is lower than the number of significant digits
|
||||
* in source, the representation will be rounded. Ignored if <= 0.
|
||||
* @param fixedPoint If true, then maximumDigits is the maximum
|
||||
* fractional digits to be converted. If false, total digits.
|
||||
*/
|
||||
public final void set(java.math.BigDecimal source,
|
||||
int maximumDigits, boolean fixedPoint) {
|
||||
setBigDecimalDigits(source.toString(), maximumDigits, fixedPoint);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the digit list to a representation of the given BigDecimal value.
|
||||
* [bnf]
|
||||
* @param source Value to be converted
|
||||
* @param maximumDigits The most digits which should be converted.
|
||||
* If maximumDigits is lower than the number of significant digits
|
||||
* in source, the representation will be rounded. Ignored if <= 0.
|
||||
* @param fixedPoint If true, then maximumDigits is the maximum
|
||||
* fractional digits to be converted. If false, total digits.
|
||||
*/
|
||||
public final void set(com.ibm.icu.math.BigDecimal source,
|
||||
int maximumDigits, boolean fixedPoint) {
|
||||
setBigDecimalDigits(source.toString(), maximumDigits, fixedPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this DigitList represents Long.MIN_VALUE;
|
||||
* false, otherwise. This is required so that getLong() works.
|
||||
*/
|
||||
private boolean isLongMIN_VALUE()
|
||||
{
|
||||
if (decimalAt != count || count != MAX_LONG_DIGITS)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (digits[i] != LONG_MIN_REP[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static byte[] LONG_MIN_REP;
|
||||
|
||||
static
|
||||
{
|
||||
// Store the representation of LONG_MIN without the leading '-'
|
||||
String s = Long.toString(Long.MIN_VALUE);
|
||||
LONG_MIN_REP = new byte[MAX_LONG_DIGITS];
|
||||
for (int i=0; i < MAX_LONG_DIGITS; ++i)
|
||||
{
|
||||
LONG_MIN_REP[i] = (byte)s.charAt(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Unused -- Alan 2003-05
|
||||
// /**
|
||||
// * Return the floor of the log base 10 of a given double.
|
||||
// * This method compensates for inaccuracies which arise naturally when
|
||||
// * computing logs, and always give the correct value. The parameter
|
||||
// * must be positive and finite.
|
||||
// */
|
||||
// private static final int log10(double d)
|
||||
// {
|
||||
// // The reason this routine is needed is that simply taking the
|
||||
// // log and dividing by log10 yields a result which may be off
|
||||
// // by 1 due to rounding errors. For example, the naive log10
|
||||
// // of 1.0e300 taken this way is 299, rather than 300.
|
||||
// double log10 = Math.log(d) / LOG10;
|
||||
// int ilog10 = (int)Math.floor(log10);
|
||||
// // Positive logs could be too small, e.g. 0.99 instead of 1.0
|
||||
// if (log10 > 0 && d >= Math.pow(10, ilog10 + 1))
|
||||
// {
|
||||
// ++ilog10;
|
||||
// }
|
||||
// // Negative logs could be too big, e.g. -0.99 instead of -1.0
|
||||
// else if (log10 < 0 && d < Math.pow(10, ilog10))
|
||||
// {
|
||||
// --ilog10;
|
||||
// }
|
||||
// return ilog10;
|
||||
// }
|
||||
//
|
||||
// private static final double LOG10 = Math.log(10.0);
|
||||
|
||||
/**
|
||||
* equality test between two digit lists.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) // quick check
|
||||
return true;
|
||||
if (!(obj instanceof DigitList)) // (1) same object?
|
||||
return false;
|
||||
DigitList other = (DigitList) obj;
|
||||
if (count != other.count ||
|
||||
decimalAt != other.decimalAt)
|
||||
return false;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (digits[i] != other.digits[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the hash code for the digit list.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashcode = decimalAt;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
hashcode = hashcode * 37 + digits[i];
|
||||
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (isZero()) return "0";
|
||||
StringBuilder buf = new StringBuilder("0.");
|
||||
for (int i=0; i<count; ++i) buf.append((char)digits[i]);
|
||||
buf.append("x10^");
|
||||
buf.append(decimalAt);
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html#License
|
||||
|
||||
package com.ibm.icu.dev.text;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class DigitListTest extends TestFmwk {
|
||||
|
||||
private static DigitList digitList = new DigitList();
|
||||
private static long testdata = 1414213562;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
digitList.set(testdata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestToString() {
|
||||
String digitListStr = digitList.toString();
|
||||
assertEquals("DigitList incorrect", "0.1414213562x10^10", digitListStr);
|
||||
}
|
||||
@Test
|
||||
public void TestHashCode() {
|
||||
int dlHashcode = digitList.hashCode();
|
||||
assertEquals("DigitList hash code incorrect", -616183837, dlHashcode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEquals() {
|
||||
DigitList digitList2 = new DigitList();
|
||||
|
||||
// Test for success
|
||||
digitList2.set(testdata);
|
||||
assertTrue("DigitList objects with same values found unequal", digitList.equals(digitList2));
|
||||
// Test for failure
|
||||
digitList2.set(testdata+1);
|
||||
assertFalse("DigitList objects with different values found equal", digitList.equals(digitList2));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue