File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
src/commonMain/kotlin/space/iseki/bencoding Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,20 @@ enum class BinaryStringStrategy {
2626
2727 context(BencodeDecoder )
2828 @OptIn(ExperimentalEncodingApi ::class )
29- internal fun decodeString (strategy : BinaryStringStrategy ): String {
30- return when ( if ( strategy == Default ) options.binaryStringStrategy else strategy) {
31- ISO88591 , Default -> bytes2StringIso88591(decodeByteArray())
32- Base64 -> kotlin.io.encoding. Base64 .encode (decodeByteArray())
33- }
34- }
29+ internal fun decodeString (strategy : BinaryStringStrategy ) = work(
30+ strategy = strategy,
31+ options = options,
32+ iso88591 = { bytes2StringIso88591 (decodeByteArray()) },
33+ base64 = { kotlin.io.encoding. Base64 .encode(decodeByteArray()) },
34+ )
3535
36+ private inline fun <T > work (
37+ strategy : BinaryStringStrategy ,
38+ options : BencodeOptions ,
39+ iso88591 : () -> T ,
40+ base64 : () -> T ,
41+ ): T = when (if (strategy == Default ) options.binaryStringStrategy else strategy) {
42+ ISO88591 , Default -> iso88591()
43+ Base64 -> base64()
44+ }
3645}
You can’t perform that action at this time.
0 commit comments