Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,23 @@ 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
/**
* 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
Comment thread
Luna712 marked this conversation as resolved.
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)
Expand Down