Class StringLeftFunction
- java.lang.Object
-
- com.ezylang.evalex.functions.AbstractFunction
-
- com.ezylang.evalex.functions.string.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 theAbstractFunctionand 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".
-
-
Field Summary
-
Fields inherited from class com.ezylang.evalex.functions.AbstractFunction
MINUS_ONE
-
-
Constructor Summary
Constructors Constructor Description StringLeftFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EvaluationValueevaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues)Evaluates the `LEFT` string function by extracting a substring from the left side of the given string.-
Methods inherited from class com.ezylang.evalex.functions.AbstractFunction
getFunctionParameterDefinitions, hasVarArgs, validatePreEvaluation
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.ezylang.evalex.functions.FunctionIfc
getCountOfNonVarArgParameters, isParameterLazy
-
-
-
-
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 evaluatedfunctionToken- the token representing the function being calledparameterValues- 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
-
-