Package org.boris.expr.function.excel

Source Code of org.boris.expr.function.excel.MID

package org.boris.expr.function.excel;

import org.boris.expr.Expr;
import org.boris.expr.ExprError;
import org.boris.expr.ExprException;
import org.boris.expr.ExprString;
import org.boris.expr.function.AbstractFunction;

public class MID extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 3);
        String str = asString(args[0], false);
        int start = asInteger(args[1], true);
        if (start < 1)
            return ExprError.VALUE;
        int len = asInteger(args[2], true);
        if (len < 0)
            return ExprError.VALUE;
        int stlen = str.length();
        if (start > stlen)
            start = stlen + 1;
        if (start + len > stlen)
            len = stlen - start + 1;
        if (len < 0)
            len = 0;
        return new ExprString(str.substring(start - 1, start + len - 1));
    }
}
TOP

Related Classes of org.boris.expr.function.excel.MID

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.