From d6b36bf97669ee43c326b0e4e80a6197891730ed Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 13 Jun 2024 21:07:14 +0200 Subject: [PATCH] feat: Handle string resources (#741) --- .../main/kotlin/app/pachli/mvstring/Main.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tools/mvstring/src/main/kotlin/app/pachli/mvstring/Main.kt b/tools/mvstring/src/main/kotlin/app/pachli/mvstring/Main.kt index 82a773de4..658142b26 100644 --- a/tools/mvstring/src/main/kotlin/app/pachli/mvstring/Main.kt +++ b/tools/mvstring/src/main/kotlin/app/pachli/mvstring/Main.kt @@ -112,10 +112,10 @@ class App : CliktCommand(help = """Move string resources between modules""") { } } - enum class State { - Searching, - Moving, - Moved, + sealed interface State { + data object Searching : State + data class Moving(val etag: String) : State + data object Moved : State } private fun moveResource(src: Path, dst: Path, id: String) { @@ -130,27 +130,33 @@ class App : CliktCommand(help = """Move string resources between modules""") { val dstFile = dst / "strings.xml" val toCopy = mutableListOf() - var state = State.Searching + var state: State = State.Searching srcFile.useLines { srcLines -> for (srcLine in srcLines) { // Moved the resource, copy the remaining lines - if (state == State.Moved) { + if (state is State.Moved) { tmpSrc.println(srcLine) continue } - // Not the resource we're looking for - if (state == State.Searching && !srcLine.contains(""" state = State.Moving("") + srcLine.contains(""" state = State.Moving("") + else -> { + tmpSrc.println(srcLine) + continue + } + } } // Matching resource. Append to dstFile - state = State.Moving toCopy.add(srcLine) - if (srcLine.contains("")) { + if (state !is State.Moving) throw RuntimeException("invalid state, $state") + + if (srcLine.contains((state as State.Moving).etag)) { if (!dstFile.exists()) createResourceFile(dstFile) dstFile.useLines { dstLines -> for (dstLine in dstLines) {