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

import java.util.Stack;

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


public class Trim extends PostfixMathCommand {
    public Trim() {
        numberOfParameters = 2;
    }

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

        Object p1 = inStack.pop();
        
        Object p2 = inStack.pop();

        if (p1 instanceof byte[]) {
            inStack.push(new String((byte[]) p1).trim());
        } else if (p1 instanceof String) {
            inStack.push(((String) p1).trim());
        } else {
            throw new ParseException("Invalid parameter type, p1 is not string/bytes");
        }
    }
}
