Compare commits
No commits in common. "e1dbdb37eb419cccc176c5603bb9dbc97e105020" and "18cb0cd0c85151a7af1370d5b83b0f20dbc66c89" have entirely different histories.
e1dbdb37eb
...
18cb0cd0c8
@ -2,7 +2,6 @@ package com.marvinelsen.chinese.transliteration
|
|||||||
|
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@Suppress("MagicNumber", "MaximumLineLength", "MaxLineLength")
|
|
||||||
data class Syllable(
|
data class Syllable(
|
||||||
val pinyinSyllableWithoutTone: String,
|
val pinyinSyllableWithoutTone: String,
|
||||||
val tone: Tone,
|
val tone: Tone,
|
||||||
@ -14,9 +13,6 @@ data class Syllable(
|
|||||||
private val zhuyinToPinyin = pinyinToZhuyin.entries.associate { it.value to it.key }
|
private val zhuyinToPinyin = pinyinToZhuyin.entries.associate { it.value to it.key }
|
||||||
private val zhuyinToneMarkRegex = """[ˊˇˋ˙]""".toRegex()
|
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 {
|
fun fromPinyinWithToneNumber(pinyinWithToneNumber: String): Syllable {
|
||||||
val pinyinWithoutNumber = pinyinWithToneNumber.substring(0, pinyinWithToneNumber.lastIndex)
|
val pinyinWithoutNumber = pinyinWithToneNumber.substring(0, pinyinWithToneNumber.lastIndex)
|
||||||
val lastCharacter = pinyinWithToneNumber.last()
|
val lastCharacter = pinyinWithToneNumber.last()
|
||||||
@ -24,6 +20,7 @@ data class Syllable(
|
|||||||
require(lastCharacter.isDigit()) {
|
require(lastCharacter.isDigit()) {
|
||||||
"'$pinyinWithToneNumber' is not a valid Pinyin with tone number syllable. Expected the last character to be a digit, but was '${pinyinWithToneNumber.last()}'"
|
"'$pinyinWithToneNumber' is not a valid Pinyin with tone number syllable. Expected the last character to be a digit, but was '${pinyinWithToneNumber.last()}'"
|
||||||
}
|
}
|
||||||
|
@Suppress("MagicNumber")
|
||||||
require(lastCharacter.digitToInt() in 1..5) {
|
require(lastCharacter.digitToInt() in 1..5) {
|
||||||
"'$pinyinWithToneNumber' is not a valid Pinyin with tone number syllable. Expected the tone number 'n' to be in range 1 <= n <= 5, but was '${pinyinWithToneNumber.last()}'"
|
"'$pinyinWithToneNumber' is not a valid Pinyin with tone number syllable. Expected the tone number 'n' to be in range 1 <= n <= 5, but was '${pinyinWithToneNumber.last()}'"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user