优化链接分割规则,避免附加参数中存在 ,{ 时导致规则切错

修复<str0,str2,...{{js}}>这种页数列表写法中,js部分内含 < 或 > 会切割错误的问题

格式化图片和匹配图片规则不在使用同一个正则,加快图片处理速度。

优化一下不需要循环执行却被循环执行的操作
pull/1123/head
bushixuanqi 4 years ago
parent 53f9e4ca42
commit 07dcc01842
  1. 10
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 30
      app/src/main/java/io/legado/app/service/help/ReadBook.kt

@ -5,14 +5,14 @@ import java.util.regex.Pattern
@Suppress("RegExpRedundantEscape") @Suppress("RegExpRedundantEscape")
object AppPattern { object AppPattern {
val JS_PATTERN: Pattern = val JS_PATTERN: Pattern =
Pattern.compile("(<js>[\\w\\W]*?</js>|@js:[\\w\\W]*$)", Pattern.CASE_INSENSITIVE) Pattern.compile("<js>([\\w\\W]+?)</js>|@js:([\\w\\W]*)", Pattern.CASE_INSENSITIVE)
val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}") val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}")
//图片有data-开头的数据属性时优先用数据属性作为src,没有数据属性时才匹配src
val imgPattern: Pattern = //匹配格式化后的图片格式
Pattern.compile("<img(?:(?![^>]*data-)[^>]*src|[^>]*data-)[^=]*= *\"([^\"{]+(?:\\{(?:[^{}]|\\{[^{}]*\\})*\\})?)\"[^>]*>", Pattern.CASE_INSENSITIVE) val imgPattern: Pattern = Pattern.compile("<img src=\"([^>]+)\">")
val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著") val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著")
val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著") val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著")
val fileNameRegex = Regex("[\\\\/:*?\"<>|.]") val fileNameRegex = Regex("[\\\\/:*?\"<>|.]")
val splitGroupRegex = Regex("[,;,;]") val splitGroupRegex = Regex("[,;,;]")
} }

@ -415,30 +415,22 @@ object ReadBook {
else -> chapter.title else -> chapter.title
} }
val contents = contentProcessor!!.getContent(book, chapter.title, content) val contents = contentProcessor!!.getContent(book, chapter.title, content)
when (chapter.index) { val textChapter = ChapterProvider.getTextChapter(book, chapter,contents,chapterSize)
durChapterIndex -> {
curTextChapter = val offset = chapter.index - durChapterIndex
ChapterProvider.getTextChapter( if (upContent) callBack?.upContent(offset ,resetPageOffset)
book, chapter, contents, chapterSize when (offset) {
) 0 -> {
if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) curTextChapter = textChapter
callBack?.upView() callBack?.upView()
curPageChanged() curPageChanged()
callBack?.contentLoadFinish() callBack?.contentLoadFinish()
} }
durChapterIndex - 1 -> { - 1 -> {
prevTextChapter = prevTextChapter = textChapter
ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize
)
if (upContent) callBack?.upContent(-1, resetPageOffset)
} }
durChapterIndex + 1 -> { 1 -> {
nextTextChapter = nextTextChapter = textChapter
ChapterProvider.getTextChapter(
book, chapter, contents, chapterSize
)
if (upContent) callBack?.upContent(1, resetPageOffset)
} }
} }
} }

Loading…
Cancel
Save