@@ -23,7 +23,7 @@ fun String.urlEncodeComponent(
2323 ' ' -> if (formUrlEncode) sb.append(" +" ) else sb.append(" %20" )
2424 // $2.3 Unreserved characters
2525 in ' a' .. ' z' , in ' A' .. ' Z' , in ' 0' .. ' 9' , ' -' , ' _' , ' .' , ' ~' -> sb.append(chr)
26- else -> sb.append( cbyte.percentEncode() )
26+ else -> cbyte.percentEncodeTo(sb )
2727 }
2828 }
2929
@@ -87,7 +87,7 @@ fun String.encodeUrlPath(validDelimiters: Set<Char>, checkPercentEncoded: Boolea
8787 when (val chr = cbyte.toInt().toChar()) {
8888 // unreserved
8989 in ' a' .. ' z' , in ' A' .. ' Z' , in ' 0' .. ' 9' , in validDelimiters -> sb.append(chr)
90- else -> sb.append( cbyte.percentEncode() )
90+ else -> cbyte.percentEncodeTo(sb )
9191 }
9292 i++
9393 }
@@ -99,13 +99,17 @@ private const val upperHex: String = "0123456789ABCDEF"
9999private val upperHexSet = upperHex.toSet()
100100
101101// $2.1 Percent-Encoding
102- private fun Byte.percentEncode (): String = buildString(3 ) {
102+ @InternalApi
103+ fun Byte.percentEncodeTo (out : Appendable ) {
103104 val code = toInt() and 0xff
104- append(' %' )
105- append(upperHex[code shr 4 ])
106- append(upperHex[code and 0x0f ])
105+ out . append(' %' )
106+ out . append(upperHex[code shr 4 ])
107+ out . append(upperHex[code and 0x0f ])
107108}
108109
110+ @InternalApi
111+ fun Byte.percentEncode (): String = StringBuilder (3 ).also (::percentEncodeTo).toString()
112+
109113/* *
110114 * Split a (decoded) query string "foo=baz&bar=quux" into it's component parts
111115 */
0 commit comments