Skip to content

Commit 7336de1

Browse files
committed
MatchNamedGroupCollection is in API 26
Use MatchGroupCollection to avoid NewApi issue
1 parent 3e94b11 commit 7336de1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

app/src/main/java/org/matrix/chromext/script/Local.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ object Local {
155155
if (eruda.exists() || versionText != null) {
156156
val verisonReg = Regex(" eruda v(?<version>[\\d\\.]+) https://")
157157
val firstLine = (versionText ?: FileReader(eruda).use { it.readText() }).lines()[0]
158-
val vMatchGroup = verisonReg.find(firstLine)?.groups as? MatchNamedGroupCollection
158+
val vMatchGroup = verisonReg.find(firstLine)?.groups
159159
if (vMatchGroup != null) {
160-
return vMatchGroup.get("version")?.value as String
160+
return vMatchGroup[1]?.value as String
161161
} else if (eruda.exists()) {
162162
eruda.delete()
163163
Log.toast(ctx, "Eruda.js is corrupted")

app/src/main/java/org/matrix/chromext/script/Parser.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.matrix.chromext.Chrome
88

99
private val blocksReg =
1010
Regex(
11-
"""(?<metablock>[\S\s]*?// ==UserScript==\r?\n([\S\s]*?)\r?\n// ==/UserScript==\s+)(?<code>[\S\s]*)""")
11+
"""(?<metablock>[\S\s]*?// ==UserScript==\r?\n[\S\s]*?\r?\n// ==/UserScript==\s+)(?<code>[\S\s]*)""")
1212
private val metaReg = Regex("""^//\s+@(?<key>[\w-]+)\s+(?<value>.+)""")
1313

1414
fun parseScript(input: String, storage: String? = null): Script? {
15-
val blockMatchGroup = blocksReg.matchEntire(input)?.groups as? MatchNamedGroupCollection
15+
val blockMatchGroup = blocksReg.matchEntire(input)?.groups
1616
if (blockMatchGroup == null) {
1717
return null
1818
}
@@ -25,15 +25,15 @@ fun parseScript(input: String, storage: String? = null): Script? {
2525
var grant = mutableListOf<String>()
2626
var exclude = mutableListOf<String>()
2727
var require = mutableListOf<String>()
28-
val meta = (blockMatchGroup.get("metablock")?.value as String)
29-
val code = blockMatchGroup.get("code")?.value as String
28+
val meta = (blockMatchGroup[1]?.value as String)
29+
val code = blockMatchGroup[2]?.value as String
3030
var storage: JSONObject? = null
3131
}
3232
script.meta.split("\n").forEach {
33-
val metaMatchGroup = metaReg.matchEntire(it)?.groups as? MatchNamedGroupCollection
33+
val metaMatchGroup = metaReg.matchEntire(it)?.groups
3434
if (metaMatchGroup != null) {
35-
val key = metaMatchGroup.get("key")?.value as String
36-
val value = metaMatchGroup.get("value")?.value as String
35+
val key = metaMatchGroup[1]?.value as String
36+
val value = metaMatchGroup[2]?.value as String
3737
when (key) {
3838
"name" -> script.name = value.replace(":", "")
3939
"namespace" -> script.namespace = value

0 commit comments

Comments
 (0)