Class Split
java.lang.Object
software.amazon.smithy.rulesengine.language.syntax.SyntaxElement
software.amazon.smithy.rulesengine.language.syntax.expressions.Expression
software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
software.amazon.smithy.rulesengine.language.syntax.expressions.functions.Split
- All Implemented Interfaces:
FromSourceLocation
,ToNode
,TypeCheck
,ToCondition
,ToExpression
Splits a string by a delimiter into parts.
The split function divides a string into an array of substrings based on a non-empty delimiter. The behavior is controlled by the limit parameter:
- limit = 0: Split all occurrences (unlimited)
- limit = 1: No split performed (returns original string as single element)
- limit > 1: Split into at most 'limit' parts (performs limit-1 splits)
Examples:
split("a--b--c", "--", 0)
returns["a", "b", "c"]
split("a--b--c", "--", 2)
returns["a", "b--c"]
split("--b--", "--", 0)
returns["", "b", ""]
split("abc", "x", 0)
returns["abc"]
split("", "--", 0)
returns[""]
split("----", "--", 0)
returns["", "", ""]
split("a--b--c--d", "--", 3)
returns["a", "b", "c--d"]
split("prefix", "--", 0)
returns["prefix"]
split("--", "--", 0)
returns["", ""]
split("a-b-c", "--", 0)
returns["a-b-c"]
split("mybucket", "--", 1)
returns["mybucket"]
split("--x-s3--azid--suffix", "--", 0)
returns["", "x-s3", "azid", "suffix"]
split("--x-s3--azid--suffix", "--", 4)
returns["", "x-s3", "azid", "suffix"]
split("--x-s3--azid--suffix", "--", 2)
returns["", "x-s3--azid--suffix"]
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
definition, functionNode
-
Method Summary
Modifier and TypeMethodDescription<T> T
accept
(ExpressionVisitor<T> visitor) Invoke theExpressionVisitor
functions for this expression.Get the rules engine version that this syntax element is available since.static Split.Definition
Gets theFunctionDefinition
implementation.static Split
ofExpressions
(ToExpression string, ToExpression delimiter, ToExpression limit) Creates aSplit
function from the given expressions.Split a string by a delimiter.Methods inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
calculateReferences, canonicalize, equals, expectOneArgument, getArguments, getFunctionDefinition, getName, getSourceLocation, hashCode, shouldSwapArgs, toConditionBuilder, toNode, toString, typeCheckLocal
Methods inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.Expression
fromNode, getLiteral, getReference, getReference, getReference, getReferences, of, of, of, parseShortform, toExpression, type, typeCheck
Methods inherited from class software.amazon.smithy.rulesengine.language.syntax.SyntaxElement
booleanEqual, getAttr, getAttr, isSet, isValidHostLabel, not, parseUrl, stringEqual, substring, template
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.smithy.rulesengine.language.syntax.ToCondition
toCondition, toCondition
-
Field Details
-
ID
- See Also:
-
-
Method Details
-
getDefinition
Gets theFunctionDefinition
implementation.- Returns:
- the function definition.
-
ofExpressions
Creates aSplit
function from the given expressions.- Parameters:
string
- the string to split.delimiter
- the delimiter.limit
- the split limit (0 for unlimited, positive for max parts).- Returns:
- The resulting
Split
function.
-
accept
Description copied from class:Expression
Invoke theExpressionVisitor
functions for this expression.- Specified by:
accept
in classExpression
- Type Parameters:
T
- the visitor return type.- Parameters:
visitor
- the visitor to be invoked.- Returns:
- the return value of the visitor.
-
availableSince
Description copied from class:SyntaxElement
Get the rules engine version that this syntax element is available since.- Overrides:
availableSince
in classSyntaxElement
- Returns:
- the version this is available since.
-
split
Split a string by a delimiter.- Parameters:
value
- the string to split (must not be null).delimiter
- the delimiter to split by (must not be null or empty).limit
- controls the split behavior: 0 = unlimited splits, 1 = no split (return original), n > 1 = split into at most n parts by performing up to n-1 split operations.- Returns:
- a non-null list of parts (never empty; returns [""] for empty input).
- Throws:
NullPointerException
- if value or delimiter is null.IllegalArgumentException
- if delimiter is empty, or if limit is negative.
-