3.0.2: 2012-01-25

net.sf.basedb.util.jep
Class LeftFunction

java.lang.Object
  extended by net.sf.basedb.util.jep.LeftFunction
All Implemented Interfaces:
JepFunction, org.nfunk.jep.function.PostfixMathCommandI

public class LeftFunction
extends Object
implements JepFunction

Adds a left(string, index|string) function to Jep. It is used to cut out the leftmost characters of a string. If the second argument is a number, the string is cut with String.substring(int, int) with 0 as the first argument. If the second argument is a string, the position of that string is looked up in the first string and is used as an index. Example:

left('foo:bar', 3) == 'foo'
left('foo:bar', ':') == 'foo')
If the second variant is used and the second string is not found within the first, the first string is returned unmodified.

Since:
3.0
Author:
nicklas
Last modified
$Date $

Constructor Summary
LeftFunction()
           
 
Method Summary
 boolean checkNumberOfParameters(int n)
           
 String getFunctionName()
          Get the name of this function.
 int getNumberOfParameters()
           
 void run(Stack stack)
           
 void setCurNumberOfParameters(int n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeftFunction

public LeftFunction()
Method Detail

getFunctionName

public String getFunctionName()
Description copied from interface: JepFunction
Get the name of this function. It is used when registering the function with a JEP parser.

Specified by:
getFunctionName in interface JepFunction
Returns:
The string "left"
See Also:
JEP.addFunction(String, PostfixMathCommandI)

getNumberOfParameters

public int getNumberOfParameters()
Specified by:
getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
Returns:
Always 2

setCurNumberOfParameters

public void setCurNumberOfParameters(int n)
Specified by:
setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Specified by:
checkNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

run

public void run(Stack stack)
         throws ParseException
Specified by:
run in interface org.nfunk.jep.function.PostfixMathCommandI
Throws:
ParseException

3.0.2: 2012-01-25