String.toBoolean() should be String?.toBoolean() #KT-14119
This commit is contained in:
@@ -46,10 +46,12 @@ public actual inline fun Int.toString(radix: Int): String = java.lang.Integer.to
|
||||
public actual inline fun Long.toString(radix: Int): String = java.lang.Long.toString(this, checkRadix(radix))
|
||||
|
||||
/**
|
||||
* Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
|
||||
* Returns `true` if this string is not `null` and its content is equal to the word "true", ignoring case, and `false` otherwise.
|
||||
*/
|
||||
@JvmName("toBooleanNullable")
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun String.toBoolean(): Boolean = java.lang.Boolean.parseBoolean(this)
|
||||
public actual inline fun String?.toBoolean(): Boolean = java.lang.Boolean.parseBoolean(this)
|
||||
|
||||
/**
|
||||
* Parses the string as a signed [Byte] number and returns the result.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
package test.io
|
||||
|
||||
import test.platformNull
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import kotlin.test.*
|
||||
|
||||
class UseCloseableResourceTest {
|
||||
@@ -23,9 +23,6 @@ class UseCloseableResourceTest {
|
||||
assertEquals("World", secondLine)
|
||||
}
|
||||
|
||||
|
||||
@Suppress("HasPlatformType", "UNCHECKED_CAST") fun <T> platformNull() = Collections.singletonList(null as T).first()
|
||||
|
||||
class Resource(val faultyClose: Boolean = false) : Closeable {
|
||||
|
||||
var isClosed = false
|
||||
|
||||
@@ -104,4 +104,19 @@ class StringJVMTest {
|
||||
assertEquals("dzdzdz", "DZdzdz".decapitalize(Locale.US))
|
||||
assertEquals("dzdzdz", "Dzdzdz".decapitalize(Locale.US))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringToBoolean() {
|
||||
assertFalse(platformNull<String>().toBoolean())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stringEquals() {
|
||||
assertFalse(platformNull<String>().equals("sample", ignoreCase = false))
|
||||
assertFalse(platformNull<String>().equals("sample", ignoreCase = true))
|
||||
assertFalse("sample".equals(platformNull<String>(), ignoreCase = false))
|
||||
assertFalse("sample".equals(platformNull(), ignoreCase = true))
|
||||
assertTrue(platformNull<String>().equals(platformNull(), ignoreCase = true))
|
||||
assertTrue(platformNull<String>().equals(platformNull<String>(), ignoreCase = false))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user