@@ -166,11 +166,7 @@ final private[scala] object StringParsers {
166
166
// some utilities for working with index bounds into the original string
167
167
@ inline
168
168
def forAllBetween (start : Int , end : Int , pred : Char => Boolean ): Boolean = {
169
- def rec (i : Int ): Boolean = {
170
- if (i >= end) true
171
- else if (pred(format.charAt(i))) rec(i + 1 )
172
- else false
173
- }
169
+ def rec (i : Int ): Boolean = i >= end || pred(format.charAt(i)) && rec(i + 1 )
174
170
rec(start)
175
171
}
176
172
@@ -211,11 +207,11 @@ final private[scala] object StringParsers {
211
207
212
208
def postfixOK (startIndex : Int , endIndex : Int ): Boolean =
213
209
(startIndex < endIndex) && {
214
- (forAllBetween(startIndex, endIndex, ch => ch >= '0' && ch <= '9' )) || {
210
+ (forAllBetween(startIndex, endIndex, isDigit )) || {
215
211
val startchar = format.charAt(startIndex)
216
212
(startchar == '+' || startchar == '-' ) &&
217
213
(endIndex - startIndex > 1 ) &&
218
- forAllBetween(startIndex + 1 , endIndex, ch => ch >= '0' && ch <= '9' )
214
+ forAllBetween(startIndex + 1 , endIndex, isDigit )
219
215
}
220
216
}
221
217
// prefix [pP] postfix
@@ -226,13 +222,15 @@ final private[scala] object StringParsers {
226
222
def isDecFloatLiteral (startIndex : Int , endIndex : Int ): Boolean = {
227
223
// invariant: endIndex > startIndex
228
224
225
+ def isExp (c : Char ): Boolean = c == 'e' || c == 'E'
226
+
229
227
def expOK (startIndex : Int , endIndex : Int ): Boolean =
230
228
(startIndex < endIndex) && {
231
229
val startChar = format.charAt(startIndex)
232
230
if (startChar == '+' || startChar == '-' )
233
231
(endIndex > (startIndex + 1 )) &&
234
- skipIndexWhile(ch => ch >= '0' && ch <= '9' , startIndex + 1 , endIndex) == endIndex
235
- else skipIndexWhile(ch => ch >= '0' && ch <= '9' , startIndex, endIndex) == endIndex
232
+ skipIndexWhile(isDigit , startIndex + 1 , endIndex) == endIndex
233
+ else skipIndexWhile(isDigit , startIndex, endIndex) == endIndex
236
234
}
237
235
238
236
// significant can be one of
@@ -244,29 +242,24 @@ final private[scala] object StringParsers {
244
242
if (startChar == '.' ) {
245
243
val noSignificant = skipIndexWhile(isDigit, startIndex + 1 , endIndex)
246
244
// a digit is required followed by optional exp
247
- (noSignificant > startIndex + 1 ) && (noSignificant >= endIndex || {
248
- val e = format.charAt(noSignificant)
249
- (e == 'e' || e == 'E' ) && expOK(noSignificant + 1 , endIndex)
250
- })
245
+ (noSignificant > startIndex + 1 ) && (noSignificant >= endIndex ||
246
+ isExp(format.charAt(noSignificant)) && expOK(noSignificant + 1 , endIndex)
247
+ )
251
248
}
252
249
else if (isDigit(startChar)) {
253
- // one set of digits, then optionally a period, then optionally another set of digits, then optionally an exponent
250
+ // one set of digits, then optionally a period, then optionally another set of digits, then optionally an exponent
254
251
val noInt = skipIndexWhile(isDigit, startIndex, endIndex)
255
- (noInt == endIndex) || { // just the digits
256
- val afterIntChar = format.charAt(noInt)
257
- if (afterIntChar == '.' ) {
252
+ // just the digits
253
+ (noInt == endIndex) || {
254
+ if (format.charAt(noInt) == '.' ) {
258
255
val noSignificant = skipIndexWhile(isDigit, noInt + 1 , endIndex)
259
- (noSignificant >= endIndex) || { // no exponent
260
- val e = format.charAt(noSignificant)
261
- (e == 'e' || e == 'E' ) && expOK(noSignificant + 1 , endIndex)
262
- }
263
- }
264
- else if (afterIntChar == 'e' || afterIntChar == 'E' ) expOK(noInt + 1 , endIndex)
265
- else false
256
+ (noSignificant >= endIndex) || // no exponent
257
+ isExp(format.charAt(noSignificant)) && expOK(noSignificant + 1 , endIndex)
258
+ } else
259
+ isExp(format.charAt(noInt)) && expOK(noInt + 1 , endIndex)
266
260
}
267
261
}
268
262
else false
269
-
270
263
}
271
264
272
265
// count 0x00 to 0x20 as "whitespace", and nothing else
0 commit comments