Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Jan 6, 2022
1 parent d9f00f5 commit 48b1fab
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/src/main/java/io/legado/app/model/localBook/TextFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ class TextFile(private val book: Book) {

@Throws(FileNotFoundException::class)
fun getChapterList(): ArrayList<BookChapter> {
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
var length = bis.read(buffer)
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)
}
Expand Down

0 comments on commit 48b1fab

Please # to comment.