Replace CSVWriter with manual string building for KMP migration
This commit is contained in:
parent
7a48277478
commit
273dc5b104
@ -22,3 +22,13 @@ package org.isoron.platform.io
|
|||||||
expect fun format(format: String, arg: String): String
|
expect fun format(format: String, arg: String): String
|
||||||
expect fun format(format: String, arg: Int): String
|
expect fun format(format: String, arg: Int): String
|
||||||
expect fun format(format: String, arg: Double): 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"
|
||||||
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import com.opencsv.CSVWriter
|
import org.isoron.platform.io.csvLine
|
||||||
import org.isoron.platform.io.format
|
import org.isoron.platform.io.format
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Writer
|
import java.io.Writer
|
||||||
@ -192,8 +192,7 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
"Target Value",
|
"Target Value",
|
||||||
"Archived?"
|
"Archived?"
|
||||||
)
|
)
|
||||||
val csv = CSVWriter(out)
|
out.write(csvLine(header))
|
||||||
csv.writeNext(header, false)
|
|
||||||
for (habit in this) {
|
for (habit in this) {
|
||||||
val (numerator, denominator) = habit.frequency
|
val (numerator, denominator) = habit.frequency
|
||||||
val cols = arrayOf(
|
val cols = arrayOf(
|
||||||
@ -210,9 +209,9 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
if (habit.isNumerical) habit.targetValue.toString() else "",
|
if (habit.isNumerical) habit.targetValue.toString() else "",
|
||||||
habit.isArchived.toString()
|
habit.isArchived.toString()
|
||||||
)
|
)
|
||||||
csv.writeNext(cols, false)
|
out.write(csvLine(cols))
|
||||||
}
|
}
|
||||||
csv.close()
|
out.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun resort()
|
abstract fun resort()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user