001    /**
002     * Implements the CFML Function insert
003     */
004    package railo.runtime.functions.string;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.ExpressionException;
008    import railo.runtime.ext.function.Function;
009    
010    public final class Insert implements Function {
011        public static String call(PageContext pc , String sub, String str, double pos) throws ExpressionException {
012                    int p=(int) pos;
013                    if(p<0 || p>str.length())
014                            throw new ExpressionException("third parameter of the function insert, must be between 0 and "+str.length()+" now ["+(p)+"]");
015                    StringBuffer sb=new StringBuffer(str.length()+sub.length());
016                    
017                    return sb.append(str.substring(0,p)).append(sub).append(str.substring(p)).toString();
018            }
019    }