in runtime/src/main/scala/org/apache/pekko/grpc/scaladsl/headers/PercentEncoding.scala [84:112]
def decode(value: String): String =
if (value.indexOf('%') > -1)
decodeSlow(value)
else
value
private def decodeSlow(value: String): String = {
val source = value.getBytes(TransferEncoding)
val buf = ByteBuffer.allocate(source.length)
var i = 0
while (i < source.length) {
if (source(i) == '%' && i + 2 < source.length) {
val ch0 = Character.digit(source(i + 1), 16)
val ch1 = Character.digit(source(i + 2), 16)
if (ch0 > -1 && ch1 > -1) {
val res = (ch0 << 4) + ch1
buf.put(res.toByte)
i += 3
} else {
buf.put(source(i))
i += 1
}
} else {
buf.put(source(i))
i += 1
}
}
new String(buf.array, 0, buf.position(), StandardCharsets.UTF_8)
}