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

run.qontract.core.value.StringValue.kt Maven / Gradle / Ivy

package run.qontract.core.value

import io.ktor.http.quote
import io.ktor.util.InternalAPI
import org.w3c.dom.Document
import org.w3c.dom.Node
import run.qontract.core.ExampleDeclarations
import run.qontract.core.pattern.*

data class StringValue(val string: String = "") : Value, ScalarValue, XMLValue {
    override val httpContentType = "text/plain"

    @OptIn(InternalAPI::class)
    override fun displayableValue(): String = toStringValue().quote()
    override fun toStringValue() = string
    override fun displayableType(): String = "string"
    override fun exactMatchElseType(): Pattern {
        return when {
            isPatternToken() -> DeferredPattern(string)
            else -> ExactValuePattern(this)
        }
    }

    override fun build(document: Document): Node = document.createTextNode(string)
    override fun listOf(valueList: List): Value {
        return JSONArrayValue(valueList)
    }

    override fun type(): Pattern = StringPattern

    override fun typeDeclarationWithKey(key: String, types: Map, exampleDeclarations: ExampleDeclarations): Pair =
            primitiveTypeDeclarationWithKey(key, types, exampleDeclarations, displayableType(), string)

    override fun typeDeclarationWithoutKey(exampleKey: String, types: Map, exampleDeclarations: ExampleDeclarations): Pair =
            primitiveTypeDeclarationWithoutKey(exampleKey, types, exampleDeclarations, displayableType(), string)

    override fun toString() = string

    fun isPatternToken(): Boolean = isPatternToken(string.trim())
    fun trimmed(): StringValue = StringValue(string.trim())
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy