@@ -2,14 +2,24 @@ package co.nimblehq.common.extensions
22
33import androidx.core.util.PatternsCompat
44import java.util.*
5+ import kotlin.contracts.ExperimentalContracts
6+ import kotlin.contracts.contract
7+
8+ private val THAI_REGEX = " ([\\ u0E00-\\ u0E7F]+)" .toRegex()
59
610/* *
711 * Check if the string not null or empty.
812 * This extension wraps for more readable.
913 *
1014 * @return true if this nullable char sequence is NOT either null or empty
1115 */
12- fun String?.isNotNullOrEmpty (): Boolean = ! this .isNullOrEmpty()
16+ @OptIn(ExperimentalContracts ::class )
17+ fun String?.isNotNullOrEmpty (): Boolean {
18+ contract {
19+ returns(true ) implies (this @isNotNullOrEmpty != null )
20+ }
21+ return ! this .isNullOrEmpty()
22+ }
1323
1424/* *
1525 * Check if the string not null or blank.
@@ -18,7 +28,13 @@ fun String?.isNotNullOrEmpty(): Boolean = !this.isNullOrEmpty()
1828 * @return true if this nullable char sequence is NOT either null or empty or consists solely of
1929 * whitespace
2030 */
21- fun String?.isNotNullOrBlank (): Boolean = ! this .isNullOrBlank()
31+ @OptIn(ExperimentalContracts ::class )
32+ fun String?.isNotNullOrBlank (): Boolean {
33+ contract {
34+ returns(true ) implies (this @isNotNullOrBlank != null )
35+ }
36+ return ! this .isNullOrBlank()
37+ }
2238
2339/* *
2440 * Eliminate the given character then titleize.
@@ -68,6 +84,5 @@ fun String.isEmailValid(): Boolean {
6884 * @return true if this string is Thai
6985 */
7086fun String.isThai (): Boolean {
71- val thaiRegex = " ([\\ u0E00-\\ u0E7F]+)" .toRegex()
72- return if (isEmpty() || isBlank()) false else all { thaiRegex.matches(it.toString()) }
87+ return isNotEmpty() && all { THAI_REGEX .matches(it.toString()) }
7388}
0 commit comments