diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/data/entities/XmlAble.kt b/app/src/main/java/com/github/braillesystems/learnbraille/data/entities/XmlAble.kt index 4ef3c0fc..cb4e0681 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/data/entities/XmlAble.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/data/entities/XmlAble.kt @@ -5,13 +5,13 @@ interface XmlAble { val xmlParams: Map val xmlBody: HtmlText fun toXml(): HtmlText { - var paramsString = "" + val paramsStringBuilder = StringBuilder() for ((key, value) in xmlParams) { - val formattedValue = value.replace("\"", "'") - paramsString += " $key=\"$formattedValue\"" + val formattedValue = value.replace("\"", "'").replace("
", "") + paramsStringBuilder.append(" $key=\"$formattedValue\"") } val formattedBody = xmlBody.replace("\n +".toRegex(), "\n") - return "<$xmlTag$paramsString>\n$formattedBody\n" + return "<$xmlTag$paramsStringBuilder>\n$formattedBody\n" } } diff --git a/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt b/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt index 9b855009..e48e669d 100644 --- a/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt +++ b/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt @@ -7,10 +7,10 @@ import org.junit.Test import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E -import com.github.braillesystems.learnbraille.res.MarkerType import com.github.braillesystems.learnbraille.res.golubinaIntroLessons import com.github.braillesystems.learnbraille.res.SymbolType import java.io.File +import java.lang.StringBuilder internal val testLessons by lessons { lesson(name = "first lesson") { @@ -99,11 +99,12 @@ internal fun toXml(lesson: LessonWithSteps): HtmlText { override val xmlBody: HtmlText get() = { - var stepBuilder: HtmlText = "" + val stepBuilder = StringBuilder() for (step in lesson.second.dropLast(1)) { - stepBuilder += (toXml(step.first.data) + "\n") // TODO [...
] -> [

...

] + stepBuilder.append(toXml(step.first.data) + "\n") } - stepBuilder + toXml(lesson.second.takeLast(1)[0].first.data) + stepBuilder.append(toXml(lesson.second.takeLast(1)[0].first.data)) + stepBuilder.toString() }() }.toXml() } @@ -126,19 +127,27 @@ class ToXmlTest { @Test fun lessonToXml() { - println(toXml(testLessons.lessons[0])) + assertEquals( + """first title""", + toXml(testLessons.lessons[0]).replace("\n", "") + ) + } + @Test + fun dumpGolubinaLessons() { var xmlText = "" for (lessons in golubinaIntroLessons.lessons) { xmlText += (toXml(lessons) + "\n") } val xmlLinesList = xmlText.split("\n") - File("course.xml").printWriter().use { out -> + val outputPath = "course.xml" + File(outputPath).printWriter().use { out -> out.println("") out.println("") xmlLinesList.forEach { out.println(it) } out.println("") } + print("course dumped to file: `$outputPath`") } }