Skip to content

Commit 18c2643

Browse files
committed
small number fix (regex seems to fail) TOON
1 parent 2abcec7 commit 18c2643

File tree

2 files changed

+8
-4
lines changed
  • dataframe-json/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io
    • test/kotlin/org/jetbrains/kotlinx/dataframe/io

2 files changed

+8
-4
lines changed

dataframe-json/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/toon.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ internal value class ToonString(override val value: String) : ToonPrimitive<Stri
6767
private companion object {
6868
private val disallowedToonChars = setOf('\n', '\r', '\t', '"', '{', '}', '[', ']', ':', '\\')
6969

70+
// TODO test, regex seems to fail...
7071
private fun String.looksLikeNumber() =
71-
matches("""/^-?\d+(?:.\d+)?(?:e[+-]?\d+)?$/i""".toRegex()) ||
72+
toLongOrNull() != null ||
73+
toDoubleOrNull() != null ||
74+
matches("""/^-?\d+(?:.\d+)?(?:e[+-]?\d+)?$/i""".toRegex()) ||
7275
matches("""/^0\d+$/""".toRegex())
7376

7477
private fun String.needsQuotes(activeDelimiter: ToonDelimiter): Boolean =

dataframe-json/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/ToonTests.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.api.group
55
import org.jetbrains.kotlinx.dataframe.api.groupBy
66
import org.jetbrains.kotlinx.dataframe.api.into
77
import org.jetbrains.kotlinx.dataframe.impl.io.ToonArray
8+
import org.jetbrains.kotlinx.dataframe.impl.io.ToonDelimiter
89
import org.jetbrains.kotlinx.dataframe.impl.io.ToonObject
910
import org.jetbrains.kotlinx.dataframe.impl.io.ToonPrimitive
1011
import org.jetbrains.kotlinx.dataframe.impl.io.encodeToToonImpl
@@ -176,12 +177,12 @@ class ToonTests {
176177
"Charlie", "Daniels", 20, "Moscow", null, false,
177178
"Charlie", "Chaplin", 40, "Milan", null, true,
178179
"Bob", "Marley", 30, "Tokyo", 68, true,
179-
"Alice", "Wolf", 20, null, 55, false,
180-
"Charlie", "Byrd", 30, "Moscow", 90, true,
180+
"123", "Wolf", 20, null, 55, false,
181+
"Cha:rlie", "Byrd", 30, "Moscow", 90, true,
181182
)
182183

183184
println(
184-
encodeToToonImpl(df).render(),
185+
encodeToToonImpl(df).render(delimiter = ToonDelimiter.PIPE),
185186
)
186187
}
187188

0 commit comments

Comments
 (0)