Skip to content

Commit

Permalink
feat: Use StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
kongwoojin committed May 4, 2024
1 parent c51cd0c commit a769b97
Showing 1 changed file with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun HtmlView(
val customViewQueue = ArrayDeque<CustomView>()

var isWebView = false
var webViewHtml = ""
val webViewHtml = StringBuilder()

var eventType = parser.eventType

Expand Down Expand Up @@ -72,9 +72,9 @@ fun HtmlView(
HTML_SPAN -> {
if (isWebView) {
parser.getAttributeValue(null, "style")?.let { style ->
webViewHtml += "<span style=\"$style\">"
webViewHtml.append("<span style=\"$style\">")
} ?: {
webViewHtml += "<span>"
webViewHtml.append("<span>")
}
} else {
val style = parser.getAttributeValue(null, "style")
Expand Down Expand Up @@ -217,10 +217,12 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<table ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<table ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}

HTML_TR -> {
Expand All @@ -231,10 +233,12 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<tr ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<tr ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}

HTML_TD -> {
Expand All @@ -245,10 +249,12 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<td ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<td ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}

HTML_TH -> {
Expand All @@ -259,10 +265,12 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<th ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<th ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}

HTML_COLGROUP -> {
Expand All @@ -273,10 +281,12 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<colgroup ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<colgroup ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}

HTML_COL -> {
Expand All @@ -287,18 +297,20 @@ fun HtmlView(
val attributeValue = parser.getAttributeValue(null, attributeName)
attributeMap[attributeName] = attributeValue
}
webViewHtml += "<col ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
webViewHtml.append(
"<col ${
attributeMap.map { (key, value) -> "$key=\"$value\"" }
.joinToString(" ")
}>"
)
}
}
}

XmlPullParser.TEXT -> {
if (parser.text.isNotBlank()) {
if (isWebView) {
webViewHtml += parser.text
webViewHtml.append(parser.text)
} else {
append(parser.text)
}
Expand Down Expand Up @@ -341,45 +353,45 @@ fun HtmlView(

HTML_SPAN -> {
if (isWebView) {
webViewHtml += "</span>"
webViewHtml.append("</span>")
} else {
pop()
}
}

HTML_TABLE -> {
webViewHtml += "</table>"
webViewHtml.append("</table>")
customViewPosition.add(length)
customViewQueue.add(
CustomView(
type = CustomView.CustomViewType.WEB_VIEW,
data = mapOf(
"html" to webViewHtml
"html" to webViewHtml.toString()
)
)
)
isWebView = false
webViewHtml = ""
webViewHtml.setLength(0)
}

HTML_TR -> {
webViewHtml += "</tr>"
webViewHtml.append("</tr>")
}

HTML_TD -> {
webViewHtml += "</td>"
webViewHtml.append("</td>")
}

HTML_TH -> {
webViewHtml += "</th>"
webViewHtml.append("</th>")
}

HTML_COLGROUP -> {
webViewHtml += "</colgroup>"
webViewHtml.append("</colgroup>")
}

HTML_COL -> {
webViewHtml += "</col>"
webViewHtml.append("</col>")
}
}
}
Expand Down

0 comments on commit a769b97

Please sign in to comment.