From c2d2be6c0a1882d76d1df9fc0894af968140f402 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 19 Dec 2019 18:56:39 +0800 Subject: [PATCH] Fix unexpected space at the end of `toUHexString` result --- .../kotlin/net.mamoe.mirai/utils/io/ByteArrayUtil.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/ByteArrayUtil.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/ByteArrayUtil.kt index 65a4b16f8..57ba6971b 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/ByteArrayUtil.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/ByteArrayUtil.kt @@ -15,10 +15,10 @@ fun ByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: Int return buildString(length * 2) { this@toUHexString.forEachIndexed { index, it -> if (index in offset until lastIndex) { - var ret = it.toByte().toUByte().toString(16).toUpperCase() + var ret = it.toUByte().toString(16).toUpperCase() if (ret.length == 1) ret = "0$ret" append(ret) - if (index != lastIndex) append(separator) + if (index < lastIndex - 1) append(separator) } } } @@ -34,7 +34,7 @@ fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: In var ret = it.toByte().toUByte().toString(16).toUpperCase() if (ret.length == 1) ret = "0$ret" append(ret) - if (index != lastIndex) append(separator) + if (index < lastIndex - 1) append(separator) } } }