From 7d2379154252070b0b14b7f9e5a991bca7fe8902 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 15 Sep 2021 17:06:49 +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 --- .../io/legado/app/help/ContentProcessor.kt | 25 +++---------------- 1 file changed, 4 insertions(+), 21 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 829fea981..ccf4c1df9 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -65,27 +65,10 @@ class ContentProcessor private constructor( var mContent = content.trimStart { it.code <= 0x20 || it == ' ' || it == ',' || it == ',' } - //去除书名 - if (mContent.startsWith(book.name)) { - mContent = mContent.substring(book.name.length) - } - //去除带书名号的书名 - val cName = "《${book.name}》" - if (mContent.startsWith(cName)) { - mContent = mContent.substring(cName.length) - } - //去除无效内容 - mContent = mContent.trimStart { - it.code <= 0x20 || it == ' ' || it == ',' || it == ',' - } - //去除标题 - if (mContent.startsWith(chapter.title)) { - mContent = mContent.substring(chapter.title.length) - } - //去除无效内容 - mContent = mContent.trimStart { - it.code <= 0x20 || it == ' ' || it == ',' || it == ',' - } + //去除重复标题 + val titleRegex = + "^(\\s|\\pP)*《*(${book.name})*》*(\\s|\\pP)*${chapter.title}(\\s|\\pP)+".toRegex() + mContent = mContent.replace(titleRegex, "") if (includeTitle) { //重新添加标题 mContent = chapter.getDisplayTitle() + "\n" + mContent