Skip to content

Commit 7a5fdfb

Browse files
committed
POSIX Double parsing
1 parent 62d327b commit 7a5fdfb

File tree

1 file changed

+10
-5
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api

1 file changed

+10
-5
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/parse.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,23 @@ internal object Parsers : GlobalParserOptions {
171171
return null
172172
}
173173

174-
private fun String.parseDouble(format: NumberFormat) =
174+
private val posixNumberFormat = NumberFormat.getInstance(Locale.forLanguageTag("C.UTF-8"))
175+
176+
private fun String.parseDouble(userNumberFormat: NumberFormat) =
175177
when (uppercase(Locale.getDefault())) {
176178
"NAN" -> Double.NaN
177179
"INF" -> Double.POSITIVE_INFINITY
178180
"-INF" -> Double.NEGATIVE_INFINITY
179181
"INFINITY" -> Double.POSITIVE_INFINITY
180182
"-INFINITY" -> Double.NEGATIVE_INFINITY
181183
else -> {
182-
val parsePosition = ParsePosition(0)
183-
val result: Double? = format.parse(this, parsePosition)?.toDouble()
184-
if (parsePosition.index != this.length) null
185-
else result
184+
fun parseWithFormat(format: NumberFormat): Double? {
185+
val parsePosition = ParsePosition(0)
186+
val result: Double? = format.parse(this, parsePosition)?.toDouble()
187+
return if (parsePosition.index != this.length) null
188+
else result
189+
}
190+
parseWithFormat(userNumberFormat) ?: parseWithFormat(posixNumberFormat)
186191
}
187192
}
188193

0 commit comments

Comments
 (0)