Add method to test whether a string is a valid pinyin with tone number syllable #1

Merged
marvinelsen merged 2 commits from add-is-valid-method into main 2024-09-20 10:58:27 +00:00
Showing only changes of commit e897dd3c82 - Show all commits

View File

@ -13,6 +13,9 @@ data class Syllable(
private val zhuyinToPinyin = pinyinToZhuyin.entries.associate { it.value to it.key }
private val zhuyinToneMarkRegex = """[ˊˇˋ˙]""".toRegex()
fun isValidPinyinWithToneNumberSyllable(pinyinSyllable: String) =
pinyinSyllable.last().isDigit() && pinyinSyllable.last().digitToInt() in 1..5 && pinyinSyllable.lowercase() in pinyinToZhuyin
fun fromPinyinWithToneNumber(pinyinWithToneNumber: String): Syllable {
val pinyinWithoutNumber = pinyinWithToneNumber.substring(0, pinyinWithToneNumber.lastIndex)
val lastCharacter = pinyinWithToneNumber.last()