All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redundent.kotlin.xml.TextElement.kt Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package org.redundent.kotlin.xml

/**
 * An element type that has some text in it.
 * For example:
 * http://blog.redundent.org
 */
open class TextElement internal constructor(val text: String) : Element {
	private fun isEmpty() = text.trim('\n', '\r').isBlank()

	override fun render(builder: Appendable, indent: String, printOptions: PrintOptions) {
		if (isEmpty()) {
			return
		}

		val lineEnding = getLineEnding(printOptions)

		builder.append("$indent${renderedText(printOptions)}$lineEnding")
	}

	internal fun renderSingleLine(builder: Appendable, printOptions: PrintOptions) {
		builder.append(renderedText(printOptions))
	}

	internal open fun renderedText(printOptions: PrintOptions): String? =
		escapeValue(text, printOptions.xmlVersion, printOptions.useCharacterReference)

	override fun equals(other: Any?): Boolean = other is TextElement && other.text == text

	override fun hashCode(): Int = text.hashCode()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy