From 48b1fab76503ef2a30347545a3e9f65dbe9d5f61 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 Jan 2022 15:54:42 +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 --- .../java/io/legado/app/model/localBook/TextFile.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt index 22a6251f4..5c798627c 100644 --- a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt @@ -20,8 +20,7 @@ class TextFile(private val book: Book) { @Throws(FileNotFoundException::class) fun getChapterList(): ArrayList { - var rulePattern: Pattern? = null - if (book.charset == null || book.tocUrl.isEmpty()) { + val rulePattern: Pattern? = if (book.charset == null || book.tocUrl.isEmpty()) { LocalBook.getBookInputStream(book).use { bis -> val buffer = ByteArray(BUFFER_SIZE) var blockContent: String @@ -29,19 +28,19 @@ class TextFile(private val book: Book) { book.charset = EncodingDetect.getEncode(buffer) charset = book.fileCharset() blockContent = String(buffer, 0, length, charset) - rulePattern = if (book.tocUrl.isNotEmpty()) { - Pattern.compile(book.tocUrl, Pattern.MULTILINE) + if (book.tocUrl.isNotEmpty()) { + book.tocUrl.toPattern(Pattern.MULTILINE) } else { if (blockContent.isEmpty()) { length = bis.read(buffer) book.charset = EncodingDetect.getEncode(buffer) blockContent = String(buffer, 0, length, charset) } - getTocRule(blockContent)?.let { - Pattern.compile(it.rule, Pattern.MULTILINE) - } + getTocRule(blockContent)?.rule?.toPattern(Pattern.MULTILINE) } } + } else { + book.tocUrl.toPattern(Pattern.MULTILINE) } return analyze(rulePattern) }