From: Lanius Trolling Date: Sat, 6 Apr 2024 16:42:03 +0000 (-0400) Subject: Rework string-building code X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=feb60c1366e5ba8bf96bea8d012749748188ef97;p=factbooks Rework string-building code --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt index 862a56c..7383dfa 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_html.kt @@ -16,11 +16,13 @@ typealias HtmlBuilderSubject = TagConsumer<*>.() -> Any? context(T) operator fun (TagConsumer<*>.() -> Any?).unaryPlus() = with(HtmlLexerTagConsumer(consumer)) { this@unaryPlus() } -fun (TagConsumer<*>.() -> Any?).toFragment() = buildString { - val builder = appendHTML() - with(HtmlLexerTagConsumer(builder)) { this@toFragment() } - builder.finalize() -} +fun (TagConsumer<*>.() -> Any?).toFragment() = StringBuilder() + .appendHTML() + .also { builder -> + with(HtmlLexerTagConsumer(builder)) { this@toFragment() } + } + .finalize() + .toString() class HtmlLexerTagConsumer private constructor(private val downstream: TagConsumer<*>) : TagConsumer { override fun onTagStart(tag: Tag) {