Preserve feeds elements whitespaces

This commit is contained in:
Shinokuni 2020-09-17 22:17:58 +02:00
parent 82c29d0732
commit f6f8807b3a

View File

@ -1,13 +1,14 @@
package com.readrops.api.utils package com.readrops.api.utils
import com.gitlab.mvysny.konsumexml.Konsumer import com.gitlab.mvysny.konsumexml.Konsumer
import com.gitlab.mvysny.konsumexml.Whitespace
fun Konsumer.nonNullText(failOnElement: Boolean = true): String { fun Konsumer.nonNullText(failOnElement: Boolean = true): String {
val text = text(failOnElement = failOnElement) val text = text(failOnElement = failOnElement, whitespace = Whitespace.preserve)
return if (text.isNotEmpty()) text else throw ParseException("Xml field $name can't be null") return if (text.isNotEmpty()) text else throw ParseException("Xml field $name can't be null")
} }
fun Konsumer.nullableText(failOnElement: Boolean = true): String? { fun Konsumer.nullableText(failOnElement: Boolean = true): String? {
val text = text(failOnElement = failOnElement) val text = text(failOnElement = failOnElement, whitespace = Whitespace.preserve)
return if (text.isNotEmpty()) text else null return if (text.isNotEmpty()) text else null
} }