修复 by 规则bug

pull/935/head
ag2s20150909 4 years ago
parent 1adc1db65b
commit 296f839f7c
  1. 19
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@ -65,22 +65,29 @@ object LocalBook {
|| (fileName.contains(" by ", true)) || (fileName.contains(" by ", true))
) { ) {
//匹配(知轩藏书常用格式) 《书名》其它信息作者:作者名.txt //匹配(知轩藏书常用格式) 《书名》其它信息作者:作者名.txt
val m1 = Pattern val m1 = Pattern
.compile("《(.*?)》.*?作者:(.*?).txt") .compile("《(.*?)》.*?作者:(.*?)\\.txt")
.matcher(fileName) .matcher(fileName)
//匹配 书名 by 作者名.txt //匹配 书名 by 作者名.txt
val m2 = Pattern val m2 = Pattern
.compile("(.*?) by (.*?).txt") .compile("txt\\.(.*?) yb (.*?)$")
.matcher(fileName) .matcher(fileName.reversed())
if (m1.find()) { if (m1.find()) {
name = m1.group(1) ?: fileName.replace(".txt", "") name = m1.group(1) ?: fileName.replace(".txt", "")
author = m1.group(2) ?: "" author = m1.group(2) ?: ""
BookHelp.formatBookAuthor(author) BookHelp.formatBookAuthor(author)
} else if (m2.find()) { } else if (m2.find()) {
name = m2.group(1) ?: fileName.replace(".txt", "") var temp = m2.group(2)
author = m2.group(2) ?: "" name = if (temp==null||temp == "") {
fileName.replace(".txt", "")
} else {
temp.reversed()
}
temp = m2.group(1) ?: ""
author = temp.reversed()
BookHelp.formatBookAuthor(author) BookHelp.formatBookAuthor(author)
} else { } else {
@ -89,7 +96,7 @@ object LocalBook {
name = if (e > st && st != -1) { name = if (e > st && st != -1) {
fileName.substring(st + 1, e) fileName.substring(st + 1, e)
} else { } else {
fileName fileName.replace(".txt", "")
} }

Loading…
Cancel
Save