All Implemented Interfaces:
FromSourceLocation, ToNode, TypeCheck, ToCondition, ToExpression

public final class Split extends LibraryFunction
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"]
  • Field Details

  • Method Details

    • getDefinition

      public static Split.Definition getDefinition()
      Gets the FunctionDefinition implementation.
      Returns:
      the function definition.
    • ofExpressions

      public static Split ofExpressions(ToExpression string, ToExpression delimiter, ToExpression limit)
      Creates a Split 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

      public <T> T accept(ExpressionVisitor<T> visitor)
      Description copied from class: Expression
      Invoke the ExpressionVisitor functions for this expression.
      Specified by:
      accept in class Expression
      Type Parameters:
      T - the visitor return type.
      Parameters:
      visitor - the visitor to be invoked.
      Returns:
      the return value of the visitor.
    • availableSince

      public RulesVersion availableSince()
      Description copied from class: SyntaxElement
      Get the rules engine version that this syntax element is available since.
      Overrides:
      availableSince in class SyntaxElement
      Returns:
      the version this is available since.
    • split

      public static List<String> split(String value, String delimiter, int limit)
      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.