|
|
@ -82,26 +82,17 @@ object AnalyzeTxtFile { |
|
|
|
val curChapter = BookChapter() |
|
|
|
val curChapter = BookChapter() |
|
|
|
curChapter.title = matcher.group() |
|
|
|
curChapter.title = matcher.group() |
|
|
|
curChapter.start = chapter.end |
|
|
|
curChapter.start = chapter.end |
|
|
|
curChapter.end = chapter.end |
|
|
|
|
|
|
|
toc.add(curChapter) |
|
|
|
toc.add(curChapter) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (toc.size != 0) { |
|
|
|
val lastChapter = toc.lastOrNull() |
|
|
|
//获取上一章节 |
|
|
|
lastChapter?.let { |
|
|
|
val lastChapter = toc.last() |
|
|
|
//上一章节结束等于这一章节开始 |
|
|
|
lastChapter.end = |
|
|
|
it.end = it.start!! + chapterContent.toByteArray(charset).size |
|
|
|
lastChapter.start!! + chapterContent.toByteArray(charset).size |
|
|
|
|
|
|
|
//创建当前章节 |
|
|
|
|
|
|
|
val curChapter = BookChapter() |
|
|
|
|
|
|
|
curChapter.title = matcher.group() |
|
|
|
|
|
|
|
curChapter.start = lastChapter.end |
|
|
|
|
|
|
|
toc.add(curChapter) |
|
|
|
|
|
|
|
} else { //如果章节不存在则创建章节 |
|
|
|
|
|
|
|
val curChapter = BookChapter() |
|
|
|
|
|
|
|
curChapter.title = matcher.group() |
|
|
|
|
|
|
|
curChapter.start = 0L |
|
|
|
|
|
|
|
curChapter.end = 0L |
|
|
|
|
|
|
|
toc.add(curChapter) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//创建当前章节 |
|
|
|
|
|
|
|
val curChapter = BookChapter() |
|
|
|
|
|
|
|
curChapter.title = matcher.group() |
|
|
|
|
|
|
|
curChapter.start = lastChapter?.end ?: 0 |
|
|
|
} |
|
|
|
} |
|
|
|
//设置指针偏移 |
|
|
|
//设置指针偏移 |
|
|
|
seekPos += chapterContent.length |
|
|
|
seekPos += chapterContent.length |
|
|
|