This commit is contained in:
Horis
2024-09-06 09:49:33 +08:00
parent 2198b6363c
commit ad08fa7b47
@@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import splitties.init.appCtx import splitties.init.appCtx
import java.util.regex.Matcher
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException import kotlin.coroutines.resumeWithException
@@ -36,7 +37,8 @@ fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): Stri
bindings["result"] = matcher.group() bindings["result"] = matcher.group()
eval(replacement1, bindings) eval(replacement1, bindings)
}.toString() }.toString()
matcher.appendReplacement(stringBuffer, jsResult) val quotedResult = Matcher.quoteReplacement(jsResult)
matcher.appendReplacement(stringBuffer, quotedResult)
} else { } else {
matcher.appendReplacement(stringBuffer, replacement1) matcher.appendReplacement(stringBuffer, replacement1)
} }
@@ -49,7 +51,8 @@ fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): Stri
} }
handler.postDelayed(timeout) { handler.postDelayed(timeout) {
if (coroutine.isActive) { if (coroutine.isActive) {
val timeoutMsg = "替换超时,3秒后还未结束将重启应用\n替换规则$regex\n替换内容:${this}" val timeoutMsg =
"替换超时,3秒后还未结束将重启应用\n替换规则$regex\n替换内容:$charSequence"
val exception = RegexTimeoutException(timeoutMsg) val exception = RegexTimeoutException(timeoutMsg)
block.cancel(exception) block.cancel(exception)
appCtx.longToastOnUi(timeoutMsg) appCtx.longToastOnUi(timeoutMsg)