pull/2457/head
kunfei 2 years ago
parent c40d59d71d
commit 94287b106a
  1. 2
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  2. 2
      app/src/main/java/io/legado/app/help/book/ContentProcessor.kt
  3. 8
      app/src/main/java/io/legado/app/utils/RegexExtensions.kt

@ -103,7 +103,7 @@ data class BookChapter(
displayTitle.replaceRegex(
item.pattern,
item.replacement
)
).getOrThrow()
} else {
displayTitle.replace(item.pattern, item.replacement)
}

@ -144,7 +144,7 @@ class ContentProcessor private constructor(
mContent.replaceRegex(
item.pattern,
item.replacement
)
).getOrThrow()
} else {
mContent.replace(item.pattern, item.replacement)
}

@ -1,6 +1,5 @@
package io.legado.app.utils
import android.util.Log
import com.google.re2j.Pattern
import com.script.SimpleBindings
import io.legado.app.constant.AppConst
@ -8,7 +7,8 @@ import io.legado.app.constant.AppConst
/**
* 带有超时检测的正则替换
*/
fun CharSequence.replaceRegex(regex: String, replacement: String): String {
fun CharSequence.replaceRegex(regex: String, replacement: String): Result<String> {
return kotlin.runCatching {
val charSequence = this
val isJs = replacement.startsWith("@js:")
val replacement1 = if (isJs) replacement.substring(4) else replacement
@ -27,7 +27,7 @@ fun CharSequence.replaceRegex(regex: String, replacement: String): String {
}
}
matcher.appendTail(stringBuffer)
Log.e("regex", "end")
return stringBuffer.toString()
stringBuffer.toString()
}
}

Loading…
Cancel
Save