001    /**
002     * Implements the CFML Function arraydeleteat
003     */
004    package railo.runtime.functions.arrays;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.functions.BIF;
009    import railo.runtime.op.Caster;
010    import railo.runtime.type.Array;
011    
012    
013    public final class ArrayDelete extends BIF {
014    
015            private static final long serialVersionUID = 1120923916196967210L;
016            
017            public static boolean call(PageContext pc , Array array, Object value) throws PageException {
018                    return call(pc, array, value,null);
019            }
020            public static boolean call(PageContext pc , Array array, Object value, String scope) throws PageException {
021                    boolean onlyFirst=!"all".equalsIgnoreCase(scope);
022                    double pos;
023                    if((pos=ArrayFindNoCase.call(pc, array, value))>0){
024                            array.removeE((int)pos);
025                            if(onlyFirst) return true;
026                    }
027                    else return false;
028                    
029                    while((pos=ArrayFindNoCase.call(pc, array, value))>0){
030                            array.removeE((int)pos);
031                    }
032                    
033                    return true;
034            }
035            
036            @Override
037            public Object invoke(PageContext pc, Object[] args) throws PageException {
038                    if(args.length==2)return call(pc,Caster.toArray(args[0]),args[1]);
039                    return call(pc,Caster.toArray(args[0]),args[1],Caster.toString(args[2]));
040            }
041            
042    }