-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#43] Additional attributes per LocalizedString
- Loading branch information
1 parent
b0dae4d
commit c1f879f
Showing
19 changed files
with
493 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
...src/commonMain/kotlin/de/comahe/i18n4k/messages/formatter/parsing/MessageFormatContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
package de.comahe.i18n4k.messages.formatter.parsing | ||
|
||
import de.comahe.i18n4k.messages.formatter.MessageValueFormatter | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.ImmutableMap | ||
import kotlinx.collections.immutable.toImmutableList | ||
import kotlinx.collections.immutable.toPersistentMap | ||
|
||
data class MessageFormatContext( | ||
val formatterTypes : ImmutableMap<String, MessageValueFormatter> | ||
val formatterTypes: ImmutableMap<CharSequence, MessageValueFormatter>, | ||
val formatterPrefixTypes: ImmutableList<MessageValueFormatter>, | ||
) { | ||
constructor(formatters: Collection<MessageValueFormatter>) : | ||
this( | ||
@Suppress("USELESS_CAST") | ||
formatters.filter { !it.typeIdIsPrefix } | ||
.associateBy({ it.typeId as CharSequence }, { it }) | ||
.toPersistentMap(), | ||
formatters.filter { it.typeIdIsPrefix }.toImmutableList(), | ||
) | ||
|
||
fun getFormatterFor(typeId: CharSequence): MessageValueFormatter? { | ||
return formatterTypes[typeId] | ||
?: formatterPrefixTypes.firstOrNull { typeId.startsWith(it.typeId) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.