|
|
@@ -149,11 +149,20 @@ class TextFile(private val book: Book) {
|
|
|
val chapterLength = chapterContent.toByteArray(charset).size
|
|
|
val lastStart = toc.lastOrNull()?.start ?: curOffset
|
|
|
if (curOffset + chapterLength - lastStart > maxLengthWithToc) {
|
|
|
+ toc.lastOrNull()?.let {
|
|
|
+ it.end = it.start
|
|
|
+ }
|
|
|
toc.addAll(analyze(lastStart, curOffset + chapterLength))
|
|
|
- }
|
|
|
- //如果 seekPos == 0 && chapterStart != 0 表示当前block处前面有一段内容
|
|
|
- //第一种情况一定是序章 第二种情况是上一个章节的内容
|
|
|
- if (seekPos == 0 && chapterStart != 0) { //获取当前章节的内容
|
|
|
+ //创建当前章节
|
|
|
+ val curChapter = BookChapter()
|
|
|
+ curChapter.title = matcher.group()
|
|
|
+ curChapter.start = curOffset + chapterLength
|
|
|
+ toc.add(curChapter)
|
|
|
+ } else if (seekPos == 0 && chapterStart != 0) {
|
|
|
+ /*
|
|
|
+ * 如果 seekPos == 0 && chapterStart != 0 表示当前block处前面有一段内容
|
|
|
+ * 第一种情况一定是序章 第二种情况是上一个章节的内容
|
|
|
+ */
|
|
|
if (toc.isEmpty()) { //如果当前没有章节,那么就是序章
|
|
|
//加入简介
|
|
|
if (StringUtils.trim(chapterContent).isNotEmpty()) {
|
|
|
@@ -186,7 +195,7 @@ class TextFile(private val book: Book) {
|
|
|
if (toc.isNotEmpty()) { //获取章节内容
|
|
|
//获取上一章节
|
|
|
val lastChapter = toc.last()
|
|
|
- toc.last().isVolume =
|
|
|
+ lastChapter.isVolume =
|
|
|
chapterContent.substringAfter(lastChapter.title).isBlank()
|
|
|
lastChapter.end =
|
|
|
lastChapter.start!! + chapterContent.toByteArray(charset).size.toLong()
|
|
|
@@ -264,7 +273,7 @@ class TextFile(private val book: Book) {
|
|
|
//分章的位置
|
|
|
chapterPos = 0
|
|
|
while (strLength > 0) {
|
|
|
- ++chapterPos
|
|
|
+ chapterPos++
|
|
|
//是否长度超过一章
|
|
|
if (strLength > maxLengthWithNoToc) { //在buffer中一章的终止点
|
|
|
var end = length
|
|
|
@@ -297,7 +306,7 @@ class TextFile(private val book: Book) {
|
|
|
//设置结尾章节
|
|
|
if (bufferStart > 100) {
|
|
|
val chapter = BookChapter()
|
|
|
- chapter.title = "第${blockPos}章(${chapterPos + 1})"
|
|
|
+ chapter.title = "第${blockPos}章(${chapterPos})"
|
|
|
chapter.start = toc.lastOrNull()?.end ?: curOffset
|
|
|
chapter.end = chapter.start!! + bufferStart
|
|
|
toc.add(chapter)
|