修复txt标题识别不出来导致末尾章节太长加载不出来

This commit is contained in:
kunfei
2023-03-16 09:46:14 +08:00
parent ae0332486d
commit 069b4dc91f
@@ -259,6 +259,24 @@ class TextFile(private val book: Book) {
curOffset += length.toLong()
//设置上一章的结尾
toc.lastOrNull()?.end = curOffset
}
toc.lastOrNull()?.let { chapter ->
if (chapter.end!! - chapter.start!! > maxLengthWithToc) {
val end = chapter.end!!
chapter.end = chapter.start
//章节字数太多进行拆分
val lastTitle = chapter.title
val lastTitleLength = lastTitle.toByteArray(charset).size
val chapters = analyze(
chapter.start!! + lastTitleLength,
end
)
chapters.forEachIndexed { index, bookChapter ->
bookChapter.title = "$lastTitle(${index + 1})"
}
toc.addAll(chapters)
}
}
}
System.gc()