Skip to content

Commit

Permalink
Merge pull request #927 from skayliu/skayliu-is-blank
Browse files Browse the repository at this point in the history
feat: add function `is blank()` to check if a string is blank
  • Loading branch information
saig0 authored Sep 20, 2024
2 parents 9351e46 + 356ca38 commit 209b3f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object StringBuiltinFunctions {
"extract" -> List(extractFunction),
"trim" -> List(trimFunction),
"uuid" -> List(uuidFunction),
"to base64" -> List(toBase64Function)
"to base64" -> List(toBase64Function),
"is blank" -> List(isBlankFunction)
)

private def substringFunction = builtinFunction(
Expand Down Expand Up @@ -287,4 +288,11 @@ object StringBuiltinFunctions {
}
)

private def isBlankFunction = builtinFunction(
params = List("string"),
invoke = {case List(ValString(string)) =>
ValBoolean(string.isBlank)
}
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,32 @@ class BuiltinStringFunctionsTest

evaluateExpression(""" to base64(value: "Camunda") """) should returnResult("Q2FtdW5kYQ==")
}

"A is blank() function" should "return true if the string contains only whitespace" in {
evaluateExpression(
expression = """ is blank("") """
) should returnResult(true)

evaluateExpression(
expression = """ is blank(" ") """
) should returnResult(true)

evaluateExpression(
expression = """ is blank("\t\n\r\f") """
) should returnResult(true)

evaluateExpression(
expression = """ is blank(string: "") """
) should returnResult(true)
}

it should "return false if the string contains only non-whitespace characters" in {
evaluateExpression(
expression = """ is blank("hello world") """
) should returnResult(false)

evaluateExpression(
expression = """ is blank(" hello world ") """
) should returnResult(false)
}
}

0 comments on commit 209b3f6

Please sign in to comment.