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

ai.platon.pulsar.common.Wildchar.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package ai.platon.pulsar.common

class Wildchar(val wildcard: String) {
    fun toRegex(): Regex {
        return toRegularExpression().toRegex()
    }

    fun toRegularExpression(): String {
        val length = wildcard.length
        val s = StringBuffer(length)
        s.append('^')
        var i = 0
        while (i < length) {
            val c = wildcard[i]
            when (c) {
                '*' -> s.append(".*")
                '?' -> s.append(".")
                '(', ')', '[', ']', '$', '^', '.', '{', '}', '|', '\\' -> {
                    s.append("\\")
                    s.append(c)
                }
                else -> s.append(c)
            }
            i++
        }
        s.append('$')
        return s.toString()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy