Skip to content

Commit 792ce91

Browse files
committed
refactor: replace throw IllegalArgumentException with require for error checks in BaseRadix
1 parent 394f7ea commit 792ce91

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/commonMain/kotlin/com/eignex/kencode/BaseRadix.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ open class BaseRadix(private val alphabet: String, val blockSize: Int = 32) :
8585
val fullBlocks = input.length / fullBlockLen
8686
val lastBlockLen = input.length % fullBlockLen
8787

88-
if (lastBlockLen != 0 && lastBlockLen !in lengths) {
89-
throw IllegalArgumentException("Invalid encoded length: ${input.length}")
90-
}
88+
require(!(lastBlockLen != 0 && lastBlockLen !in lengths)) { "Invalid encoded length: ${input.length}" }
9189

9290
val lastOutLen =
9391
if (lastBlockLen > 0) invLengths[lastBlockLen - 1] else 0
@@ -151,15 +149,15 @@ open class BaseRadix(private val alphabet: String, val blockSize: Int = 32) :
151149
val code = input[i].code
152150
val index =
153151
if (code < inverseAlphabet.size) inverseAlphabet[code] else -1
154-
if (index < 0) throw IllegalArgumentException("Not an encoding char: '${input[i]}'")
152+
require(index >= 0) { "Not an encoding char: '${input[i]}'" }
155153
n = n * base + BigInteger.fromLong(index.toLong())
156154
}
157155

158156
for (i in outLen - 1 downTo 0) {
159157
output[outPos + i] = (n and bigFF).byteValue(exactRequired = false)
160158
n = n shr 8
161159
}
162-
if (n != bigZero) throw IllegalArgumentException("Invalid encoding block.")
160+
require(n == bigZero) { "Invalid encoding block." }
163161
return output
164162
}
165163
}

0 commit comments

Comments
 (0)