Browse Source

Fix LDML range parsing

pull/4519/head
Chanjung Kim 8 months ago
parent
commit
c2ca9488e5
  1. 9
      components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralCondition.kt
  2. 5
      components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralOperand.kt
  3. 2
      components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralRuleList.kt

9
components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralCondition.kt

@ -120,6 +120,7 @@ internal sealed class PluralCondition {
't' -> PluralOperand.T 't' -> PluralOperand.T
'v' -> PluralOperand.V 'v' -> PluralOperand.V
'w' -> PluralOperand.W 'w' -> PluralOperand.W
'c', 'e' -> PluralOperand.C
else -> throw PluralConditionParseException(description) else -> throw PluralConditionParseException(description)
} }
} }
@ -165,14 +166,18 @@ internal sealed class PluralCondition {
return start..start return start..start
} }
consumeNext() consumeNext()
if (peekNext() != '.') throw PluralConditionParseException(description) if (consumeNext() != '.') throw PluralConditionParseException(description)
val endInclusive = consumeNextInt() val endInclusive = consumeNextInt()
return start..endInclusive return start..endInclusive
} }
fun nextCommaOrNull(): Char? { fun nextCommaOrNull(): Char? {
return when (peekNextOrNull()) { return when (peekNextOrNull()) {
',' -> ',' ',' -> {
consumeNext()
','
}
null -> null null -> null
else -> throw PluralConditionParseException(description) else -> throw PluralConditionParseException(description)
} }

5
components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralOperand.kt

@ -38,4 +38,9 @@ internal enum class PluralOperand {
* The visible fraction digits in the source number, *without* trailing zeros, expressed as an integer. * The visible fraction digits in the source number, *without* trailing zeros, expressed as an integer.
*/ */
T, T,
/**
* Compact decimal exponent value: exponent of the power of 10 used in compact decimal formatting.
*/
C,
} }

2
components/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/intl/PluralRuleList.kt

@ -58,7 +58,7 @@ internal class PluralRuleList private constructor(private val rules: Array<Plura
return null return null
} }
private fun createInstance(cldrLocaleName: String): PluralRuleList { internal fun createInstance(cldrLocaleName: String): PluralRuleList {
val cldrPluralRuleListIndex = cldrPluralRuleListIndexByLocale[cldrLocaleName]!! val cldrPluralRuleListIndex = cldrPluralRuleListIndexByLocale[cldrLocaleName]!!
val cldrPluralRuleList = cldrPluralRuleLists[cldrPluralRuleListIndex] val cldrPluralRuleList = cldrPluralRuleLists[cldrPluralRuleListIndex]
val pluralRules = cldrPluralRuleList.map { val pluralRules = cldrPluralRuleList.map {

Loading…
Cancel
Save