You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/kotlin/unsigned/java_1_7/int.kt
+11-13Lines changed: 11 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -19,19 +19,17 @@ fun compare(a: Int, b: Int) = if (a < b) -1 else if (a == b) 0 else 1
19
19
fun String.parseUnsignedInt(radix:Int): Int {
20
20
21
21
if (length >0) {
22
-
val firstChar =this[0]
23
-
if (firstChar =='-')
24
-
throwNumberFormatException(String.format("Illegal leading minus sign "+"on unsigned string %s.", this))
25
-
else {
26
-
if (length <=5||// Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
27
-
radix ==10&& length <=9) // Integer.MAX_VALUE in base 10 is 10 digits
28
-
returnthis.toInt(radix)
29
-
else {
30
-
val ell =this.toLong(radix)
31
-
if (ell andBigInteger("ffffffff00000000", 16).toLong() ==0L)
32
-
return ell.toInt()
33
-
else
34
-
throwNumberFormatException(String.format("String value %s exceeds "+"range of unsigned int.", this))
22
+
returnwhen (this[0]) {
23
+
'-'->throwNumberFormatException(String.format("Illegal leading minus sign "+"on unsigned string %s.", this))
24
+
else->when {
25
+
length <=5||/* Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits */ radix ==10&& length <=9/* Integer.MAX_VALUE in base 10 is 10 digits*/->this.toInt(radix)
0 commit comments