From 296f839f7c30473a8e554dbc3fd1dc2d241f816a Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Tue, 6 Apr 2021 06:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20by=20=E8=A7=84=E5=88=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/model/localBook/LocalBook.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index f23172ccd..a01efaee0 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -65,22 +65,29 @@ object LocalBook { || (fileName.contains(" by ", true)) ) { + //匹配(知轩藏书常用格式) 《书名》其它信息作者:作者名.txt val m1 = Pattern - .compile("《(.*?)》.*?作者:(.*?).txt") + .compile("《(.*?)》.*?作者:(.*?)\\.txt") .matcher(fileName) //匹配 书名 by 作者名.txt val m2 = Pattern - .compile("(.*?) by (.*?).txt") - .matcher(fileName) + .compile("txt\\.(.*?) yb (.*?)$") + .matcher(fileName.reversed()) if (m1.find()) { name = m1.group(1) ?: fileName.replace(".txt", "") author = m1.group(2) ?: "" BookHelp.formatBookAuthor(author) } else if (m2.find()) { - name = m2.group(1) ?: fileName.replace(".txt", "") - author = m2.group(2) ?: "" + var temp = m2.group(2) + name = if (temp==null||temp == "") { + fileName.replace(".txt", "") + } else { + temp.reversed() + } + temp = m2.group(1) ?: "" + author = temp.reversed() BookHelp.formatBookAuthor(author) } else { @@ -89,7 +96,7 @@ object LocalBook { name = if (e > st && st != -1) { fileName.substring(st + 1, e) } else { - fileName + fileName.replace(".txt", "") }