@@ -33,13 +33,13 @@ import org.jetbrains.kotlinx.dataframe.hasNulls
33
33
import org.jetbrains.kotlinx.dataframe.impl.canParse
34
34
import org.jetbrains.kotlinx.dataframe.impl.catchSilent
35
35
import org.jetbrains.kotlinx.dataframe.impl.createStarProjectedType
36
+ import org.jetbrains.kotlinx.dataframe.impl.io.FastDoubleParser
36
37
import org.jetbrains.kotlinx.dataframe.impl.javaDurationCanParse
37
38
import org.jetbrains.kotlinx.dataframe.io.isURL
38
39
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
39
40
import org.jetbrains.kotlinx.dataframe.values
40
41
import java.math.BigDecimal
41
42
import java.net.URL
42
- import java.text.NumberFormat
43
43
import java.text.ParsePosition
44
44
import java.time.format.DateTimeFormatter
45
45
import java.time.format.DateTimeFormatterBuilder
@@ -274,29 +274,6 @@ internal object Parsers : GlobalParserOptions {
274
274
null
275
275
}
276
276
277
- private fun String.parseDouble (format : NumberFormat ) =
278
- when (uppercase(Locale .getDefault())) {
279
- " NAN" -> Double .NaN
280
-
281
- " INF" -> Double .POSITIVE_INFINITY
282
-
283
- " -INF" -> Double .NEGATIVE_INFINITY
284
-
285
- " INFINITY" -> Double .POSITIVE_INFINITY
286
-
287
- " -INFINITY" -> Double .NEGATIVE_INFINITY
288
-
289
- else -> {
290
- val parsePosition = ParsePosition (0 )
291
- val result: Double? = format.parse(this , parsePosition)?.toDouble()
292
- if (parsePosition.index != this .length) {
293
- null
294
- } else {
295
- result
296
- }
297
- }
298
- }
299
-
300
277
inline fun <reified T : Any > stringParser (
301
278
catch : Boolean = false,
302
279
coveredBy : Set <KType > = emptySet(),
@@ -316,11 +293,15 @@ internal object Parsers : GlobalParserOptions {
316
293
): StringParserWithFormat <T > = StringParserWithFormat (typeOf<T >(), coveredBy, body)
317
294
318
295
private val parserToDoubleWithOptions = stringParserWithOptions { options ->
319
- val numberFormat = NumberFormat .getInstance (options?.locale ? : Locale .getDefault ())
320
- val parser = { it: String -> it.parseDouble(numberFormat ) }
296
+ val fastDoubleParser = FastDoubleParser (options ? : ParserOptions ())
297
+ val parser = { it: String -> fastDoubleParser.parseOrNull(it ) }
321
298
parser
322
299
}
323
300
301
+ private val posixDoubleParser = FastDoubleParser (
302
+ ParserOptions (locale = Locale .forLanguageTag(" C.UTF-8" )),
303
+ )
304
+
324
305
internal val parsersOrder = listOf (
325
306
// Int
326
307
stringParser<Int > { it.toIntOrNull() },
@@ -383,7 +364,7 @@ internal object Parsers : GlobalParserOptions {
383
364
// Double, with explicit number format or taken from current locale
384
365
parserToDoubleWithOptions,
385
366
// Double, with POSIX format
386
- stringParser<Double > { it.parseDouble( NumberFormat .getInstance( Locale .forLanguageTag( " C.UTF-8 " )) ) },
367
+ stringParser<Double > { posixDoubleParser.parseOrNull(it ) },
387
368
// Boolean
388
369
stringParser<Boolean > { it.toBooleanOrNull() },
389
370
// BigDecimal
@@ -448,9 +429,9 @@ internal object Parsers : GlobalParserOptions {
448
429
return parser.applyOptions(options)
449
430
}
450
431
451
- internal fun getDoubleParser (locale : Locale ? = null): (String ) -> Double? {
432
+ internal fun getDoubleParser (locale : Locale ? = null, useFastDoubleParser : Boolean ): (String ) -> Double? {
452
433
val options = if (locale != null ) {
453
- ParserOptions (locale = locale)
434
+ ParserOptions (locale = locale, useFastDoubleParser = useFastDoubleParser )
454
435
} else {
455
436
null
456
437
}
0 commit comments