Allow equals with ignoreCase parameter to take nullable Strings both as a receiver and a parameter.

#KT-9188
This commit is contained in:
Ilya Gorbunov
2015-10-09 17:45:03 +03:00
parent c0faf82f77
commit 6d7cc0671e
3 changed files with 12 additions and 4 deletions
+5 -3
View File
@@ -47,11 +47,13 @@ public inline fun CharSequence.isEmpty(): Boolean = this.length() == 0
public fun String.isBlank(): Boolean = length() == 0 || matches("^[\\s\\xA0]+$")
public fun String.equals(anotherString: String, ignoreCase: Boolean = false): Boolean =
if (!ignoreCase)
public fun String?.equals(anotherString: String?, ignoreCase: Boolean = false): Boolean =
if (this == null)
anotherString == null
else if (!ignoreCase)
this == anotherString
else
this.toLowerCase() == anotherString.toLowerCase()
anotherString != null && this.toLowerCase() == anotherString.toLowerCase()
public fun String.regionMatches(thisOffset: Int, other: String, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean {