优化
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user