pull/1319/head
gedoor 3 years ago
parent 11f5e5f611
commit 539105e4a5
  1. 6
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  2. 11
      app/src/main/java/io/legado/app/utils/StringUtils.kt

@ -6,10 +6,10 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.StringUtils
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import splitties.init.appCtx import splitties.init.appCtx
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.util.regex.Pattern
class ContentProcessor private constructor( class ContentProcessor private constructor(
private val bookName: String, private val bookName: String,
@ -67,8 +67,8 @@ class ContentProcessor private constructor(
if (includeTitle) { if (includeTitle) {
//去除重复标题 //去除重复标题
try { try {
val name = StringUtils.escapeToRegex(book.name) val name = Pattern.quote(book.name)
val title = StringUtils.escapeToRegex(chapter.title) val title = Pattern.quote(chapter.title)
val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex()
mContent = mContent.replace(titleRegex, "") mContent = mContent.replace(titleRegex, "")
} catch (e: Exception) { } catch (e: Exception) {

@ -313,17 +313,6 @@ object StringUtils {
return buf.toString() return buf.toString()
} }
private val regexNeedEscaped =
arrayOf("\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|")
fun escapeToRegex(text: String): String {
var str = text
regexNeedEscaped.forEach {
str = str.replace(it, "\\" + it)
}
return str
}
fun byteToHexString(bytes: ByteArray?): String { fun byteToHexString(bytes: ByteArray?): String {
if (bytes == null) return "" if (bytes == null) return ""
val sb = StringBuilder(bytes.size * 2) val sb = StringBuilder(bytes.size * 2)

Loading…
Cancel
Save