From 8bc3631964a41edbe38df420de76ea2d4a0283e1 Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:20:50 -0600 Subject: [PATCH] subdub regex function --- .../dantotsu/media/anime/AnimeNameAdapter.kt | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt index 272464ac23..ccc44eeca4 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeNameAdapter.kt @@ -1,5 +1,6 @@ package ani.dantotsu.media.anime +import java.util.Locale import java.util.regex.Matcher import java.util.regex.Pattern @@ -10,7 +11,39 @@ class AnimeNameAdapter { const val failedEpisodeNumberRegex = "(? "sub" + SubDubType.DUB -> "dub" + } + val toggledCasePreserved = + if (subdub?.get(0)?.isUpperCase() == true || soft?.get(0) + ?.isUpperCase() == true + ) toggled.replaceFirstChar { + if (it.isLowerCase()) it.titlecase( + Locale.ROOT + ) else it.toString() + } else toggled + + subdubMatcher.replaceFirst(toggledCasePreserved + bed) + } else { + null + } + } + + enum class SubDubType { + SUB, DUB + } fun findSeasonNumber(text: String): Int? { val seasonPattern: Pattern = Pattern.compile(seasonRegex, Pattern.CASE_INSENSITIVE)