From 539105e4a59644cf424c0f74a7acc1351a630bbe Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 16 Sep 2021 10:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/ContentProcessor.kt | 6 +++--- app/src/main/java/io/legado/app/utils/StringUtils.kt | 11 ----------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 82eba7c36..fbfbf913e 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -6,10 +6,10 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.ReplaceRule -import io.legado.app.utils.StringUtils import io.legado.app.utils.toastOnUi import splitties.init.appCtx import java.lang.ref.WeakReference +import java.util.regex.Pattern class ContentProcessor private constructor( private val bookName: String, @@ -67,8 +67,8 @@ class ContentProcessor private constructor( if (includeTitle) { //去除重复标题 try { - val name = StringUtils.escapeToRegex(book.name) - val title = StringUtils.escapeToRegex(chapter.title) + val name = Pattern.quote(book.name) + val title = Pattern.quote(chapter.title) val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() mContent = mContent.replace(titleRegex, "") } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 0bb0f025f..d9ab96b62 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -313,17 +313,6 @@ object StringUtils { 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 { if (bytes == null) return "" val sb = StringBuilder(bytes.size * 2)