From aca8fd7f3d80fde7784ee9086400599ef1003f91 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 25 Aug 2020 16:18:44 +0200 Subject: [PATCH] Refactor: Kotlin style --- .../matrix/android/sdk/internal/util/Glob.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Glob.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Glob.kt index fb8a5367dd..129bf0dec4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Glob.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/util/Glob.kt @@ -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) + } } + // append("$") } - out += "" // '$'.toString() - return out }