commonMain.fuel.Parameters.kt Maven / Gradle / Ivy
package fuel
public fun String.fillURLWithParameters(parameters: List>): String {
val joiner =
if (this.contains("?")) {
if (parameters.isNotEmpty()) {
"&"
} else {
// There is already a trailing ?
""
}
} else {
"?"
}
return this + joiner + parameters.formUrlEncode()
}
private fun List>.formUrlEncode(): String = buildString { formUrlEncodeTo(this) }
private fun List>.formUrlEncodeTo(out: Appendable) {
joinTo(out, "&") {
val key = UriCodec.encode(it.first)
val value = UriCodec.encode(it.second)
"$key=$value"
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy