Skip to content

Commit

Permalink
MANGA REGEX FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 19, 2024
1 parent 0d32342 commit b1eedce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/src/main/java/ani/dantotsu/media/manga/MangaNameAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ import java.util.regex.Pattern
class MangaNameAdapter {
companion object {
const val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
const val filedChapterNumberRegex = "(?<!part\\s)\\b(\\d+)\\b"
fun findChapterNumber(text: String): Float? {
val pattern: Pattern = Pattern.compile(chapterRegex, Pattern.CASE_INSENSITIVE)
val matcher: Matcher = pattern.matcher(text)

return if (matcher.find()) {
matcher.group(2)?.toFloat()
} else {
null
val failedChapterNumberPattern: Pattern =
Pattern.compile(filedChapterNumberRegex, Pattern.CASE_INSENSITIVE)
val failedChapterNumberMatcher: Matcher =
failedChapterNumberPattern.matcher(text)
if (failedChapterNumberMatcher.find()) {
failedChapterNumberMatcher.group(1)?.toFloat()
} else {
null
}
}
}
}
Expand Down

0 comments on commit b1eedce

Please sign in to comment.