commonMain.kiota.internal.SegmentUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kiota-url Show documentation
Show all versions of kiota-url Show documentation
A kotlin multiplatform library for representing headless collection based ui such as lists, tables and grids
package kiota.internal
import kiota.DynamicParamMatch
import kiota.ExactMatch
import kiota.SegmentMatch
import kiota.WildCardMatch
import kollections.Collection
import kollections.filterIsInstance
import kollections.forEachIndexed
import kollections.joinToString
import kollections.associate
private fun SegmentMatch.toScore() = when (this) {
is WildCardMatch -> 1
is DynamicParamMatch -> 2
is ExactMatch -> 3
}
internal fun Collection.toScore(): Int {
var score = 0
forEachIndexed { idx, segment ->
val level = idx + 1
score += level * segment.toScore()
}
return score
}
internal fun Collection.toEvaluatedUrl() = joinToString("/") { it.path }
internal fun Collection.toParams() = filterIsInstance().associate { it.key to it.value }