001    /**
002     * Implements the CFML Function removechars
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 RemoveChars implements Function {
011            public static String call(PageContext pc , String str, double s, double l) throws ExpressionException {
012                    int start=(int) s;
013                    int length=(int) l;
014                    int strLength=str.length();
015                    
016                    // check param 2
017                    if(start<1 || start>strLength)
018                            throw new ExpressionException("Parameter 2 of function removeChars which is now ["+start+"] must be a greater 0 and less than the length of the first parameter"); 
019    
020                    // check param 3
021                    if(length<0)
022                            throw new ExpressionException("Parameter 3 of function removeChars which is now ["+length+"] must be a non-negative integer"); 
023    
024                    if(strLength==0) return "";
025                    
026                    String rtn=str.substring(0,start-1);
027                    
028                    if(start+length<=strLength) rtn+=str.substring(start+length-1);
029                    return rtn;
030            }
031    }