package com.eactive.eai.transformer.function.generic;

import java.util.Stack;

import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;

import com.eactive.eai.common.util.StringUtil;


public class LeftTrim extends PostfixMathCommand {
    public LeftTrim() {
        numberOfParameters = 1;
    }

    public void run(Stack inStack) throws ParseException {
        checkStack(inStack);

        Object p1 = inStack.pop();

        if (p1 instanceof byte[]) {
            inStack.push(StringUtil.leftTrim(new String((byte[]) p1)));
        } else if (p1 instanceof String) {
            inStack.push(StringUtil.leftTrim(((String) p1)));
        } else {
            throw new ParseException("Invalid parameter type, p1 is not string/bytes");
        }
    }
    public static void main(String[] args) throws Exception{
    	LeftTrim t = new LeftTrim();
    	Stack inStack = new Stack();
    	inStack.add(" abd  ");
    	t.run(inStack);
    	String data = (String)inStack.pop();
    	// System.out.println("["+data+"]");
    }
}
