@@ -78,11 +78,36 @@ static NumberToken parse(CharSequence value, int beginIndex, int endIndex) {
7878
7979 checkNotEmpty (cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
8080
81- if (TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , '.' ) >= 0
82- || TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , 'e' ) >= 0
83- || TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , 'E' ) >= 0 ) {
84- char lastChar = clean .charAt (cleanEndIndex - 1 );
81+ boolean negative = false ;
82+ {
83+ char ch = clean .charAt (cleanBeginIndex );
84+ if (ch == '+' || ch == '-' ) {
85+ negative = ch == '-' ;
86+ cleanBeginIndex += 1 ;
87+
88+ checkNotEmpty (cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
89+ }
90+ }
91+
92+ IntegralToken .Radix radix ;
93+ if (TextUtils .startsWithIgnoreCase (clean , cleanBeginIndex , cleanEndIndex , "0x" )) {
94+ radix = IntegralToken .Radix .HEX ;
95+ cleanBeginIndex += 2 ;
96+ } else if (TextUtils .startsWithIgnoreCase (clean , cleanBeginIndex , cleanEndIndex , "0b" )) {
97+ radix = IntegralToken .Radix .BINARY ;
98+ cleanBeginIndex += 2 ;
99+ } else {
100+ radix = IntegralToken .Radix .DECIMAL ;
101+ }
85102
103+ checkNotEmpty (cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
104+
105+ char lastChar = clean .charAt (cleanEndIndex - 1 );
106+ if ((radix == IntegralToken .Radix .DECIMAL ) && (
107+ lastChar == 'f' || lastChar == 'F' || lastChar == 'd' || lastChar == 'D'
108+ || TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , '.' ) >= 0
109+ || TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , 'e' ) >= 0
110+ || TextUtils .indexOf (clean , cleanBeginIndex , cleanEndIndex , 'E' ) >= 0 )) {
86111 FloatingType floatingType ;
87112 if (lastChar == 'f' || lastChar == 'F' ) {
88113 floatingType = FloatingType .FLOAT ;
@@ -94,37 +119,20 @@ static NumberToken parse(CharSequence value, int beginIndex, int endIndex) {
94119 floatingType = FloatingType .DOUBLE ;
95120 }
96121
97- double doubleValue = Double .parseDouble (clean .subSequence (cleanBeginIndex , cleanEndIndex ).toString ());
98- if (!Double .isFinite (doubleValue ) || doubleValue < -floatingType .max || doubleValue > floatingType .max ) {
99- throw invalidNumberLiteral (value , beginIndex , endIndex );
100- }
122+ checkNotEmpty (cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
101123
102- return new Token .FloatingToken (doubleValue , floatingType );
103- } else {
104- boolean negative = false ;
105- {
106- char ch = clean .charAt (cleanBeginIndex );
107- if (ch == '+' || ch == '-' ) {
108- negative = ch == '-' ;
109- cleanBeginIndex += 1 ;
110-
111- checkNotEmpty (cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
112- }
124+ if (clean .charAt (cleanBeginIndex ) == '_' || clean .charAt (cleanEndIndex - 1 ) == '_' ) {
125+ throw invalidNumberLiteral (value , beginIndex , endIndex );
113126 }
114127
115- IntegralToken .Radix radix ;
116- if (TextUtils .startsWithIgnoreCase (clean , cleanBeginIndex , cleanEndIndex , "0x" )) {
117- radix = IntegralToken .Radix .HEX ;
118- cleanBeginIndex += 2 ;
119- } else if (TextUtils .startsWithIgnoreCase (clean , cleanBeginIndex , cleanEndIndex , "0b" )) {
120- radix = IntegralToken .Radix .BINARY ;
121- cleanBeginIndex += 2 ;
122- } else {
123- radix = IntegralToken .Radix .DECIMAL ;
128+ double doubleValue = Double .parseDouble (clean .subSequence (cleanBeginIndex , cleanEndIndex ).toString ().replace ("_" , "" ));
129+ if (!Double .isFinite (doubleValue )
130+ || floatingType == FloatingType .FLOAT && (doubleValue < -Float .MAX_VALUE || doubleValue > Float .MAX_VALUE )) {
131+ throw invalidNumberLiteral (value , beginIndex , endIndex );
124132 }
125133
126- checkNotEmpty ( cleanBeginIndex , cleanEndIndex , value , beginIndex , endIndex );
127-
134+ return new Token . FloatingToken ( doubleValue , floatingType );
135+ } else {
128136 IntegralToken .Suffix suffix = IntegralToken .Suffix .check (clean , cleanBeginIndex , cleanEndIndex , radix );
129137 cleanEndIndex -= suffix .value ().length ();
130138
0 commit comments