From 6b1637bef94da8df2ab873c7a12e3aa482215027 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 25 Mar 2020 08:14:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/localBook/AnalyzeTxtFile.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 4e51b9536..96de16e8c 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -60,16 +60,16 @@ class AnalyzeTxtFile { //获取文件中的数据到buffer,直到没有数据为止 while (bookStream.read(buffer, 0, buffer.size).also { length = it } > 0) { blockPos++ + var blockContent = String(buffer, charset) + val lastN = blockContent.lastIndexOf("\n") + if (lastN > 0) { + blockContent = blockContent.substring(0, lastN) + length = blockContent.toByteArray(charset).size + allLength += length + bookStream.seek(allLength.toLong()) + } //如果存在Chapter if (rulePattern != null) { //将数据转换成String - var blockContent = String(buffer, 0, length, charset) - val lastN = blockContent.lastIndexOf("\n") - if (lastN != 0) { - blockContent = blockContent.substring(0, lastN) - length = blockContent.toByteArray(charset).size - allLength += length - bookStream.seek(allLength.toLong()) - } //当前Block下使过的String的指针 var seekPos = 0 //进行正则匹配 @@ -80,6 +80,7 @@ class AnalyzeTxtFile { //获取章节内容 val chapterContent = blockContent.substring(seekPos, chapterStart) if (chapterContent.length > 30000 && pattern == null) { + //移除不匹配的规则 tocRules.remove(tocRule) return analyze(bookStream, book, null) }