Refactor: Kotlin style

This commit is contained in:
Benoit Marty 2020-08-25 16:18:44 +02:00
parent f5ea4fb6ac
commit aca8fd7f3d
1 changed files with 12 additions and 10 deletions

View File

@ -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
} }