Deprecate parseInt and parseFloat. Replace deprecated usages in tests.

#KT-4497
This commit is contained in:
Ilya Gorbunov
2017-01-23 18:15:30 +03:00
parent 4e5e14c9a0
commit 4018d10bf6
8 changed files with 10 additions and 17 deletions
+2 -1
View File
@@ -7,9 +7,10 @@ public external fun eval(expr: String): dynamic = noImpl
public external val undefined: Nothing? = noImpl
@Deprecated("Use toInt(radix) instead.", ReplaceWith("s.toInt(radix)"), level = DeprecationLevel.ERROR)
public external fun parseInt(s: String, radix: Int = noImpl): Int
@Deprecated("Use toDouble() instead.", ReplaceWith("s.toDouble()"), level = DeprecationLevel.ERROR)
public external fun parseFloat(s: String, radix: Int = noImpl): Double
public external fun js(code: String): dynamic = noImpl
+1 -1
View File
@@ -69,6 +69,6 @@ inline fun <T, R> T.perform(job: (T)-> R) : R {
return job(this)
}
inline fun String.toInt2() : Int = parseInt(this)
inline fun String.toInt2() : Int = this.toInt()
class RuntimeExceptionWithValue(val value: String) : RuntimeException()
+1 -1
View File
@@ -140,6 +140,6 @@ external object Number {
fun parseInt(str: String): Int = noImpl
}
inline fun String.toInt2(): Int = parseInt(this)
inline fun String.toInt2(): Int = this.toInt()
class RuntimeExceptionWithValue(val value: String = "") : RuntimeException()
@@ -104,4 +104,4 @@ inline fun <T, R> T.performWithFailFinally(job: (T)-> R, failJob : (e: RuntimeEx
}
}
inline fun String.toInt2() : Int = parseInt(this)
inline fun String.toInt2() : Int = this.toInt()
@@ -1,5 +1,3 @@
fun main(args: Array<String>) {
println(max(parseInt(args[0]), parseInt(args[1])))
println(maxOf(args[0].toInt(), args[1].toInt()))
}
fun max(a: Int, b: Int) = if (a > b) a else b
@@ -1,12 +1,6 @@
// Return null if str does not hold a number
fun myParseInt(str: String): Int? {
try {
return parseInt(str)
}
catch (e: NumberFormatException) {
println("One of argument isn't Int")
}
return null
fun myParseInt(str: String): Int? = str.toIntOrNull().also {
if (it == null) println("One of arguments isn't Int")
}
fun main(args: Array<String>) {
+1 -1
View File
@@ -1,6 +1,6 @@
fun main(args: Array<String>) {
val x = parseInt(args[0])
val x = args[0].toInt()
//Check if a number lies within a range:
val y = 10
if (x in 1..y - 1)
@@ -32,7 +32,7 @@ fun main(args: Array<String>) {
printBottles(99)
}
else {
val bottles = parseInt(args[0]);
val bottles = args[0].toIntOrNull()
if (bottles != null) {
printBottles(bottles);
}