MANGA REGEX FIX
This commit is contained in:
parent
0d32342765
commit
b1eedce229
1 changed files with 10 additions and 1 deletions
|
@ -6,15 +6,24 @@ import java.util.regex.Pattern
|
||||||
class MangaNameAdapter {
|
class MangaNameAdapter {
|
||||||
companion object {
|
companion object {
|
||||||
const val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
|
const val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
|
||||||
|
const val filedChapterNumberRegex = "(?<!part\\s)\\b(\\d+)\\b"
|
||||||
fun findChapterNumber(text: String): Float? {
|
fun findChapterNumber(text: String): Float? {
|
||||||
val pattern: Pattern = Pattern.compile(chapterRegex, Pattern.CASE_INSENSITIVE)
|
val pattern: Pattern = Pattern.compile(chapterRegex, Pattern.CASE_INSENSITIVE)
|
||||||
val matcher: Matcher = pattern.matcher(text)
|
val matcher: Matcher = pattern.matcher(text)
|
||||||
|
|
||||||
return if (matcher.find()) {
|
return if (matcher.find()) {
|
||||||
matcher.group(2)?.toFloat()
|
matcher.group(2)?.toFloat()
|
||||||
|
} else {
|
||||||
|
val failedChapterNumberPattern: Pattern =
|
||||||
|
Pattern.compile(filedChapterNumberRegex, Pattern.CASE_INSENSITIVE)
|
||||||
|
val failedChapterNumberMatcher: Matcher =
|
||||||
|
failedChapterNumberPattern.matcher(text)
|
||||||
|
if (failedChapterNumberMatcher.find()) {
|
||||||
|
failedChapterNumberMatcher.group(1)?.toFloat()
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue