Skip to content

Commit 2259794

Browse files
fix: preset keys abbreviation not working
1 parent 5f9947a commit 2259794

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/src/main/java/com/osfans/trime/ime/keyboard/KeyAction.kt

+7-11
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,13 @@ class KeyAction(
175175

176176
companion object {
177177
private val BRACED_STR = Regex("""\{[^{}]+\}""")
178-
private val KV_PATTERN = Regex("""(\\w+)=(\\w+)""")
179178

180-
private fun decodeMapFromString(str: String): Map<String, String> {
181-
val map = mutableMapOf<String, String>()
182-
val trimmed = str.removeSurrounding("{", "}")
183-
val matches = KV_PATTERN.findAll(trimmed)
184-
for (match in matches) {
185-
val (_, k, v) = match.groupValues
186-
map[k] = v
187-
}
188-
return map
189-
}
179+
private fun decodeMapFromString(str: String): Map<String, String> =
180+
str
181+
.removeSurrounding("{", "}")
182+
.split(", ")
183+
.mapNotNull {
184+
it.split("=").takeIf { it.size == 2 }?.let { (key, value) -> key to value }
185+
}.toMap()
190186
}
191187
}

0 commit comments

Comments
 (0)