From 9313c297ce0e71c55a9ed983126df3313e529d3c Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Wed, 20 May 2026 10:37:22 -0600 Subject: [PATCH 1/2] SubtitleHelper: replace usage of java.lang.Character --- .../lagradost/cloudstream3/utils/SubtitleHelper.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt index 8d5479cc0ab..4e0313e6544 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt @@ -315,10 +315,17 @@ object SubtitleHelper { val flagOffset = 0x1F1E6 // regional indicator "[A]" val offset = flagOffset - asciiOffset - val firstChar: Int = Character.codePointAt(countryLetters, 0) + offset - val secondChar: Int = Character.codePointAt(countryLetters, 1) + offset + fun toSurrogatePair(codePoint: Int): String { + val high = ((codePoint - 0x10000) shr 10) + 0xD800 + val low = ((codePoint - 0x10000) and 0x3FF) + 0xDC00 + return "${high.toChar()}${low.toChar()}" + } + + val upperLetters = countryLetters.uppercase() + val first = upperLetters[0].code + offset + val second = upperLetters[1].code + offset - return String(Character.toChars(firstChar)) + String(Character.toChars(secondChar)) + return toSurrogatePair(first) + toSurrogatePair(second) } // when (langTag = country) or (langTag contains country) From f71f42a0ca268916a66dcc55dd438055c319b802 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Thu, 21 May 2026 16:22:47 -0600 Subject: [PATCH 2/2] Add comment --- .../com/lagradost/cloudstream3/utils/SubtitleHelper.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt index 4e0313e6544..7becf4d19c0 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/SubtitleHelper.kt @@ -315,6 +315,12 @@ object SubtitleHelper { val flagOffset = 0x1F1E6 // regional indicator "[A]" val offset = flagOffset - asciiOffset + /** + * Unicode surrogate pairs encode code points above U+FFFF (outside the Basic Multilingual Plane). + * The code point is offset by 0x10000, then split into two 10-bit halves: + * high surrogate: upper 10 bits, biased into the range 0xD800-0xDBFF + * low surrogate: lower 10 bits (masked with 0x3FF), biased into the range 0xDC00-0xDFFF + */ fun toSurrogatePair(codePoint: Int): String { val high = ((codePoint - 0x10000) shr 10) + 0xD800 val low = ((codePoint - 0x10000) and 0x3FF) + 0xDC00