From 7721efad8a36bcd2e0f8b13673ea6c46ae8b8b46 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 8 May 2015 23:08:23 +0300 Subject: [PATCH] Restore isNotEmpty and isNotBlank methods for non-nullable String receiver. #KT-7234 Fixed --- libraries/stdlib/src/kotlin/text/Strings.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 5d3d7ba8e8f..410c974ae7a 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -1,6 +1,7 @@ package kotlin import java.util.NoSuchElementException +import kotlin.platform.platformName import kotlin.text.MatchResult import kotlin.text.Regex @@ -149,6 +150,7 @@ public fun String.padEnd(length: Int, padChar: Char = ' '): String { /** Returns true if the string is not null and not empty */ deprecated("Use !isNullOrEmpty() or isNullOrEmpty().not() for nullable strings.") +platformName("isNotEmptyNullable") public fun String?.isNotEmpty(): Boolean = this != null && this.length() > 0 /** @@ -161,9 +163,20 @@ public fun String?.isNullOrEmpty(): Boolean = this == null || this.length() == 0 */ public fun String.isEmpty(): Boolean = length() == 0 +/** + * Returns `true` if this string is not empty. + */ +public fun String.isNotEmpty(): Boolean = length() > 0 + // implemented differently in JVM and JS //public fun String.isBlank(): Boolean = length() == 0 || all { it.isWhitespace() } + +/** + * Returns `true` if this string is not empty and contains some characters except of whitespace characters. + */ +public fun String.isNotBlank(): Boolean = !isBlank() + /** * Returns `true` if this nullable string is either null or empty or consists solely of whitespace characters. */