Implement String.toBoolean() for JS.
#KT-16348
This commit is contained in:
committed by
Ilya Gorbunov
parent
86c10b635a
commit
11696ac4c0
@@ -18,6 +18,11 @@ package kotlin.text
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
|
||||
*/
|
||||
public fun String.toBoolean(): Boolean = toLowerCase() == "true"
|
||||
|
||||
/**
|
||||
* Parses the string as a signed [Byte] number and returns the result.
|
||||
* @throws NumberFormatException if the string is not a valid representation of a number.
|
||||
|
||||
@@ -126,6 +126,11 @@ expect fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, othe
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
|
||||
*/
|
||||
expect fun String.toBoolean(): Boolean
|
||||
|
||||
/**
|
||||
* Parses the string as a signed [Byte] number and returns the result.
|
||||
* @throws NumberFormatException if the string is not a valid representation of a number.
|
||||
|
||||
@@ -5,7 +5,6 @@ import kotlin.test.*
|
||||
|
||||
class StringNumberConversionTest {
|
||||
|
||||
@kotlin.jvm.JvmVersion
|
||||
@Test fun toBoolean() {
|
||||
assertEquals(true, "true".toBoolean())
|
||||
assertEquals(true, "True".toBoolean())
|
||||
|
||||
Reference in New Issue
Block a user