|
|
@ -327,39 +327,46 @@ object BookHelp { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val chapterNamePattern by lazy { |
|
|
|
private val chapterNamePattern1 by lazy { |
|
|
|
Pattern.compile("^(.*?第([\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9\\s]+)[章节篇回集])[、,。 ::.\\s]*") |
|
|
|
Pattern.compile(".*?第([\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9\\s]+)[章节篇回集话]") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val chapterNamePattern2 by lazy { |
|
|
|
|
|
|
|
Pattern.compile("^(?:[\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9]+\\s*[,:,:、]\\s*)*([\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9]+)\\s*(?:[,:,:、]|[..][^\\d0-9])") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getChapterNum(chapterName: String?): Int { |
|
|
|
private fun getChapterNum(chapterName: String?): Int { |
|
|
|
if (chapterName != null) { |
|
|
|
chapterName?:return -1 |
|
|
|
val matcher: Matcher = chapterNamePattern.matcher(chapterName) |
|
|
|
return StringUtils.stringToInt( |
|
|
|
if (matcher.find()) { |
|
|
|
( |
|
|
|
return StringUtils.stringToInt(matcher.group(2)) |
|
|
|
chapterNamePattern1.matcher(chapterName).takeIf{it.find()} |
|
|
|
} |
|
|
|
?:chapterNamePattern2.matcher(chapterName).takeIf{it.find()} |
|
|
|
} |
|
|
|
)?.group(1) |
|
|
|
return -1 |
|
|
|
?:"-1" |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("SpellCheckingInspection") |
|
|
|
@Suppress("SpellCheckingInspection") |
|
|
|
private val regexOther by lazy { |
|
|
|
private val regexOther by lazy { |
|
|
|
// 所有非字母数字中日韩文字 CJK区+扩展A-F区 |
|
|
|
// 所有非字母数字中日韩文字及空白字符 CJK区+扩展A-F区 |
|
|
|
return@lazy "[^\\w\\u4E00-\\u9FEF〇\\u3400-\\u4DBF\\u20000-\\u2A6DF\\u2A700-\\u2EBEF]".toRegex() |
|
|
|
return@lazy "[^\\w\\u4E00-\\u9FEF〇\\u3400-\\u4DBF\\u20000-\\u2A6DF\\u2A700-\\u2EBEF]|\\s".toRegex() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val regexA by lazy { |
|
|
|
private val regexA by lazy { |
|
|
|
return@lazy "\\s".toRegex() |
|
|
|
//章节序号,排除处于结尾的状况,避免将章节名替换为空字串 |
|
|
|
|
|
|
|
return@lazy "^.*?第(?:[\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9]+)[章节篇回集话](?!$)|^(?:[\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9]+[,:,:、])*(?:[\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9]+)(?:[,:,:、](?!$)|[..](?=[^\\d0-9]))".toRegex() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val regexB by lazy { |
|
|
|
private val regexB by lazy { |
|
|
|
return@lazy "^第.*?章|[(\\[][^()\\[\\]]{2,}[)\\]]$".toRegex() |
|
|
|
//前后附加内容,整个章节名都在括号中时只剔除首尾括号,避免将章节名替换为空字串 |
|
|
|
|
|
|
|
return@lazy "(?!^)(?:[〖【(《〈〔[{\\[{(][^〖【(《〈〔[{\\[{()}]〕〉》)】〗\\]}]+)?[)}]〕〉》)】〗\\]}]$|^[〖【(《〈〔[{\\[{(](?:[^〖【(《〈〔[{\\[{()}]〕〉》)】〗\\]}]+[)}]〕〉》)】〗\\]}])?(?!$)".toRegex() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getPureChapterName(chapterName: String?): String { |
|
|
|
private fun getPureChapterName(chapterName: String?): String { |
|
|
|
return if (chapterName == null) "" else StringUtils.fullToHalf(chapterName) |
|
|
|
return if (chapterName == null) "" else StringUtils.fullToHalf(chapterName) |
|
|
|
|
|
|
|
.replace(regexOther, "") |
|
|
|
.replace(regexA, "") |
|
|
|
.replace(regexA, "") |
|
|
|
.replace(regexB, "") |
|
|
|
.replace(regexB, "") |
|
|
|
.replace(regexOther, "") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|