Refactor: Kotlin style

This commit is contained in:
Benoit Marty 2020-08-25 16:18:44 +02:00
parent f5ea4fb6ac
commit aca8fd7f3d

View file

@ -23,16 +23,18 @@ internal fun String.hasSpecialGlobChar(): Boolean {
// Very simple glob to regexp converter
internal fun String.simpleGlobToRegExp(): String {
var out = "" // "^"
for (element in this) {
when (element) {
'*' -> out += ".*"
'?' -> out += '.'.toString()
'.' -> out += "\\."
'\\' -> out += "\\\\"
else -> out += element
val string = this
return buildString {
// append("^")
string.forEach { char ->
when (char) {
'*' -> append(".*")
'?' -> append(".")
'.' -> append("\\.")
'\\' -> append("\\\\")
else -> append(char)
}
}
out += "" // '$'.toString()
return out
// append("$")
}
}