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

com.itangcent.common.text.LiteralTemplateEvaluator.kt Maven / Gradle / Ivy

package com.itangcent.common.text

/**
 * resolve:
 * 'string' -> string
 * "string" -> string
 */
class LiteralTemplateEvaluator private constructor() : TemplateEvaluator {

    override fun eval(str: String): Any? {
        if (str.startsWith('\'') && str.endsWith('\'')) {
            return str.removeSurrounding("'")
        } else if (str.startsWith('\"') && str.endsWith('\"')) {
            return str.removeSurrounding("\"")
        }
        return null
    }

    companion object {
        val INSTANCE = LiteralTemplateEvaluator()
    }
}

class LiteralTemplateEvaluatorDecorator : TemplateEvaluatorDecorator {
    override fun decorate(templateEvaluator: TemplateEvaluator): TemplateEvaluator {
        return LiteralTemplateEvaluator.INSTANCE.union(templateEvaluator)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy