Class StringLeftFunction

  • All Implemented Interfaces:
    FunctionIfc

    @FunctionParameter(name="string") @FunctionParameter(name="length")
    public class StringLeftFunction
    extends AbstractFunction
    Represents a function that extracts a substring from the left side of a given string. This class extends the AbstractFunction and implements the logic for the `LEFT` string function, which returns a specified number of characters from the beginning (left) of the input string.

    Two parameters are required for this function:

    • string - The input string from which the substring will be extracted.
    • length - The number of characters to extract from the left side of the string. If the specified length is greater than the string's length, the entire string is returned. If the length is negative or zero, an empty string is returned.

    Example usage: If the input string is "hello" and the length is 2, the result will be "he".

    • Constructor Detail

      • StringLeftFunction

        public StringLeftFunction()
    • Method Detail

      • evaluate

        public EvaluationValue evaluate​(Expression expression,
                                        Token functionToken,
                                        EvaluationValue... parameterValues)
        Evaluates the `LEFT` string function by extracting a substring from the left side of the given string.
        Parameters:
        expression - the current expression being evaluated
        functionToken - the token representing the function being called
        parameterValues - the parameters passed to the function; expects exactly two parameters: a string and a numeric value for length
        Returns:
        the substring extracted from the left side of the input string as an EvaluationValue