Replace CSVWriter with manual string building for KMP migration

This commit is contained in:
Alinson S. Xavier 2026-04-05 17:15:24 -05:00
parent 7a48277478
commit 273dc5b104
2 changed files with 14 additions and 5 deletions

View File

@ -22,3 +22,13 @@ package org.isoron.platform.io
expect fun format(format: String, arg: String): String
expect fun format(format: String, arg: Int): String
expect fun format(format: String, arg: Double): String
fun csvLine(fields: Array<String>): String {
return fields.joinToString(",") { field ->
if (field.any { it == ',' || it == '"' || it == '\n' || it == '\r' }) {
"\"${field.replace("\"", "\"\"")}\""
} else {
field
}
} + "\n"
}

View File

@ -18,7 +18,7 @@
*/
package org.isoron.uhabits.core.models
import com.opencsv.CSVWriter
import org.isoron.platform.io.csvLine
import org.isoron.platform.io.format
import java.io.IOException
import java.io.Writer
@ -192,8 +192,7 @@ abstract class HabitList : Iterable<Habit> {
"Target Value",
"Archived?"
)
val csv = CSVWriter(out)
csv.writeNext(header, false)
out.write(csvLine(header))
for (habit in this) {
val (numerator, denominator) = habit.frequency
val cols = arrayOf(
@ -210,9 +209,9 @@ abstract class HabitList : Iterable<Habit> {
if (habit.isNumerical) habit.targetValue.toString() else "",
habit.isArchived.toString()
)
csv.writeNext(cols, false)
out.write(csvLine(cols))
}
csv.close()
out.close()
}
abstract fun resort()