Refactor: Kotlin style
This commit is contained in:
parent
f5ea4fb6ac
commit
aca8fd7f3d
|
@ -23,16 +23,18 @@ internal fun String.hasSpecialGlobChar(): Boolean {
|
||||||
|
|
||||||
// Very simple glob to regexp converter
|
// Very simple glob to regexp converter
|
||||||
internal fun String.simpleGlobToRegExp(): String {
|
internal fun String.simpleGlobToRegExp(): String {
|
||||||
var out = "" // "^"
|
val string = this
|
||||||
for (element in this) {
|
return buildString {
|
||||||
when (element) {
|
// append("^")
|
||||||
'*' -> out += ".*"
|
string.forEach { char ->
|
||||||
'?' -> out += '.'.toString()
|
when (char) {
|
||||||
'.' -> out += "\\."
|
'*' -> append(".*")
|
||||||
'\\' -> out += "\\\\"
|
'?' -> append(".")
|
||||||
else -> out += element
|
'.' -> append("\\.")
|
||||||
|
'\\' -> append("\\\\")
|
||||||
|
else -> append(char)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// append("$")
|
||||||
}
|
}
|
||||||
out += "" // '$'.toString()
|
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue