code errors - init

This commit is contained in:
alex-s168
2024-03-29 09:54:28 +01:00
parent ed580a9647
commit 355289716b
2 changed files with 142 additions and 0 deletions

View File

@@ -17,6 +17,16 @@ class MutMultiLineString(
return lines[row][col]
}
/** if out of bounds, extends with @see fill */
operator fun get(row: Int): MutString {
if (row >= lines.size) {
repeat(row - lines.size + 1) {
lines.add(MutString(fill = fill))
}
}
return lines[row]
}
/** if out of bounds, extends with @see fill */
operator fun set(row: Int, col: Int, value: Char) {
if (row >= lines.size) {
@@ -50,4 +60,14 @@ class MutMultiLineString(
override fun toString(): String =
lines.joinToString(separator = "\n")
companion object {
fun from(str: String, fill: Char): MutMultiLineString {
val res = MutMultiLineString(fill)
str.lines().forEach {
res.lines += MutString(it, fill)
}
return res
}
}
}