Fix is valid pinyin method

This commit is contained in:
Marvin Elsen 2024-09-20 13:23:01 +02:00
parent e1dbdb37eb
commit 7c0820fc36
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2

View File

@ -15,7 +15,9 @@ data class Syllable(
private val zhuyinToneMarkRegex = """[ˊˇˋ˙]""".toRegex()
fun isValidPinyinWithToneNumberSyllable(pinyinSyllable: String) =
pinyinSyllable.last().isDigit() && pinyinSyllable.last().digitToInt() in 1..5 && pinyinSyllable.lowercase() in pinyinToZhuyin
pinyinSyllable.last().isDigit() && pinyinSyllable.last().digitToInt() in 1..5 && pinyinSyllable
.substring(0, pinyinSyllable.lastIndex)
.lowercase() in pinyinToZhuyin
fun fromPinyinWithToneNumber(pinyinWithToneNumber: String): Syllable {
val pinyinWithoutNumber = pinyinWithToneNumber.substring(0, pinyinWithToneNumber.lastIndex)
@ -45,7 +47,7 @@ data class Syllable(
return Syllable(
zhuyinToPinyin[zhuyinWithoutToneMark]!!,
Tone.fromZhuyinToneMarkOrNull(zhuyin.last()) ?: Tone.fromZhuyinToneMarkOrNull(zhuyin.first())
?: Tone.FIRST
?: Tone.FIRST
)
}