Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ package co.nimblehq.common.extensions

import androidx.core.util.PatternsCompat
import java.util.*
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

private val THAI_REGEX = "([\\u0E00-\\u0E7F]+)".toRegex()

/**
* Check if the string not null or empty.
* This extension wraps for more readable.
*
* @return true if this nullable char sequence is NOT either null or empty
*/
fun String?.isNotNullOrEmpty(): Boolean = !this.isNullOrEmpty()
@OptIn(ExperimentalContracts::class)
fun String?.isNotNullOrEmpty(): Boolean {
contract {
returns(true) implies (this@isNotNullOrEmpty != null)
}
return !this.isNullOrEmpty()
}

/**
* Check if the string not null or blank.
Expand All @@ -18,7 +28,13 @@ fun String?.isNotNullOrEmpty(): Boolean = !this.isNullOrEmpty()
* @return true if this nullable char sequence is NOT either null or empty or consists solely of
* whitespace
*/
fun String?.isNotNullOrBlank(): Boolean = !this.isNullOrBlank()
@OptIn(ExperimentalContracts::class)
fun String?.isNotNullOrBlank(): Boolean {
contract {
returns(true) implies (this@isNotNullOrBlank != null)
}
return !this.isNullOrBlank()
}

/**
* Eliminate the given character then titleize.
Expand Down Expand Up @@ -68,6 +84,5 @@ fun String.isEmailValid(): Boolean {
* @return true if this string is Thai
*/
fun String.isThai(): Boolean {
val thaiRegex = "([\\u0E00-\\u0E7F]+)".toRegex()
return if (isEmpty() || isBlank()) false else all { thaiRegex.matches(it.toString()) }
return isNotEmpty() && all { THAI_REGEX.matches(it.toString()) }
}
Loading